From 76e4df24d5fb92816bce123eea2d4ca2b91d95c8 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 25 Nov 2009 21:18:50 -0800 Subject: [PATCH 1/1] hmap: New function hmap_is_empty(). --- src/libpspp/hmap.h | 10 ++++++++++ tests/libpspp/hmap-test.c | 1 + 2 files changed, 11 insertions(+) diff --git a/src/libpspp/hmap.h b/src/libpspp/hmap.h index c9e764de..1592f803 100644 --- a/src/libpspp/hmap.h +++ b/src/libpspp/hmap.h @@ -115,6 +115,7 @@ } */ +#include #include #include @@ -182,6 +183,7 @@ static inline struct hmap_node *hmap_next (const struct hmap *, const struct hmap_node *); /* Counting. */ +static bool hmap_is_empty (const struct hmap *); static inline size_t hmap_count (const struct hmap *); static inline size_t hmap_capacity (const struct hmap *); @@ -442,6 +444,14 @@ hmap_next (const struct hmap *map, const struct hmap_node *node) : hmap_first_nonempty_bucket__ (map, (node->hash & map->mask) + 1)); } +/* Returns true if MAP currently contains no data items, false + otherwise. */ +static inline bool +hmap_is_empty (const struct hmap *map) +{ + return map->count == 0; +} + /* Returns the number of data items currently in MAP. */ static inline size_t hmap_count (const struct hmap *map) diff --git a/tests/libpspp/hmap-test.c b/tests/libpspp/hmap-test.c index 3b336906..64511b7b 100644 --- a/tests/libpspp/hmap-test.c +++ b/tests/libpspp/hmap-test.c @@ -342,6 +342,7 @@ check_hmap (struct hmap *hmap, const int data[], size_t cnt, size_t i, j; int *order; + check (hmap_is_empty (hmap) == (cnt == 0)); check (hmap_count (hmap) == cnt); check (cnt <= hmap_capacity (hmap)); -- 2.30.2