diff options
author | David Champion <dgc@bikeshed.us> | 2017-01-28 18:47:41 -0800 |
---|---|---|
committer | David Champion <dgc@bikeshed.us> | 2017-01-28 18:47:41 -0800 |
commit | 705801c1c2ce97531be392e6bd553c9671fdcb1e (patch) | |
tree | 168cab2aebf3a822511aa7e3d7b8019307ed542d /hash.c | |
parent | f318cb48d18ef1cc52c9c9e9e17c03e88c3c4f07 (diff) |
Add reentrant hash_walk() function for iterating down a hash table.
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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; +} + |