#include "SpookyAlpha.h" #include #include #include typedef unsigned long u4; u4 one_at_a_time(const char *message, size_t length, u4 seed) { int i; u4 hash = seed; for (i=0; i> 6); } hash += (hash << 15); hash ^= (hash >> 11); hash += (hash << 3); return hash; } void plain(const void *message, size_t length, uint64_t *hash1, uint64_t *hash2) { const uint64_t *data = (const uint64_t *)message; const uint64_t *end = data + length/8; uint64_t a = *hash1, b = *hash2; int i; for (; data < end; data += 8) { a += data[0]; b += data[1]; a += data[2]; b += data[3]; a += data[4]; b += data[5]; a += data[6]; b += data[7]; } *hash1 = a; *hash2 = b; } typedef struct ranctx { uint64_t a; uint64_t b; uint64_t c; uint64_t d;} ranctx; static uint64_t ranval( ranctx *x ) { uint64_t e = x->a - rot64(x->b, 23); x->a = x->b ^ rot64(x->c, 16); x->b = x->c + rot64(x->d, 11); x->c = x->d + e; x->d = e + x->a; return x->d; } void raninit( ranctx *x, uint64_t seed) { int i; x->a = 0xdeadbeef; x->b = x->c = x->d = seed; for (i=0; i<20; ++i) ranval(x); } #define NUMBUF 1024 #define BUFSIZE (1<<20) void DoTiming() { uint64_t a,z, hash1, hash2; char *buf[NUMBUF]; int i, j; Spooky state; a = GetTickCount(); for (i=0; i>1 ) & 0x5555555555555555LL); c = (c & 0x3333333333333333LL) + ((c>>2 ) & 0x3333333333333333LL); c = (c & 0x0f0f0f0f0f0f0f0fLL) + ((c>>4 ) & 0x0f0f0f0f0f0f0f0fLL); c = (c & 0x00ff00ff00ff00ffLL) + ((c>>8 ) & 0x00ff00ff00ff00ffLL); c = (c & 0x0000ffff0000ffffLL) + ((c>>16) & 0x0000ffff0000ffffLL); c = (c & 0x00000000ffffffffLL) + ((c>>32) & 0x00000000ffffffffLL); return c; } #undef NUMBUF #undef BUFSIZE #define BUFSIZE 256 #define TRIES 60 #define MEASURES 6 void TestPair() { int h,i,j,k,l,m, maxk; ranctx ctx; raninit(&ctx, 1); for (h=0; h>1); measure[5][l] = measure[0][l] + measure[1][l]; measure[5][l] ^= (measure[4][l]>>1); } for (l=0; l<2; ++l) { for (m=0; m maxk) { maxk = k; } } } printf("done with buffer size %d max %d\n", h, maxk); } } int main() { char buf[256]; int i, j, k; for (i=0; i<256; ++i) { buf[i] = i; } for (i=0; i<256; ++i) { uint64_t a,b,c,d,e,f; Spooky state; a = c = e = 1; b = d = f = 2; // all as one call SpookyHash(buf, i, &a, &b); // all as one piece SpookyInit(&state, c, d); SpookyUpdate(&state, buf, i); SpookyFinal(&state, &c, &d); // a bunch of 1-byte pieces SpookyInit(&state, e, f); for (j=0; j