From 17f5190ade3350b57c48a3c8f6e59f4361823685 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 12 Dec 2010 02:42:45 -0500 Subject: [PATCH] Added hash_iter() function, for iterating all matching entries in a hashtable. --- mojoshader_common.c | 27 +++++++++++++++++++++++++++ mojoshader_internal.h | 1 + 2 files changed, 28 insertions(+) diff --git a/mojoshader_common.c b/mojoshader_common.c index 9cdd76c8..eac261e8 100644 --- a/mojoshader_common.c +++ b/mojoshader_common.c @@ -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; diff --git a/mojoshader_internal.h b/mojoshader_internal.h index 03654547..0b58c904 100644 --- a/mojoshader_internal.h +++ b/mojoshader_internal.h @@ -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);