ref: 8e631b19c4bf009a69489fcdd2e0b8c84a104a15
parent: 03f72f7bc34e43a767cf3686ac3c0f55cf7c64d5
author: Jacob Moody <moody@posixcafe.org>
date: Sun May 22 18:38:02 EDT 2022
attempt actual int hashing Prototyping for what could end up as a 'default' for ints
--- a/hash.h
+++ b/hash.h
@@ -8,6 +8,7 @@
struct Hmap {
uvlong (*hash)(void*);
int (*cmp)(void*,void*);
+
int nbs;
int nsz;
--- a/test.c
+++ b/test.c
@@ -62,9 +62,14 @@
uvlong
runehash(void *p)
{
+ uvlong s;
Hkey k;
+
k.p = p;
- return k.v;
+ s = 2654435761L;
+ s *= 1<<sizeof(p);
+ s *= k.v;
+ return s>>sizeof(p);
}
int
@@ -82,6 +87,8 @@
Hmap *h;
char *v;
char *p, *p2;
+ char keys[] = "abcdefghijklmnopqrstuvwxyz";
+ int i;
h = hmapalloc(runehash, runecmp, 16, sizeof(char*));
@@ -90,6 +97,11 @@
assert(hmapset(&h, k.p, &v, nil) == 0);
assert(hmapset(&h, k.p, &v, &p2) == 1);
assert(p2 == v);
+
+ for(i=0; i < sizeof keys - 1; i++){
+ k.v = keys[i];
+ hmapset(&h, k.p, &v, nil);
+ }
assert(hmapget(h, k.p, &p) == 0);
assert(p && *p);