49 static void hsanity(t)
56 end = (
ub4)1<<(t->logsize);
58 printf(
"error: end %ld apos %ld\n", end, t->apos);
63 for (h=t->table[t->apos]; h && h != t->ipos; h = h->
next)
66 printf(
"error:ipos not in apos, apos is %ld\n", t->apos);
71 for (counter=0, i=0; i<end; ++i)
72 for (h=t->table[i]; h; h=h->
next)
74 if (counter != t->count)
75 printf(
"error: counter %ld t->count %ld\n", counter, t->count);
89 register ub4 newsize = (
ub4)1<<(++t->logsize);
90 register ub4 newmask = newsize-1;
92 register hitem **oldtab = t->table;
96 for (i=0; i<newsize; ++i) newtab[i] = (
hitem *)0;
101 for (i=newsize>>1; i--;)
103 register hitem *
this, *that, **newplace;
104 for (
this = oldtab[i];
this;)
108 newplace = &newtab[(that->
hval & newmask)];
109 that->
next = *newplace;
118 free((
char *)oldtab);
129 len = ((
ub4)1<<logsize);
131 for (i=0; i<len; ++i) t->
table[i] = (
hitem *)0;
147 free((
char *)t->table);
165 for (h = t->table[
y=(
x&t->mask)]; h; h = h->
next)
167 if ((
x == h->
hval) &&
169 !memcmp(key, h->
key, keyl))
189 register hitem *h,**hp;
193 for (h = t->table[(
y=(
x&t->mask))]; h; h = h->
next)
195 if ((
x == h->
hval) &&
197 !memcmp(key, h->
key, keyl))
209 if (++t->count > (
ub4)1<<(t->logsize))
241 if (!(h = t->ipos))
return FALSE;
244 for (ip = &t->table[t->apos]; *ip != h; ip = &(*ip)->
next)
268 return (t->ipos != (
hitem *)0);
281 ub4 end = (
ub4)1<<(t->logsize);
285 for (i=oldapos+1; i<end; ++i)
287 if (t->table[i&t->mask])
290 t->ipos = t->table[i];
296 for (i=0; i<=oldapos; ++i)
301 t->ipos = t->table[i];
319 for (i=0; i<=t->mask; ++i)
321 for (h=t->table[i], j=0; h; ++j, h=h->
next)
323 for (walk=stat; walk && (walk->
keyl != j); walk=walk->
next)
334 if (!stat || stat->
keyl > j) {walk->next=stat; stat=walk;}
348 for (walk=stat; walk; walk=walk->next)
350 total+=(double)walk->
hval*(
double)walk->keyl*(double)walk->keyl;
352 if (t->count) total /= (double)t->count;
353 else total = (
double)0;
357 for (walk=stat; walk; walk=walk->next)
359 printf(
"items %ld: %ld buckets\n", walk->keyl, walk->hval);
361 printf(
"\nbuckets: %ld items: %ld existing: %g\n\n",
362 ((
ub4)1<<t->logsize), t->count, total);
368 redel(t->space, stat);
static void hgrow(htab *t)
word hadd(htab *t, ub1 *key, ub4 keyl, void *stuff)
htab * hcreate(word logsize)
word hfind(htab *t, ub1 *key, ub4 keyl)
#define redel(root, item)