Skip to content

Commit

Permalink
Added hash_iter() function, for iterating all matching entries in a h…
Browse files Browse the repository at this point in the history
…ashtable.
  • Loading branch information
icculus committed Dec 12, 2010
1 parent e737db0 commit 17f5190
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mojoshader_common.c
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions mojoshader_internal.h
Expand Up @@ -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);
Expand Down

0 comments on commit 17f5190

Please sign in to comment.