diff options
author | Jason Ekstrand <[email protected]> | 2015-01-05 22:31:23 -0800 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2015-01-15 07:20:23 -0800 |
commit | a3b73ccf6db3efe4ce0eed4c60d1e2709b335cac (patch) | |
tree | cda3e43886f11fb94f323aad11108dc2c8680b06 /src/util/hash_table.h | |
parent | e4115ca9d824a27176c58fdeede392d4d99b0cab (diff) |
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 <[email protected]>
Diffstat (limited to 'src/util/hash_table.h')
-rw-r--r-- | src/util/hash_table.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/util/hash_table.h b/src/util/hash_table.h index 5561e158454..7f9fd6288ea 100644 --- a/src/util/hash_table.h +++ b/src/util/hash_table.h @@ -101,6 +101,25 @@ static inline uint32_t _mesa_hash_pointer(const void *pointer) return _mesa_hash_data(&pointer, sizeof(pointer)); } +static const uint32_t _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)) + /** * This foreach function is safe against deletion (which just replaces * an entry's data with the deleted marker), but not against insertion |