From 62bb46a48cb9ecad96e1fe3591253243c2fb614e Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 2 Jan 2023 00:23:24 +0100 Subject: Add _empty() functions --- src/gehashmap.h | 8 ++++++++ src/geset.h | 7 +++++++ 2 files changed, 15 insertions(+) (limited to 'src') diff --git a/src/gehashmap.h b/src/gehashmap.h index ccd7a60..c85695c 100644 --- a/src/gehashmap.h +++ b/src/gehashmap.h @@ -55,6 +55,7 @@ bool n##_get(n_t *, k, v *); \ bool n##_has(n_t *, k); \ size_t n##_size(n_t *); \ + bool n##_empty(n_t *); \ int n##_remove(n_t *, k); \ int n##_resize(n_t *, size_t); \ bool n##_key_iseq(k, k); \ @@ -168,6 +169,13 @@ return map->__size; \ } \ \ + /* Function to check if a hashmap is empty . */ \ + bool \ + n##_empty(n_t *map) \ + { \ + return map->__size == 0; \ + } \ + \ /* 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. diff --git a/src/geset.h b/src/geset.h index da463f2..a87692b 100644 --- a/src/geset.h +++ b/src/geset.h @@ -38,6 +38,7 @@ int n##_add(n_t *, t); \ bool n##_has(n_t *, t); \ size_t n##_size(n_t *); \ + bool n##_empty(n_t *); \ int n##_remove(n_t *, t); \ int n##_resize(n_t *, size_t); \ bool int_n##_key_iseq(t, t); \ @@ -92,6 +93,12 @@ return int_n##_size(set); \ } \ \ + bool \ + n##_empty(n_t *set) \ + { \ + return int_n##_empty(set); \ + } \ + \ int \ n##_remove(n_t *set, t e) \ { \ -- cgit v1.2.3