[Mesa-dev] [PATCH 13/14] util: Use hashing functions from hash_table.h

Thomas Helland thomashelland90 at gmail.com
Sun Jan 1 18:37:57 UTC 2017


---
 src/util/non_replacing_hash_table.c | 47 -------------------------------------
 src/util/non_replacing_hash_table.h | 35 +--------------------------
 2 files changed, 1 insertion(+), 81 deletions(-)

diff --git a/src/util/non_replacing_hash_table.c b/src/util/non_replacing_hash_table.c
index ecec94e2d6..64dc5c9c18 100644
--- a/src/util/non_replacing_hash_table.c
+++ b/src/util/non_replacing_hash_table.c
@@ -511,50 +511,3 @@ _mesa_non_replacing_hash_table_random_entry(struct non_replacing_hash_table *ht,
 
    return NULL;
 }
-
-
-/**
- * Quick FNV-1a hash implementation based on:
- * http://www.isthe.com/chongo/tech/comp/fnv/
- *
- * FNV-1a is not be the best hash out there -- Jenkins's lookup3 is supposed
- * to be quite good, and it probably beats FNV.  But FNV has the advantage
- * that it involves almost no code.  For an improvement on both, see Paul
- * Hsieh's http://www.azillionmonkeys.com/qed/hash.html
- */
-uint32_t
-_mesa_hash_data(const void *data, size_t size)
-{
-   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 = _mesa_fnv32_1a_offset_bias;
-
-   while (*key != 0) {
-      hash = _mesa_fnv32_1a_accumulate(hash, *key);
-      key++;
-   }
-
-   return hash;
-}
-
-/**
- * String compare function for use as the comparison callback in
- * _mesa_non_replacing_hash_table_create().
- */
-bool
-_mesa_key_string_equal(const void *a, const void *b)
-{
-   return strcmp(a, b) == 0;
-}
-
-bool
-_mesa_key_pointer_equal(const void *a, const void *b)
-{
-   return a == b;
-}
diff --git a/src/util/non_replacing_hash_table.h b/src/util/non_replacing_hash_table.h
index f047ad5c11..e8a29635f6 100644
--- a/src/util/non_replacing_hash_table.h
+++ b/src/util/non_replacing_hash_table.h
@@ -33,6 +33,7 @@
 #include <stdbool.h>
 #include "c99_compat.h"
 #include "macros.h"
+#include "util/hash_table.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -101,40 +102,6 @@ struct non_replacing_hash_entry *
 _mesa_non_replacing_hash_table_random_entry(struct non_replacing_hash_table *ht,
                               bool (*predicate)(struct non_replacing_hash_entry *entry));
 
-uint32_t _mesa_hash_data(const void *data, size_t size);
-uint32_t _mesa_hash_string(const char *key);
-bool _mesa_key_string_equal(const void *a, const void *b);
-bool _mesa_key_pointer_equal(const void *a, const void *b);
-
-static inline uint32_t _mesa_key_hash_string(const void *key)
-{
-   return _mesa_hash_string((const char *)key);
-}
-
-static inline uint32_t _mesa_hash_pointer(const void *pointer)
-{
-   return _mesa_hash_data(&pointer, sizeof(pointer));
-}
-
-enum {
-   _mesa_fnv32_1a_offset_bias = 2166136261u,
-};
-
-static inline uint32_t
-_mesa_fnv32_1a_accumulate_block(uint32_t hash, const void *data,
-                                size_t size)
-{
-   const uint8_t *bytes = (const uint8_t *)data;
-
-   while (size-- != 0) {
-      hash ^= *bytes;
-      hash = hash * 0x01000193;
-      bytes++;
-   }
-
-   return hash;
-}
-
 #define _mesa_fnv32_1a_accumulate(hash, expr) \
    _mesa_fnv32_1a_accumulate_block(hash, &(expr), sizeof(expr))
 
-- 
2.11.0



More information about the mesa-dev mailing list