pmhash: permite iterar os valores.
[cascardo/declara.git] / lib / pmhash.c
index 5bada1e..2bf6c43 100644 (file)
@@ -95,3 +95,17 @@ void pmhash_del(struct pmhash *pmhash)
        }
        free(pmhash);
 }
+
+void * pmhash_next(struct pmhash *pmhash, void **iter)
+{
+       int i;
+       struct item *item = *iter;
+       if (item == NULL)
+               i = 0;
+       else
+               i = item - pmhash->items + 1;
+       if (i >= (int) pmhash->len)
+               return NULL;
+       *iter = pmhash->items + i;
+       return pmhash->items[i].val;
+}