diff options
author | Ben Pfaff <blp@nicira.com> | 2009-10-14 17:03:55 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2009-11-04 15:00:30 -0800 |
commit | cce1d8bd8e326c93579a6ff5d037fe3a60a39f86 (patch) | |
tree | de57bab2a0360bce07d96e35347751765bf0c1bc /lib/hash.h | |
parent | 0064467516248fb3b28bdbd7d0f4e54b861627cf (diff) |
hash: Implement hash function for "double" values.
This will be used by the configuration database, which can store real
numbers.
Diffstat (limited to 'lib/hash.h')
-rw-r--r-- | lib/hash.h | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -19,6 +19,7 @@ #include <stddef.h> #include <stdint.h> #include <string.h> +#include "util.h" /* This is the public domain lookup3 hash by Bob Jenkins from * http://burtleburtle.net/bob/c/lookup3.c, modified for style. */ @@ -47,6 +48,7 @@ } while (0) uint32_t hash_words(const uint32_t *, size_t n_word, uint32_t basis); +uint32_t hash_2words(const uint32_t *, uint32_t basis); uint32_t hash_bytes(const void *, size_t n_bytes, uint32_t basis); static inline uint32_t hash_string(const char *s, uint32_t basis) @@ -68,6 +70,12 @@ static inline uint32_t hash_int(uint32_t x, uint32_t basis) return x + basis; } +static inline uint32_t hash_double(double x, uint32_t basis) +{ + BUILD_ASSERT_DECL(sizeof x == 8); + return hash_2words((const uint32_t *) &x, basis); +} + static inline uint32_t hash_pointer(const void *p, uint32_t basis) { /* Often pointers are hashed simply by casting to integer type, but that |