* 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
| 1369 | * algorithm, and cap the result at RETAIN_HASH_SIZE. |
| 1370 | */ |
| 1371 | static unsigned |
| 1372 | xo_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 |
no outgoing calls
no test coverage detected