diff --git a/m-dict.h b/m-dict.h index d7f7c6ef..8f77ccf0 100644 --- a/m-dict.h +++ b/m-dict.h @@ -228,7 +228,14 @@ map->used = 0; \ DICTI_CONTRACT(name, map); \ } \ - \ + \ + static inline bool \ + M_C(name,_empty_p)(const dict_t map) \ + { \ + DICTI_CONTRACT(name, map); \ + return map->used == 0; \ + } \ + \ static inline size_t \ M_C(name,_size)(const dict_t map) \ { \ @@ -1064,7 +1071,14 @@ typedef enum { DICTI_OA_CONTRACT(dict); \ return true; \ } \ - \ + \ + static inline bool \ + M_C(name,_empty_p)(const dict_t dict) \ + { \ + DICTI_OA_CONTRACT(dict); \ + return dict->count == 0; \ + } \ + \ static inline size_t \ M_C(name,_size)(const dict_t dict) \ { \ diff --git a/tests/test-mdict.c b/tests/test-mdict.c index 9baf0c09..8dafa997 100644 --- a/tests/test-mdict.c +++ b/tests/test-mdict.c @@ -69,10 +69,12 @@ static void test_data(void) { dict_str_t dict; int data_size = (int) array_string_size(v_str); - + dict_str_init (dict); + assert(dict_str_empty_p(dict)); for (int i = 0; i < data_size; ++i) { dict_str_set_at(dict, *array_string_cget(v_str, i), *array_string_cget(v_str, (i+1) % data_size)); + assert(!dict_str_empty_p(dict)); } assert(dict_str_size(dict) == 1227176);