| 1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
| 11 |
|
#include <stdio.h> |
| 12 |
|
#include "lookup.h" |
| 13 |
|
|
| 14 |
+ |
#ifdef NOSTRUCTASS |
| 15 |
+ |
#define copystruct(d,s) bcopy((char *)(s),(char *)(d),sizeof(*(d))) |
| 16 |
+ |
#else |
| 17 |
+ |
#define copystruct(d,s) (*(d) = *(s)) |
| 18 |
+ |
#endif |
| 19 |
+ |
|
| 20 |
|
#define MEM_PTR char * |
| 21 |
|
|
| 22 |
|
extern MEM_PTR calloc(); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
|
| 51 |
< |
long |
| 51 |
> |
unsigned long |
| 52 |
|
lu_shash(s) /* hash a nul-terminated string */ |
| 53 |
|
char *s; |
| 54 |
|
{ |
| 79 |
|
41, 198, 99 |
| 80 |
|
}; |
| 81 |
|
register int i = 0; |
| 82 |
< |
register long h = 0; |
| 82 |
> |
register unsigned long h = 0; |
| 83 |
|
register unsigned char *t = (unsigned char *)s; |
| 84 |
|
|
| 85 |
|
while (*t) |
| 86 |
< |
h ^= (long)shuffle[*t++] << ((i+=11) & 0xf); |
| 86 |
> |
h ^= (unsigned long)shuffle[*t++] << ((i+=11) & 0xf); |
| 87 |
|
|
| 88 |
|
return(h); |
| 89 |
|
} |
| 94 |
|
register LUTAB *tbl; |
| 95 |
|
char *key; |
| 96 |
|
{ |
| 97 |
< |
long hval; |
| 97 |
> |
unsigned long hval; |
| 98 |
|
int i, n; |
| 99 |
|
register int ndx; |
| 100 |
|
register LUENT *le; |
| 101 |
|
/* look up object */ |
| 102 |
< |
if (tbl->tsiz == 0) |
| 103 |
< |
lu_init(tbl, 1); |
| 102 |
> |
if (tbl->tsiz == 0 && !lu_init(tbl, 1)) |
| 103 |
> |
return(NULL); |
| 104 |
|
hval = (*tbl->hashf)(key); |
| 105 |
|
tryagain: |
| 106 |
|
ndx = hval % tbl->tsiz; |
| 101 |
– |
le = &tbl->tabl[ndx]; |
| 107 |
|
for (i = 0, n = 1; i < tbl->tsiz; i++, n += 2) { |
| 108 |
+ |
le = &tbl->tabl[ndx]; |
| 109 |
|
if (le->key == NULL) { |
| 110 |
|
le->hval = hval; |
| 111 |
|
return(le); |
| 114 |
|
(tbl->keycmp == NULL || !(*tbl->keycmp)(le->key, key))) { |
| 115 |
|
return(le); |
| 116 |
|
} |
| 117 |
< |
le += n; |
| 112 |
< |
if ((ndx += n) >= tbl->tsiz) { /* this happens rarely */ |
| 117 |
> |
if ((ndx += n) >= tbl->tsiz) /* this happens rarely */ |
| 118 |
|
ndx = ndx % tbl->tsiz; |
| 114 |
– |
le = &tbl->tabl[ndx]; |
| 115 |
– |
} |
| 119 |
|
} |
| 120 |
|
/* table is full, reallocate */ |
| 121 |
|
le = tbl->tabl; |
| 127 |
|
tbl->ndel = i; |
| 128 |
|
return(NULL); |
| 129 |
|
} |
| 127 |
– |
if (!ndx) |
| 128 |
– |
goto tryagain; |
| 130 |
|
/* |
| 131 |
|
* The following code may fail if the user has reclaimed many |
| 132 |
|
* deleted entries and the system runs out of memory in a |
| 135 |
|
while (ndx--) |
| 136 |
|
if (le[ndx].key != NULL) |
| 137 |
|
if (le[ndx].data != NULL) |
| 138 |
< |
*lu_find(tbl, le[ndx].key) = le[ndx]; |
| 138 |
> |
copystruct(lu_find(tbl,le[ndx].key), &le[ndx]); |
| 139 |
|
else if (tbl->freek != NULL) |
| 140 |
|
(*tbl->freek)(le[ndx].key); |
| 141 |
|
free((MEM_PTR)le); |