version 1.9, 2000/06/11 07:54:32 |
version 1.10, 2002/06/15 18:24:56 |
Line 67 __RCSID("$NetBSD$"); |
|
Line 67 __RCSID("$NetBSD$"); |
|
* defined: |
* defined: |
*/ |
*/ |
|
|
static void RebuildTable __P((Hash_Table *)); |
static void RebuildTable(Hash_Table *); |
|
|
/* |
/* |
* The following defines the ratio of # entries to # buckets |
* The following defines the ratio of # entries to # buckets |
Line 83 static void RebuildTable __P((Hash_Table |
|
Line 83 static void RebuildTable __P((Hash_Table |
|
* |
* |
* This routine just sets up the hash table. |
* This routine just sets up the hash table. |
* |
* |
|
* Input: |
|
* t Structure to to hold table. |
|
* numBuckets How many buckets to create for starters. This |
|
* number is rounded up to a power of two. If |
|
* <= 0, a reasonable default is chosen. The |
|
* table will grow in size later as needed. |
|
* |
* Results: |
* Results: |
* None. |
* None. |
* |
* |
Line 93 static void RebuildTable __P((Hash_Table |
|
Line 100 static void RebuildTable __P((Hash_Table |
|
*/ |
*/ |
|
|
void |
void |
Hash_InitTable(t, numBuckets) |
Hash_InitTable(Hash_Table *t, int numBuckets) |
register Hash_Table *t; /* Structure to use to hold table. */ |
|
int numBuckets; /* How many buckets to create for starters. |
|
* This number is rounded up to a power of |
|
* two. If <= 0, a reasonable default is |
|
* chosen. The table will grow in size later |
|
* as needed. */ |
|
{ |
{ |
register int i; |
int i; |
register struct Hash_Entry **hp; |
struct Hash_Entry **hp; |
|
|
/* |
/* |
* Round up the size to a power of two. |
* Round up the size to a power of two. |
Line 140 Hash_InitTable(t, numBuckets) |
|
Line 141 Hash_InitTable(t, numBuckets) |
|
*/ |
*/ |
|
|
void |
void |
Hash_DeleteTable(t) |
Hash_DeleteTable(Hash_Table *t) |
Hash_Table *t; |
|
{ |
{ |
register struct Hash_Entry **hp, *h, *nexth = NULL; |
struct Hash_Entry **hp, *h, *nexth = NULL; |
register int i; |
int i; |
|
|
for (hp = t->bucketPtr, i = t->size; --i >= 0;) { |
for (hp = t->bucketPtr, i = t->size; --i >= 0;) { |
for (h = *hp++; h != NULL; h = nexth) { |
for (h = *hp++; h != NULL; h = nexth) { |
Line 168 Hash_DeleteTable(t) |
|
Line 168 Hash_DeleteTable(t) |
|
* |
* |
* Searches a hash table for an entry corresponding to key. |
* Searches a hash table for an entry corresponding to key. |
* |
* |
|
* Input: |
|
* t Hash table to search. |
|
* key A hash key. |
|
* |
* Results: |
* Results: |
* The return value is a pointer to the entry for key, |
* The return value is a pointer to the entry for key, |
* if key was present in the table. If key was not |
* if key was present in the table. If key was not |
Line 180 Hash_DeleteTable(t) |
|
Line 184 Hash_DeleteTable(t) |
|
*/ |
*/ |
|
|
Hash_Entry * |
Hash_Entry * |
Hash_FindEntry(t, key) |
Hash_FindEntry(Hash_Table *t, char *key) |
Hash_Table *t; /* Hash table to search. */ |
|
char *key; /* A hash key. */ |
|
{ |
{ |
register Hash_Entry *e; |
Hash_Entry *e; |
register unsigned h; |
unsigned h; |
register char *p; |
char *p; |
|
|
for (h = 0, p = key; *p;) |
for (h = 0, p = key; *p;) |
h = (h << 5) - h + *p++; |
h = (h << 5) - h + *p++; |
Line 205 Hash_FindEntry(t, key) |
|
Line 207 Hash_FindEntry(t, key) |
|
* Searches a hash table for an entry corresponding to |
* Searches a hash table for an entry corresponding to |
* key. If no entry is found, then one is created. |
* key. If no entry is found, then one is created. |
* |
* |
|
* Input: |
|
* t Hash table to search. |
|
* key A hash key. |
|
* newPtr Filled in with TRUE if new entry created, |
|
* FALSE otherwise. |
|
* |
* Results: |
* Results: |
* The return value is a pointer to the entry. If *newPtr |
* The return value is a pointer to the entry. If *newPtr |
* isn't NULL, then *newPtr is filled in with TRUE if a |
* isn't NULL, then *newPtr is filled in with TRUE if a |
Line 217 Hash_FindEntry(t, key) |
|
Line 225 Hash_FindEntry(t, key) |
|
*/ |
*/ |
|
|
Hash_Entry * |
Hash_Entry * |
Hash_CreateEntry(t, key, newPtr) |
Hash_CreateEntry(Hash_Table *t, char *key, Boolean *newPtr) |
register Hash_Table *t; /* Hash table to search. */ |
|
char *key; /* A hash key. */ |
|
Boolean *newPtr; /* Filled in with TRUE if new entry created, |
|
* FALSE otherwise. */ |
|
{ |
{ |
register Hash_Entry *e; |
Hash_Entry *e; |
register unsigned h; |
unsigned h; |
register char *p; |
char *p; |
int keylen; |
int keylen; |
struct Hash_Entry **hp; |
struct Hash_Entry **hp; |
|
|
Line 284 Hash_CreateEntry(t, key, newPtr) |
|
Line 288 Hash_CreateEntry(t, key, newPtr) |
|
*/ |
*/ |
|
|
void |
void |
Hash_DeleteEntry(t, e) |
Hash_DeleteEntry(Hash_Table *t, Hash_Entry *e) |
Hash_Table *t; |
|
Hash_Entry *e; |
|
{ |
{ |
register Hash_Entry **hp, *p; |
Hash_Entry **hp, *p; |
|
|
if (e == NULL) |
if (e == NULL) |
return; |
return; |
Line 312 Hash_DeleteEntry(t, e) |
|
Line 314 Hash_DeleteEntry(t, e) |
|
* This procedure sets things up for a complete search |
* This procedure sets things up for a complete search |
* of all entries recorded in the hash table. |
* of all entries recorded in the hash table. |
* |
* |
|
* Input: |
|
* t Table to be searched. |
|
* searchPtr Area in which to keep state about search. |
|
* |
* Results: |
* Results: |
* The return value is the address of the first entry in |
* The return value is the address of the first entry in |
* the hash table, or NULL if the table is empty. |
* the hash table, or NULL if the table is empty. |
Line 325 Hash_DeleteEntry(t, e) |
|
Line 331 Hash_DeleteEntry(t, e) |
|
*/ |
*/ |
|
|
Hash_Entry * |
Hash_Entry * |
Hash_EnumFirst(t, searchPtr) |
Hash_EnumFirst(Hash_Table *t, Hash_Search *searchPtr) |
Hash_Table *t; /* Table to be searched. */ |
|
register Hash_Search *searchPtr;/* Area in which to keep state |
|
* about search.*/ |
|
{ |
{ |
searchPtr->tablePtr = t; |
searchPtr->tablePtr = t; |
searchPtr->nextIndex = 0; |
searchPtr->nextIndex = 0; |
Line 342 Hash_EnumFirst(t, searchPtr) |
|
Line 345 Hash_EnumFirst(t, searchPtr) |
|
* Hash_EnumNext -- |
* Hash_EnumNext -- |
* This procedure returns successive entries in the hash table. |
* This procedure returns successive entries in the hash table. |
* |
* |
|
* Input: |
|
* searchPtr Area used to keep state about search. |
|
* |
* Results: |
* Results: |
* The return value is a pointer to the next HashEntry |
* The return value is a pointer to the next HashEntry |
* in the table, or NULL when the end of the table is |
* in the table, or NULL when the end of the table is |
Line 355 Hash_EnumFirst(t, searchPtr) |
|
Line 361 Hash_EnumFirst(t, searchPtr) |
|
*/ |
*/ |
|
|
Hash_Entry * |
Hash_Entry * |
Hash_EnumNext(searchPtr) |
Hash_EnumNext(Hash_Search *searchPtr) |
register Hash_Search *searchPtr; /* Area used to keep state about |
|
search. */ |
|
{ |
{ |
register Hash_Entry *e; |
Hash_Entry *e; |
Hash_Table *t = searchPtr->tablePtr; |
Hash_Table *t = searchPtr->tablePtr; |
|
|
/* |
/* |
Line 401 Hash_EnumNext(searchPtr) |
|
Line 405 Hash_EnumNext(searchPtr) |
|
*/ |
*/ |
|
|
static void |
static void |
RebuildTable(t) |
RebuildTable(Hash_Table *t) |
register Hash_Table *t; |
|
{ |
{ |
register Hash_Entry *e, *next = NULL, **hp, **xp; |
Hash_Entry *e, *next = NULL, **hp, **xp; |
register int i, mask; |
int i, mask; |
register Hash_Entry **oldhp; |
Hash_Entry **oldhp; |
int oldsize; |
int oldsize; |
|
|
oldhp = t->bucketPtr; |
oldhp = t->bucketPtr; |