42 |
|
} |
43 |
|
|
44 |
|
|
45 |
< |
int |
46 |
< |
lu_hash(s) /* hash a nul-terminated string */ |
45 |
> |
long |
46 |
> |
lu_shash(s) /* hash a nul-terminated string */ |
47 |
|
register char *s; |
48 |
|
{ |
49 |
< |
register int h = 0; |
49 |
> |
register int i = 0; |
50 |
> |
register long h = 0; |
51 |
|
|
52 |
|
while (*s) |
53 |
< |
h = (h<<1 & 0x7fff) ^ (*s++ & 0xff); |
53 |
> |
h ^= (long)(*s++ & 0xff) << (i++ & 15); |
54 |
|
return(h); |
55 |
|
} |
56 |
|
|
60 |
|
register LUTAB *tbl; |
61 |
|
char *key; |
62 |
|
{ |
63 |
< |
int hval, i; |
64 |
< |
register int ndx; |
65 |
< |
LUENT *oldtabl; |
63 |
> |
long hval; |
64 |
> |
int i; |
65 |
> |
register int ndx; |
66 |
> |
register LUENT *oldtabl; |
67 |
|
/* look up object */ |
68 |
< |
hval = lu_hash(key); |
68 |
> |
hval = (*tbl->hashf)(key); |
69 |
|
tryagain: |
70 |
|
for (i = 0; i < tbl->tsiz; i++) { |
71 |
|
ndx = (hval + i*i) % tbl->tsiz; |
72 |
< |
if (tbl->tabl[ndx].key == NULL || |
73 |
< |
!strcmp(tbl->tabl[ndx].key, key)) |
72 |
> |
if (tbl->tabl[ndx].key == NULL) { |
73 |
> |
tbl->tabl[ndx].hval = hval; |
74 |
|
return(&tbl->tabl[ndx]); |
75 |
+ |
} |
76 |
+ |
if ( tbl->tabl[ndx].hval == hval && (tbl->keycmp == NULL || |
77 |
+ |
!(*tbl->keycmp)(tbl->tabl[ndx].key, key)) ) |
78 |
+ |
return(&tbl->tabl[ndx]); |
79 |
|
} |
80 |
|
/* table is full, reallocate */ |
81 |
|
oldtabl = tbl->tabl; |
89 |
|
} |
90 |
|
if (!ndx) |
91 |
|
goto tryagain; |
92 |
+ |
/* |
93 |
+ |
* The following code may fail if the user has reclaimed many |
94 |
+ |
* deleted entries and the system runs out of memory in a |
95 |
+ |
* recursive call to lu_find(). |
96 |
+ |
*/ |
97 |
|
while (ndx--) |
98 |
|
if (oldtabl[ndx].key != NULL) |
99 |
|
if (oldtabl[ndx].data != NULL) |