MCPcopy Create free account
hub / github.com/F-Stack/f-stack / xo_retain_hash

Function xo_retain_hash

tools/libxo/libxo/libxo.c:1371–1387  ·  view source on GitHub ↗

* Simple hash function based on Thomas Wang's paper. The original is * gone, but an archive is available on the Way Back Machine: * * http://web.archive.org/web/20071223173210/\ * http://www.concentric.net/~Ttwang/tech/inthash.htm * * For our purposes, we can assume the low four bits are uninteresting * since any string less that 16 bytes wouldn't be worthy of * retaining. We toss th

Source from the content-addressed store, hash-verified

1369 * algorithm, and cap the result at RETAIN_HASH_SIZE.
1370 */
1371static unsigned
1372xo_retain_hash (const char *fmt)
1373{
1374 volatile uintptr_t iptr = (uintptr_t) (const void *) fmt;
1375
1376 /* Discard low four bits and high bits; they aren't interesting */
1377 uint32_t val = (uint32_t) ((iptr >> 4) & (((1 << 24) - 1)));
1378
1379 val = (val ^ 61) ^ (val >> 16);
1380 val = val + (val << 3);
1381 val = val ^ (val >> 4);
1382 val = val * 0x3a8f05c5; /* My large prime number */
1383 val = val ^ (val >> 15);
1384 val &= RETAIN_HASH_SIZE - 1;
1385
1386 return val;
1387}
1388
1389/*
1390 * Walk all buckets, clearing all retained entries

Callers 3

xo_retain_clearFunction · 0.85
xo_retain_findFunction · 0.85
xo_retain_addFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected