X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fhash.h;h=3f140381c36104ce22eb558e08a9ea75ab52d6a4;hb=36775dad3505929f8370166c33e8e0f04ca96c1c;hp=2015a639fc1b321d319fa4cb4e463e97793e1b54;hpb=cce1d8bd8e326c93579a6ff5d037fe3a60a39f86;p=openvswitch diff --git a/lib/hash.h b/lib/hash.h index 2015a639..3f140381 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -16,6 +16,7 @@ #ifndef HASH_H #define HASH_H 1 +#include #include #include #include @@ -64,10 +65,20 @@ static inline uint32_t hash_int(uint32_t x, uint32_t basis) x ^= x >> 17; x -= x << 9; x ^= x << 4; + x += basis; x -= x << 3; x ^= x << 10; x ^= x >> 15; - return x + basis; + return x; +} + +/* 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)