diff options
author | John Tytgat <joty@netsurf-browser.org> | 2008-07-26 22:29:15 +0000 |
---|---|---|
committer | John Tytgat <joty@netsurf-browser.org> | 2008-07-26 22:29:15 +0000 |
commit | 5f6c2cbff7cd778b6487943d62e71ff9e7b04893 (patch) | |
tree | 2755ac7fd68397c47142e4ba030b8212e16862b2 /utils | |
parent | aae686d90a3741293c6b3f2d15c7e2976b72adb9 (diff) | |
download | netsurf-5f6c2cbff7cd778b6487943d62e71ff9e7b04893.tar.gz netsurf-5f6c2cbff7cd778b6487943d62e71ff9e7b04893.tar.bz2 |
- Compiler warning squash
- Changed a lineending \n\r -> \n for a couple of files.
- More code style conformance.
svn path=/trunk/netsurf/; revision=4762
Diffstat (limited to 'utils')
-rw-r--r-- | utils/hashtable.c | 56 | ||||
-rw-r--r-- | utils/hashtable.h | 1 |
2 files changed, 28 insertions, 29 deletions
diff --git a/utils/hashtable.c b/utils/hashtable.c index ce4ec3755..6a5bce0ba 100644 --- a/utils/hashtable.c +++ b/utils/hashtable.c @@ -42,6 +42,34 @@ struct hash_table { struct hash_entry **chain; }; +/** + * Hash a string, returning a 32bit value. The hash algorithm used is + * Fowler Noll Vo - a very fast and simple hash, ideal for short strings. + * See http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash for more details. + * + * \param datum The string to hash. + * \param len Pointer to unsigned integer to record datum's length in. + * \return The calculated hash value for the datum. + */ + +static inline unsigned int hash_string_fnv(const char *datum, unsigned int *len) +{ + unsigned int z = 0x01000193; + const char *start = datum; + *len = 0; + + if (datum == NULL) + return 0; + + while (*datum) { + z *= 0x01000193; + z ^= *datum++; + } + *len = datum - start; + + return z; +} + /** * Create a new hash table, and return a context for it. The memory consumption @@ -179,34 +207,6 @@ const char *hash_get(struct hash_table *ht, const char *key) } /** - * Hash a string, returning a 32bit value. The hash algorithm used is - * Fowler Noll Vo - a very fast and simple hash, ideal for short strings. - * See http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash for more details. - * - * \param datum The string to hash. - * \param len Pointer to unsigned integer to record datum's length in. - * \return The calculated hash value for the datum. - */ - -unsigned int hash_string_fnv(const char *datum, unsigned int *len) -{ - unsigned int z = 0x01000193; - const char *start = datum; - *len = 0; - - if (datum == NULL) - return 0; - - while (*datum) { - z *= 0x01000193; - z ^= *datum++; - } - *len = datum - start; - - return z; -} - -/** * Iterate through all available hash keys. * * \param ht The hash table context to iterate. diff --git a/utils/hashtable.h b/utils/hashtable.h index 2c698b0b3..432ccfe2a 100644 --- a/utils/hashtable.h +++ b/utils/hashtable.h @@ -30,7 +30,6 @@ struct hash_table *hash_create(unsigned int chains); void hash_destroy(struct hash_table *ht); bool hash_add(struct hash_table *ht, const char *key, const char *value); const char *hash_get(struct hash_table *ht, const char *key); -inline unsigned int hash_string_fnv(const char *datum, unsigned int *len); const char *hash_iterate(struct hash_table *ht, unsigned int *c1, unsigned int **c2); |