summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorDavid Champion <dgc@bikeshed.us>2017-01-28 18:47:41 -0800
committerDavid Champion <dgc@bikeshed.us>2017-01-28 18:47:41 -0800
commit705801c1c2ce97531be392e6bd553c9671fdcb1e (patch)
tree168cab2aebf3a822511aa7e3d7b8019307ed542d /hash.c
parentf318cb48d18ef1cc52c9c9e9e17c03e88c3c4f07 (diff)
Add reentrant hash_walk() function for iterating down a hash table.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index c8dbaeba..d87a3218 100644
--- a/hash.c
+++ b/hash.c
@@ -297,3 +297,30 @@ void hash_destroy (HASH **ptr, void (*destroy) (void *))
FREE (&pptr->table);
FREE (ptr); /* __FREE_CHECKED__ */
}
+
+struct hash_elem *hash_walk(const HASH *table, struct hash_walk_state *state)
+{
+ if (state->last && state->last->next)
+ {
+ state->last = state->last->next;
+ return state->last;
+ }
+
+ if (state->last)
+ state->index++;
+
+ while (state->index < table->nelem)
+ {
+ if (table->table[state->index])
+ {
+ state->last = table->table[state->index];
+ return state->last;
+ }
+ state->index++;
+ }
+
+ state->index = 0;
+ state->last = NULL;
+ return NULL;
+}
+