diff options
author | Ben Pfaff <blp@nicira.com> | 2009-11-04 15:01:00 -0800 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2009-11-04 15:01:00 -0800 |
commit | 8e5421180d1acd5856f41e6dd33ff69ccb7af92b (patch) | |
tree | e90c1322643968815d18b76af4dcfeb90a19de04 /lib/hash.h | |
parent | cce1d8bd8e326c93579a6ff5d037fe3a60a39f86 (diff) |
hash: Implement hash function for Boolean values.
This will be used by the configuration database, and it's generally useful
to have around.
Diffstat (limited to 'lib/hash.h')
-rw-r--r-- | lib/hash.h | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -16,6 +16,7 @@ #ifndef HASH_H #define HASH_H 1 +#include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <string.h> @@ -70,6 +71,15 @@ static inline uint32_t hash_int(uint32_t x, uint32_t basis) return x + basis; } +/* An attempt at a useful 1-bit hash function. Has not been analyzed for + * quality. */ +static inline uint32_t hash_boolean(bool x, uint32_t basis) +{ + enum { P0 = 0xc2b73583 }; /* This is hash_int(1, 0). */ + enum { P1 = 0xe90f1258 }; /* This is hash_int(2, 0). */ + return (x ? P0 : P1) ^ HASH_ROT(basis, 1); +} + static inline uint32_t hash_double(double x, uint32_t basis) { BUILD_ASSERT_DECL(sizeof x == 8); |