#define _IDX_ITERATOR_FIRST (UINT_MAX - 1)
#define ITERATOR_FIRST ((Iterator) { .idx = _IDX_ITERATOR_FIRST, .next_key = NULL })
+#define ITERATOR_IS_FIRST(i) ((i).idx == _IDX_ITERATOR_FIRST)
/* Macros for type checking */
#define PTR_COMPATIBLE_WITH_HASHMAP_BASE(h) \
return _hashmap_first_key(HASHMAP_BASE(h), false);
}
-#define hashmap_clear_with_destructor(_s, _f) \
+#define hashmap_clear_with_destructor(h, f) \
({ \
+ Hashmap *_h = (h); \
void *_item; \
- while ((_item = hashmap_steal_first(_s))) \
- _f(_item); \
+ while ((_item = hashmap_steal_first(_h))) \
+ f(_item); \
+ _h; \
})
-#define hashmap_free_with_destructor(_s, _f) \
- ({ \
- hashmap_clear_with_destructor(_s, _f); \
- hashmap_free(_s); \
- })
-#define ordered_hashmap_clear_with_destructor(_s, _f) \
+#define hashmap_free_with_destructor(h, f) \
+ hashmap_free(hashmap_clear_with_destructor(h, f))
+#define ordered_hashmap_clear_with_destructor(h, f) \
({ \
+ OrderedHashmap *_h = (h); \
void *_item; \
- while ((_item = ordered_hashmap_steal_first(_s))) \
- _f(_item); \
- })
-#define ordered_hashmap_free_with_destructor(_s, _f) \
- ({ \
- ordered_hashmap_clear_with_destructor(_s, _f); \
- ordered_hashmap_free(_s); \
+ while ((_item = ordered_hashmap_steal_first(_h))) \
+ f(_item); \
+ _h; \
})
+#define ordered_hashmap_free_with_destructor(h, f) \
+ ordered_hashmap_free(ordered_hashmap_clear_with_destructor(h, f))
/* no hashmap_next */
void* ordered_hashmap_next(OrderedHashmap *h, const void *key);