| 7 |
|
|
| 8 |
|
#include <stdio.h> |
| 9 |
|
#include <stdlib.h> |
| 10 |
+ |
#include <string.h> |
| 11 |
|
|
| 12 |
|
#include "lookup.h" |
| 13 |
|
|
| 13 |
– |
extern int |
| 14 |
– |
lu_strcmp( |
| 15 |
– |
const void *s1, |
| 16 |
– |
const void *s2 |
| 17 |
– |
) |
| 18 |
– |
{ |
| 19 |
– |
return strcmp((const char*)s1,(const char*)s2); |
| 20 |
– |
} |
| 14 |
|
|
| 15 |
< |
extern int |
| 15 |
> |
int |
| 16 |
|
lu_init( /* initialize tbl for at least nel elements */ |
| 17 |
< |
register LUTAB *tbl, |
| 17 |
> |
LUTAB *tbl, |
| 18 |
|
int nel |
| 19 |
|
) |
| 20 |
|
{ |
| 23 |
|
32749, 65521, 131071, 262139, 524287, 1048573, 2097143, |
| 24 |
|
4194301, 8388593, 0 |
| 25 |
|
}; |
| 26 |
< |
register int *hsp; |
| 26 |
> |
int *hsp; |
| 27 |
|
|
| 28 |
|
nel += nel>>1; /* 66% occupancy */ |
| 29 |
|
for (hsp = hsiztab; *hsp; hsp++) |
| 39 |
|
} |
| 40 |
|
|
| 41 |
|
|
| 42 |
< |
extern unsigned long |
| 42 |
> |
unsigned long |
| 43 |
|
lu_shash( /* hash a nul-terminated string */ |
| 44 |
< |
const void *s |
| 44 |
> |
const char *s |
| 45 |
|
) |
| 46 |
|
{ |
| 47 |
|
static unsigned char shuffle[256] = { |
| 70 |
|
106, 7, 164, 65, 222, 123, 24, 181, 82, 239, 140, |
| 71 |
|
41, 198, 99 |
| 72 |
|
}; |
| 73 |
< |
register int i = 0; |
| 74 |
< |
register unsigned long h = 0; |
| 75 |
< |
register unsigned const char *t = (unsigned const char *)s; |
| 73 |
> |
int i = 0; |
| 74 |
> |
unsigned long h = 0; |
| 75 |
> |
unsigned const char *t = (unsigned const char *)s; |
| 76 |
|
|
| 77 |
|
while (*t) |
| 78 |
|
h ^= (unsigned long)shuffle[*t++] << ((i+=11) & 0xf); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
|
| 84 |
< |
extern LUENT * |
| 84 |
> |
LUENT * |
| 85 |
|
lu_find( /* find a table entry */ |
| 86 |
< |
register LUTAB *tbl, |
| 86 |
> |
LUTAB *tbl, |
| 87 |
|
const char *key |
| 88 |
|
) |
| 89 |
|
{ |
| 90 |
|
unsigned long hval; |
| 91 |
|
int i, n; |
| 92 |
< |
register int ndx; |
| 93 |
< |
register LUENT *le; |
| 92 |
> |
int ndx; |
| 93 |
> |
LUENT *le; |
| 94 |
|
/* look up object */ |
| 95 |
|
if (tbl->tsiz == 0 && !lu_init(tbl, 1)) |
| 96 |
|
return(NULL); |
| 137 |
|
} |
| 138 |
|
|
| 139 |
|
|
| 140 |
< |
extern void |
| 140 |
> |
void |
| 141 |
|
lu_delete( /* delete a table entry */ |
| 142 |
< |
register LUTAB *tbl, |
| 143 |
< |
const char *key |
| 142 |
> |
LUTAB *tbl, |
| 143 |
> |
const char *key |
| 144 |
|
) |
| 145 |
|
{ |
| 146 |
< |
register LUENT *le; |
| 146 |
> |
LUENT *le; |
| 147 |
|
|
| 148 |
|
if ((le = lu_find(tbl, key)) == NULL) |
| 149 |
|
return; |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
|
| 159 |
< |
extern int |
| 159 |
> |
int |
| 160 |
|
lu_doall( /* loop through all valid table entries */ |
| 161 |
< |
register const LUTAB *tbl, |
| 162 |
< |
//int (*f)(const LUENT *) |
| 161 |
> |
const LUTAB *tbl, |
| 162 |
> |
/* int (*f)(const LUENT *, void *) */ |
| 163 |
|
lut_doallf_t *f, |
| 164 |
|
void *p |
| 165 |
|
) |
| 166 |
|
{ |
| 167 |
|
int rval = 0; |
| 168 |
< |
register const LUENT *tp; |
| 168 |
> |
const LUENT *tp; |
| 169 |
|
|
| 170 |
|
for (tp = tbl->tabl + tbl->tsiz; tp-- > tbl->tabl; ) |
| 171 |
|
if (tp->data != NULL) { |
| 181 |
|
} |
| 182 |
|
|
| 183 |
|
|
| 184 |
< |
extern void |
| 184 |
> |
void |
| 185 |
|
lu_done( /* free table and contents */ |
| 186 |
< |
register LUTAB *tbl |
| 186 |
> |
LUTAB *tbl |
| 187 |
|
) |
| 188 |
|
{ |
| 189 |
< |
register LUENT *tp; |
| 189 |
> |
LUENT *tp; |
| 190 |
|
|
| 191 |
|
if (!tbl->tsiz) |
| 192 |
|
return; |