Implement HTAB_FOREACH_ELEM.
@@ -218,6 +218,19 @@ DEF_VARR (htab_ind_t)
static inline htab_size_t HTAB_OP_DEF (T, collisions) (HTAB (T) * htab) { \
HTAB_ASSERT (htab != NULL, "collisions", T); \
return htab->collisions; \
+ } \
+ \
+ static inline void HTAB_OP_DEF (T, foreach_elem) (HTAB (T) * htab, \
+ void (*func) (T el, void *arg), void *arg) { \
+ htab_ind_t *addr; \
+ htab_size_t i, size; \
+ HTAB_EL (T) * els_addr; \
+ \
+ HTAB_ASSERT (htab != NULL, "foreach_elem", T); \
+ els_addr = VARR_ADDR (HTAB_EL (T), htab->els); \
+ size = VARR_LENGTH (HTAB_EL (T), htab->els); \
+ for (i = 0; i < htab->els_bound; i++) \
+ if (els_addr[i].hash != HTAB_DELETED_HASH) func (els_addr[i].el, arg); \
}
#define HTAB_CREATE(T, V, S, H, EQ, A) (HTAB_OP (T, create) (&(V), S, H, EQ, NULL, A))
@@ -229,5 +242,6 @@ DEF_VARR (htab_ind_t)
#define HTAB_DO(T, V, EL, A, TAB_EL) (HTAB_OP (T, do) (V, EL, A, &(TAB_EL)))
#define HTAB_ELS_NUM(T, V) (HTAB_OP (T, els_num) (V))
#define HTAB_COLLISIONS(T, V) (HTAB_OP (T, collisions) (V))
+#define HTAB_FOREACH_ELEM(T, V, F, A) (HTAB_OP (T, foreach_elem) (V, F, A))
#endif /* #ifndef MIR_HTAB_H */
