Skip to content
Permalink
Browse files
Added hash_iter() function, for iterating all matching entries in a h…
…ashtable.
  • Loading branch information
icculus committed Dec 12, 2010
1 parent e737db0 commit 17f5190ade3350b57c48a3c8f6e59f4361823685
Showing with 28 additions and 0 deletions.
  1. +27 −0 mojoshader_common.c
  2. +1 −0 mojoshader_internal.h
@@ -59,6 +59,33 @@ int hash_find(const HashTable *table, const void *key, const void **_value)
return 0;
} // hash_find

int hash_iter(const HashTable *table, const void *key,
const void **_value, void **iter)
{
HashItem *i = *iter;
if (i == NULL)
i = table->table[calc_hash(table, key)];
else
i = i->next;

while (i != NULL)
{
if (table->keymatch(key, i->key, table->data))
{
*_value = i->value;
*iter = i;
return 1;
} // if
i = i->next;
} // while

// no more matches.
*_value = NULL;
*iter = NULL;
return 0;
} // hash_iter


int hash_insert(HashTable *table, const void *key, const void *value)
{
HashItem *item = NULL;
@@ -177,6 +177,7 @@ void hash_destroy(HashTable *table);
int hash_insert(HashTable *table, const void *key, const void *value);
int hash_remove(HashTable *table, const void *key);
int hash_find(const HashTable *table, const void *key, const void **_value);
int hash_iter(const HashTable *table, const void *key, const void **_value, void **iter);

uint32 hash_hash_string(const void *sym, void *unused);
int hash_keymatch_string(const void *a, const void *b, void *unused);

0 comments on commit 17f5190

Please sign in to comment.