1 |
/* hash.c -- hash table maintenance |
/* hash.c -- hash table maintenance |
2 |
Copyright (C) 1995 Free Software Foundation, Inc. |
Copyright 1995, 2001 Free Software Foundation, Inc. |
3 |
Written by Greg McGary <gkm@gnu.ai.mit.edu> |
Written by Greg McGary <gkm@gnu.ai.mit.edu> |
4 |
|
|
5 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
120 |
return ((HASH_VACANT (*slot)) ? 0 : *slot); |
return ((HASH_VACANT (*slot)) ? 0 : *slot); |
121 |
} |
} |
122 |
|
|
123 |
void * |
const void * |
124 |
hash_insert (struct hash_table* ht, void *item) |
hash_insert (struct hash_table* ht, void *item) |
125 |
{ |
{ |
126 |
void **slot = hash_find_slot (ht, item); |
void **slot = hash_find_slot (ht, item); |
127 |
return hash_insert_at (ht, item, slot); |
return hash_insert_at (ht, item, slot); |
128 |
} |
} |
129 |
|
|
130 |
void * |
const void * |
131 |
hash_insert_at (struct hash_table* ht, void *item, void const *slot) |
hash_insert_at (struct hash_table* ht, void *item, void const *slot) |
132 |
{ |
{ |
133 |
void *old_item = *(void **) slot; |
const void *old_item = *(const void **) slot; |
134 |
if (HASH_VACANT (old_item)) |
if (HASH_VACANT (old_item)) |
135 |
{ |
{ |
136 |
ht->ht_fill++; |
ht->ht_fill++; |
142 |
return old_item; |
return old_item; |
143 |
} |
} |
144 |
|
|
145 |
void * |
const void * |
146 |
hash_delete (struct hash_table* ht, void const *item) |
hash_delete (struct hash_table* ht, void const *item) |
147 |
{ |
{ |
148 |
void **slot = hash_find_slot (ht, item); |
void **slot = hash_find_slot (ht, item); |
149 |
return hash_delete_at (ht, slot); |
return hash_delete_at (ht, slot); |
150 |
} |
} |
151 |
|
|
152 |
void * |
const void * |
153 |
hash_delete_at (struct hash_table* ht, void const *slot) |
hash_delete_at (struct hash_table* ht, void const *slot) |
154 |
{ |
{ |
155 |
void *item = *(void **) slot; |
const void *item = *(const void **) slot; |
156 |
if (!HASH_VACANT (item)) |
if (!HASH_VACANT (item)) |
157 |
{ |
{ |
158 |
*(void const **) slot = hash_deleted_item; |
*(void const **) slot = hash_deleted_item; |