+/* Initiate iteration over HT. Entries are obtained with
+ hash_table_iter_next, a typical iteration loop looking like this:
+
+ hash_table_iterator iter;
+ for (hash_table_iterate (ht, &iter); hash_table_iter_next (&iter); )
+ ... do something with iter.key and iter.value ...
+
+ The iterator does not need to be deallocated after use. The hash
+ table must not be modified while being iterated over. */
+
+void
+hash_table_iterate (struct hash_table *ht, hash_table_iterator *iter)
+{
+ iter->pos = ht->cells;
+ iter->end = ht->cells + ht->size;
+}
+
+/* Get the next hash table entry. ITER is an iterator object
+ initialized using hash_table_iterate. While there are more
+ entries, the key and value pointers are stored to ITER->key and
+ ITER->value respectively and 1 is returned. When there are no more
+ entries, 0 is returned.
+
+ If the hash table is modified between calls to this function, the
+ result is undefined. */
+
+int
+hash_table_iter_next (hash_table_iterator *iter)
+{
+ struct cell *c = iter->pos;
+ struct cell *end = iter->end;
+ for (; c < end; c++)
+ if (CELL_OCCUPIED (c))
+ {
+ iter->key = c->key;
+ iter->value = c->value;
+ iter->pos = c + 1;
+ return 1;
+ }
+ return 0;
+}
+