silchashtable.c
- Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+ Author: Pekka Riikonen <priikone@silcnet.org>
Copyright (C) 2001 Pekka Riikonen
void *foreach_user_context)
{
SilcHashTableEntry *entry;
+ bool auto_rehash;
uint32 i = SILC_HASH_TABLE_HASH(hash, hash_user_context);
SILC_HT_DEBUG(("index %d key %p", i, key));
+ auto_rehash = ht->auto_rehash;
+ ht->auto_rehash = FALSE;
+
entry = &ht->table[i];
if (compare) {
while (*entry) {
entry = &(*entry)->next;
}
}
+
+ ht->auto_rehash = auto_rehash;
}
/* Internal routine to add new key to the hash table */
SilcHashFunction hash,
void *hash_user_context,
SilcHashCompare compare,
- void *compare_user_context)
+ void *compare_user_context,
+ SilcHashDestructor destructor,
+ void *destructor_user_context)
{
SilcHashTableEntry *entry, prev, e;
if (prev && e->next)
prev->next = e->next;
- if (ht->destructor)
- ht->destructor(e->key, e->context, ht->destructor_user_context);
+ if (destructor) {
+ destructor(e->key, e->context, destructor_user_context);
+ } else {
+ if (ht->destructor)
+ ht->destructor(e->key, e->context, ht->destructor_user_context);
+ }
silc_free(e);
ht->entry_count--;
SilcHashFunction hash,
void *hash_user_context,
SilcHashCompare compare,
- void *compare_user_context)
+ void *compare_user_context,
+ SilcHashDestructor destructor,
+ void *destructor_user_context)
{
SilcHashTableEntry *entry, prev, e;
if (prev && e->next)
prev->next = e->next;
- if (ht->destructor)
- ht->destructor(e->key, e->context, ht->destructor_user_context);
+ if (destructor) {
+ destructor(e->key, e->context, destructor_user_context);
+ } else {
+ if (ht->destructor)
+ ht->destructor(e->key, e->context, ht->destructor_user_context);
+ }
silc_free(e);
ht->entry_count--;
{
SilcHashTableEntry e, tmp;
int i;
+ bool auto_rehash;
if (!foreach)
return;
+ auto_rehash = ht->auto_rehash;
+ ht->auto_rehash = FALSE;
for (i = 0; i < primesize[ht->table_size]; i++) {
e = ht->table[i];
while (e) {
e = tmp;
}
}
+ ht->auto_rehash = auto_rehash;
}
/* Rehashs the hash table. The size of the new hash table is provided
htl->ht = ht;
htl->entry = NULL;
htl->index = 0;
+ htl->auto_rehash = ht->auto_rehash;
+
+ /* Disallow rehashing of the table while traversing the table */
+ ht->auto_rehash = FALSE;
+}
+
+/* Resets the `htl' SilcHashTableList. */
+
+void silc_hash_table_list_reset(SilcHashTableList *htl)
+{
+ /* Set back the original auto rehash value to the table */
+ htl->ht->auto_rehash = htl->auto_rehash;
}
/* Returns always the next entry in the hash table into the `key' and