/* This is a hash function that I from http://www.cse.yorku.ca/~oz/hash.html. The author claims that it works well, but doesn't know why! */ #include #include using namespace std; int main() { unsigned int x; unsigned int hs; unsigned int g; unsigned int s; hs = 5381; x = 205936038; printf("Starting value = 0x%08x = %10u\n", x, x); hs = (hs << 25) | (hs >> 7); printf("hs = 0x%08x = %10u\n", hs, hs); x ^= hs; printf("x = value xor hs = 0x%08x = %10u\n", x, x); x = (x << 5) | (x >> 27); printf("x circ<<= 5 = 0x%08x = %10u\n", x, x); g = 'g'; printf("'g' = 0x%08x = %10u\n", g, g); g = (g << 25) | (g >> 7); printf("g = 'g' circ<< 25 = 0x%08x = %10u\n", g, g); x ^= g; printf("x ^= g = 0x%08x = %10u\n", x, x); s = 's'; printf("'s' = 0x%08x = %10u\n", s, s); x ^= s; printf("x ^= 's' = 0x%08x = %10u\n", x, x); x ^= hs; printf("x ^= hs = 0x%08x = %10u\n", x, x); return 0; }