MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / testHashingFunction

Function testHashingFunction

utils/tracking_collisions.c:52–70  ·  view source on GitHub ↗

Test the hashing function provided as callback and return the * number of collisions found. */

Source from the content-addressed store, hash-verified

50/* Test the hashing function provided as callback and return the
51 * number of collisions found. */
52unsigned long testHashingFunction(uint64_t (*hash)(char *, size_t)) {
53 unsigned long collisions = 0;
54 memset(Table,0,sizeof(Table));
55 char *prefixes[] = {"object", "message", "user", NULL};
56 for (int i = 0; prefixes[i] != NULL; i++) {
57 for (int j = 0; j < TABLE_SIZE/2; j++) {
58 char keyname[128];
59 size_t keylen = snprintf(keyname,sizeof(keyname),"%s:%d",
60 prefixes[i],j);
61 uint64_t bucket = hash(keyname,keylen) % TABLE_SIZE;
62 if (Table[bucket]) {
63 collisions++;
64 } else {
65 Table[bucket] = 1;
66 }
67 }
68 }
69 return collisions;
70}
71
72int main(void) {
73 printf("SHA1 : %lu\n", testHashingFunction(sha1Hash));

Callers 1

mainFunction · 0.85

Calls 1

hashFunction · 0.50

Tested by

no test coverage detected