Implemented hash_iter_keys().
authorRyan C. Gordon <icculus@icculus.org>
Fri, 11 Nov 2011 02:20:05 -0500
changeset 1065 bb021d539ec5
parent 1064 d3f0f4cf84f2
child 1066 ff14db741834
Implemented hash_iter_keys().
mojoshader_common.c
mojoshader_internal.h
--- a/mojoshader_common.c	Fri Nov 11 02:19:48 2011 -0500
+++ b/mojoshader_common.c	Fri Nov 11 02:20:05 2011 -0500
@@ -85,6 +85,33 @@
     return 0;
 } // hash_iter
 
+int hash_iter_keys(const HashTable *table, const void **_key, void **iter)
+{
+    HashItem *item = *iter;
+    int idx = 0;
+
+    if (item != NULL)
+    {
+        const HashItem *orig = item;
+        item = item->next;
+        if (item == NULL)
+            idx = calc_hash(table, orig->key) + 1;
+    } // if
+
+    while (!item && (idx < table->table_len))
+        item = table->table[idx++];  // skip empty buckets...
+
+    if (item == NULL)  // no more matches?
+    {
+        *_key = NULL;
+        *iter = NULL;
+        return 0;
+    } // if
+
+    *_key = item->key;
+    *iter = item;
+    return 1;
+} // hash_iter_keys
 
 int hash_insert(HashTable *table, const void *key, const void *value)
 {
--- a/mojoshader_internal.h	Fri Nov 11 02:19:48 2011 -0500
+++ b/mojoshader_internal.h	Fri Nov 11 02:20:05 2011 -0500
@@ -193,6 +193,7 @@
 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);
+int hash_iter_keys(const HashTable *table, const void **_key, void **iter);
 
 uint32 hash_hash_string(const void *sym, void *unused);
 int hash_keymatch_string(const void *a, const void *b, void *unused);