silchashtable.c
- Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+ Author: Pekka Riikonen <priikone@silcnet.org>
Copyright (C) 2001 Pekka Riikonen
#define SILC_HASH_TABLE_SIZE 3
/* Produce the index by hashing the key */
-#define SILC_HASH_TABLE_HASH_F(f, c) \
+#define SILC_HASH_TABLE_HASH(f, c) \
((f)(key, (c)) % primesize[ht->table_size])
/* Check whether need to rehash */
void *compare_user_context)
{
SilcHashTableEntry *entry, prev = NULL;
- uint32 i = SILC_HASH_TABLE_HASH_F(hash, hash_user_context);
+ uint32 i = SILC_HASH_TABLE_HASH(hash, hash_user_context);
SILC_HT_DEBUG(("index %d key %p", i, key));
void *compare_user_context)
{
SilcHashTableEntry *entry, prev = NULL;
- uint32 i = SILC_HASH_TABLE_HASH_F(hash, hash_user_context);
+ uint32 i = SILC_HASH_TABLE_HASH(hash, hash_user_context);
SILC_HT_DEBUG(("index %d key %p context %p", i, key, context));
void *compare_user_context)
{
SilcHashTableEntry *entry;
- uint32 i = SILC_HASH_TABLE_HASH_F(hash, hash_user_context);
+ uint32 i = SILC_HASH_TABLE_HASH(hash, hash_user_context);
SILC_HT_DEBUG(("index %d key %p", i, key));
void *foreach_user_context)
{
SilcHashTableEntry *entry;
- uint32 i = SILC_HASH_TABLE_HASH_F(hash, hash_user_context);
+ uint32 i = SILC_HASH_TABLE_HASH(hash, hash_user_context);
SILC_HT_DEBUG(("index %d key %p", i, key));
void *hash_user_context)
{
SilcHashTableEntry *entry;
- uint32 i = SILC_HASH_TABLE_HASH_F(hash, hash_user_context);
+ uint32 i = SILC_HASH_TABLE_HASH(hash, hash_user_context);
SILC_HT_DEBUG(("index %d key %p", i, key));
void *hash_user_context)
{
SilcHashTableEntry *entry;
- uint32 i = SILC_HASH_TABLE_HASH_F(hash, hash_user_context);
+ uint32 i = SILC_HASH_TABLE_HASH(hash, hash_user_context);
SILC_HT_DEBUG(("index %d key %p", i, key));
(*entry)->key = key;
(*entry)->context = context;
+
+ if (SILC_HASH_REHASH_INC)
+ silc_hash_table_rehash(ht, 0);
}
/* Allocates new hash table and returns it. If the `table_size' is not
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 *table, e, tmp;
uint32 table_size, size_index;
+ SILC_HT_DEBUG(("Start"));
+
if (new_size)
silc_hash_table_primesize(new_size, &size_index);
else
SilcHashTableEntry *table, e, tmp;
uint32 table_size, size_index;
+ SILC_HT_DEBUG(("Start"));
+
if (new_size)
silc_hash_table_primesize(new_size, &size_index);
else
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