diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-01-02 00:06:15 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-01-02 00:06:15 +0100 |
commit | 6337f29dd5310fd3c471ee1261077e755c3c2c39 (patch) | |
tree | f78160e3ee129b1f109a5ae02ce9ed730428d65a /src/gehashmap.h | |
parent | 9325ee9ae425d79c3c8d35fd706cdde03c0555c2 (diff) |
Add sets
Diffstat (limited to 'src/gehashmap.h')
-rw-r--r-- | src/gehashmap.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/gehashmap.h b/src/gehashmap.h index 832d047..ccd7a60 100644 --- a/src/gehashmap.h +++ b/src/gehashmap.h @@ -42,7 +42,7 @@ \ /* A structure representing an actual hashmap */ \ typedef struct { \ - size_t __size, /* The number of used buckets */ \ + size_t __size, /* The number of elements in the map */ \ __cap; /* The number of allocated buckets */ \ double __loadf; /* The % of the hashmap that must be * filled before the map grows */ \ @@ -54,6 +54,7 @@ int n##_set(n_t *, k, v); \ bool n##_get(n_t *, k, v *); \ bool n##_has(n_t *, k); \ + size_t n##_size(n_t *); \ int n##_remove(n_t *, k); \ int n##_resize(n_t *, size_t); \ bool n##_key_iseq(k, k); \ @@ -160,6 +161,13 @@ return n##_get(map, key, NULL); \ } \ \ + /* Function to get the number of elements in a hashmap. */ \ + size_t \ + n##_size(n_t *map) \ + { \ + return map->__size; \ + } \ + \ /* Function to remove an element with a given key from a hashmap. If * the key or value were dynamically allocated they will not be freed. * On error -1 is returned, otherwise 0 is returned. |