diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2014-06-15 08:48:18 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2014-06-15 08:48:18 +0000 |
commit | 2e6a99ce09cea47a9890a30c8180b823967e9a46 (patch) | |
tree | 6e5298680f3b05d7bc62c4972359f8cad46e6f6e | |
parent | 218f6e2cd9279e079ee3c19e90109d6f20cf343d (diff) |
Added coucal_calc_hashes()
-rw-r--r-- | src/coucal.c | 21 | ||||
-rw-r--r-- | src/coucal.h | 12 |
2 files changed, 22 insertions, 11 deletions
diff --git a/src/coucal.c b/src/coucal.c index 38273ce..9b24b1a 100644 --- a/src/coucal.c +++ b/src/coucal.c @@ -296,9 +296,11 @@ static void coucal_log(const coucal hashtable, coucal_loglevel level, } /* No logging (should be dropped by the compiler) */ -static void coucal_nolog(const coucal hashtable, const char *format, ...) - INTHASH_PRINTF_FUN(2, 3); -static void coucal_nolog(const coucal hashtable, const char *format, ...) { +static INTHASH_INLINE void coucal_nolog(const coucal hashtable, + const char *format, ...) + INTHASH_PRINTF_FUN(2, 3); +static INTHASH_INLINE void coucal_nolog(const coucal hashtable, + const char *format, ...) { (void) hashtable; (void) format; } @@ -431,12 +433,12 @@ coucal_hashkeys coucal_hash_data(const void *data_, size_t size) { #endif } -coucal_hashkeys coucal_hash_string(const char *name) { +INTHASH_INLINE coucal_hashkeys coucal_hash_string(const char *name) { return coucal_hash_data(name, strlen(name)); } -static INTHASH_INLINE coucal_hashkeys coucal_calc_hashes(coucal hashtable, - coucal_key_const value) { +INTHASH_INLINE coucal_hashkeys coucal_calc_hashes(coucal hashtable, + coucal_key_const value) { return hashtable->custom.key.hash == NULL ? coucal_hash_string(value) : hashtable->custom.key.hash(hashtable->custom.key.arg, value); @@ -749,13 +751,13 @@ static void coucal_default_free_handler(coucal_opaque arg, free(value.ptr); } -static void coucal_del_value_(coucal hashtable, coucal_value *pvalue) { +static INTHASH_INLINE void coucal_del_value_(coucal hashtable, coucal_value *pvalue) { if (hashtable->custom.value.free != NULL) hashtable->custom.value.free(hashtable->custom.value.arg, *pvalue); pvalue->ptr = NULL; } -static void coucal_del_value(coucal hashtable, size_t pos) { +static INTHASH_INLINE void coucal_del_value(coucal hashtable, size_t pos) { coucal_del_value_(hashtable, &hashtable->items[pos].value); } @@ -1156,7 +1158,8 @@ coucal_value* coucal_fetch_value_hashes(coucal hashtable, return NULL; } -coucal_value* coucal_fetch_value(coucal hashtable, coucal_key_const name) { +INTHASH_INLINE coucal_value* coucal_fetch_value(coucal hashtable, + coucal_key_const name) { const coucal_hashkeys hashes = coucal_calc_hashes(hashtable, name); return coucal_fetch_value_hashes(hashtable, name, &hashes); } diff --git a/src/coucal.h b/src/coucal.h index 92f4541..56814c8 100644 --- a/src/coucal.h +++ b/src/coucal.h @@ -436,8 +436,8 @@ COUCAL_EXTERN coucal_value* coucal_fetch_value(coucal hashtable, * Returns NULL if the entry could not be found. * The returned pointer is only valid until next call to this library, and can * be used for read or write operations. - * The hashes MUST have been computed using either coucal_hash_string(), or - * coucal_hash_data(), or by copying an existing hash during an enumeration. + * The hashes MUST have been computed using coucal_calc_hashes(), or by + * copying an existing hash during an enumeration. * The use of a non-matching hash is safe, but will return NULL. **/ COUCAL_EXTERN coucal_value* coucal_fetch_value_hashes(coucal hashtable, @@ -464,6 +464,14 @@ COUCAL_EXTERN struct_coucal_enum coucal_enum_new(coucal hashtable); COUCAL_EXTERN coucal_item *coucal_enum_next(struct_coucal_enum * e); /** + * Compute a hash of a key for the hashtable 'hashtable'. + * The returned hash is suitable for use with coucal_fetch_value_hashes() + * Note: the default implementation uses coucal_hash_string() + **/ +COUCAL_EXTERN coucal_hashkeys coucal_calc_hashes(coucal hashtable, + coucal_key_const value); + +/** * Compute a hash, given a string. This is the default function used for * hashing keys, which are by default strings. This function uses * coucal_hash_data() as backend. |