X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fhash.h;h=5f6409cb135e71ef25ab9dfdefb36ad273673f78;hb=a23aab1fc2f66b63ba9b7e4b9c9a8f6d58c367d0;hp=33c5c427a2e81ad4d44a70b440c4c0af8856cc94;hpb=8e5421180d1acd5856f41e6dd33ff69ccb7af92b;p=openvswitch diff --git a/lib/hash.h b/lib/hash.h index 33c5c427..5f6409cb 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -65,10 +65,11 @@ 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 @@ -82,8 +83,11 @@ static inline uint32_t hash_boolean(bool x, uint32_t 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); + uint32_t value[2]; + BUILD_ASSERT_DECL(sizeof x == sizeof value); + + memcpy(value, &x, sizeof value); + return hash_2words(value, basis); } static inline uint32_t hash_pointer(const void *p, uint32_t basis)