@@ -153,14 +153,23 @@ extern "C" {
153153} while (0)
154154
155155/*
156- * Return the number of entries in the hash map .
156+ * Return the number of entries in the hashmap .
157157 *
158158 * Parameters:
159159 * const HASHMAP(<key_type>, <data_type>) *h - hashmap pointer
160160 */
161161#define hashmap_size (h ) \
162162 ((typeof((h)->map_base.size))(h)->map_base.size)
163163
164+ /*
165+ * Return true if the hashmap is empty.
166+ *
167+ * Parameters:
168+ * const HASHMAP(<key_type>, <data_type>) *h - hashmap pointer
169+ */
170+ #define hashmap_empty (h ) \
171+ (hashmap_size(h) == 0)
172+
164173/*
165174 * Set the hashmap's initial allocation size such that no rehashes are
166175 * required to fit the specified number of entries.
@@ -174,6 +183,17 @@ extern "C" {
174183#define hashmap_reserve (h , capacity ) \
175184 hashmap_base_reserve(&(h)->map_base, capacity)
176185
186+ /*
187+ * Get the hashmap's present allocation size.
188+ *
189+ * Parameters:
190+ * HASHMAP(<key_type>, <data_type>) *h - hashmap pointer
191+ *
192+ * Returns 0 on success, or -errno on failure.
193+ */
194+ #define hashmap_capacity (h ) \
195+ ((typeof((h)->map_base.table_size))(h)->map_base.table_size)
196+
177197/*
178198 * Add a new entry to the hashmap. If an entry with a matching key
179199 * already exists -EEXIST is returned.
@@ -205,6 +225,15 @@ extern "C" {
205225 (typeof((h)->map_types->t_data))hashmap_base_get(&(h)->map_base, (const void *)__map_key); \
206226})
207227
228+ /*
229+ * Return true if the hashmap contains an entry with the specified key.
230+ *
231+ * Parameters:
232+ * const HASHMAP(<key_type>, <data_type>) *h - hashmap pointer
233+ */
234+ #define hashmap_contains (h , key ) \
235+ (hashmap_get(h, key) != NULL)
236+
208237/*
209238 * Remove an entry with the specified key from the map.
210239 *
@@ -271,6 +300,20 @@ extern "C" {
271300#define hashmap_iter_next (iter ) \
272301 hashmap_base_iter_next((iter)->iter_map, &(iter)->iter_pos)
273302
303+ /*
304+ * Do a constant-time lookup of a hashmap entry and return an iterator to it.
305+ * This provides an efficient way to access and remove an entry without
306+ * performing two lookups.
307+ *
308+ * Parameters:
309+ * HASHMAP(<key_type>, <data_type>) *h - hashmap pointer
310+ * <key_type> *key - pointer to the key to lookup
311+ *
312+ * Returns a valid iterator if the key exists, otherwise an invalid iterator.
313+ */
314+ #define hashmap_iter_find (h , key ) \
315+ ((HASHMAP_ITER(*(h))){ &(h)->map_base, hashmap_base_iter_find(&(h)->map_base, key) })
316+
274317/*
275318 * Remove the hashmap entry pointed to by this iterator and advance the
276319 * iterator to the next entry.
0 commit comments