ref: 75fa6d220de69bdb91954ea8cf942611b25214cb
dir: /src/hashing.c/
#include "flisp.h" #include "hashing.h" #include "spooky.h" value_t inthash(value_t a) { #if defined(BITS64) a = (~a) + (a << 21); // a = (a << 21) - a - 1; a = a ^ (a >> 24); a = (a + (a << 3)) + (a << 8); // a * 265 a = a ^ (a >> 14); a = (a + (a << 2)) + (a << 4); // a * 21 a = a ^ (a >> 28); a = a + (a << 31); return a; } #else a = (a+0x7ed55d16) + (a<<12); a = (a^0xc761c23c) ^ (a>>19); a = (a+0x165667b1) + (a<<5); a = (a+0xd3a2646c) ^ (a<<9); a = (a+0xfd7046c5) + (a<<3); a = (a^0xb55a4f09) ^ (a>>16); return a; } uint32_t int64to32hash(uint64_t key) { key = (~key) + (key << 18); // key = (key << 18) - key - 1; key = key ^ (key >> 31); key = key * 21; // key = (key + (key << 2)) + (key << 4); key = key ^ (key >> 11); key = key + (key << 6); key = key ^ (key >> 22); return (uint32_t)key; } #endif uint64_t memhash(const char *buf, size_t n) { return spooky_hash64(buf, n, 0xcafe8881ULL); }