From a3b73ccf6db3efe4ce0eed4c60d1e2709b335cac Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 5 Jan 2015 22:31:23 -0800 Subject: util/hash_table: Pull the details of the FNV-1a into helpers This way the basics of the FNV-1a hash can be reused to easily create other hashing functions. Reviewed-by: Eric Anholt --- src/util/hash_table.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'src/util/hash_table.c') diff --git a/src/util/hash_table.c b/src/util/hash_table.c index 0ad03837760..ac187b24ca4 100644 --- a/src/util/hash_table.c +++ b/src/util/hash_table.c @@ -431,27 +431,18 @@ _mesa_hash_table_random_entry(struct hash_table *ht, uint32_t _mesa_hash_data(const void *data, size_t size) { - uint32_t hash = 2166136261ul; - const uint8_t *bytes = data; - - while (size-- != 0) { - hash ^= *bytes; - hash = hash * 0x01000193; - bytes++; - } - - return hash; + return _mesa_fnv32_1a_accumulate_block(_mesa_fnv32_1a_offset_bias, + data, size); } /** FNV-1a string hash implementation */ uint32_t _mesa_hash_string(const char *key) { - uint32_t hash = 2166136261ul; + uint32_t hash = _mesa_fnv32_1a_offset_bias; while (*key != 0) { - hash ^= *key; - hash = hash * 0x01000193; + hash = _mesa_fnv32_1a_accumulate(hash, *key); key++; } -- cgit v1.2.3