static ulong hunt(HHSet *S, ulong h, ulong k, int kill) { int i = hhashsucc(S->T, h, 0); while (i >= 0) { ulong x = hhashget(S->T, h, i); if (S->cmp(k, x) == 0) { if (kill) hhashdel(S->T, h, i); return x; } i = hhashsucc(S->T, h, i + 1); } return 0; }
ulong count(HHash *T) { ulong m = 0; ulong h = 0; while (h < T->n) { int i = hhashsucc(T, h, 0); while (i >= 0) { ++m; i = hhashsucc(T, h, i + 1); } ++h; } return m; }
int main(void) { uint n = 16; HHash *T = hhashnew(n); uint x = rand()%n; test(hhashput(T,x,1)); uint i = hhashsucc(T,x,0); test(i == 0); hhashdel(T,x,i); test(hhashsucc(T,x,0) < 0); hhashfree(T); return 0; }
ulong fill(HHash *T) { ulong m = 0; for (ulong i = 0; i < 100; ++i) { ulong x = rand() % T->n; if (hhashsucc(T, x, 0) < 0) if (hhashput(T, x, x)) ++m; } return m; }
int main(void) { uint n = 16; HHash *T = hhashnew(n); uint x = 15; test(hhashput(T,x,1)); test(hhashsucc(T,x,0) == 0); test(hhashput(T,x,1)); test(hhashsucc(T,x,1) == 1); test(hhashput(T,x,1)); test(hhashsucc(T,x,2) == 2); test(T->m == 3); x = 14; test(hhashput(T,x,1)); test(hhashsucc(T,x,0) == 0); test(hhashput(T,x,1)); test(hhashsucc(T,x,1) == 1); test(!hhashput(T,x,1)); hhashfree(T); return 0; }
int main(void) { uint n = 16; HHash *T = hhashnew(n); uint x = rand()%n; test(hhashput(T,x,1)); test(hhashsucc(T,x,0) == 0); test(hhashput(T,x,1)); test(hhashsucc(T,x,1) == 1); test(hhashput(T,x,1)); test(hhashsucc(T,x,2) == 2); test(hhashput(T,x,1)); test(hhashsucc(T,x,3) == 3); test(!hhashput(T,x,1)); --x; test(hhashput(T,x,1)); test(hhashsucc(T,x,0) == 0); test(!hhashput(T,x,1)); hhashfree(T); return 0; }