From 5043ca7450640f23c1a5957c967f377f0fbefa19 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 25 Nov 2009 21:19:04 -0800 Subject: [PATCH] hmapx: New function hmapx_is_empty(). --- src/libpspp/hmapx.c | 4 ++-- src/libpspp/hmapx.h | 11 ++++++++++- tests/libpspp/hmapx-test.c | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/libpspp/hmapx.c b/src/libpspp/hmapx.c index d7324508..437b2bdb 100644 --- a/src/libpspp/hmapx.c +++ b/src/libpspp/hmapx.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,7 +32,7 @@ hmapx_destroy (struct hmapx *map) { if (map != NULL) { - if (hmapx_count (map) > 0) + if (!(hmapx_is_empty (map))) { struct hmapx_node *node, *next; for (node = hmapx_first (map); node != NULL; node = next) diff --git a/src/libpspp/hmapx.h b/src/libpspp/hmapx.h index 32a4452f..d463504a 100644 --- a/src/libpspp/hmapx.h +++ b/src/libpspp/hmapx.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -165,6 +165,7 @@ static inline struct hmapx_node *hmapx_next (const struct hmapx *, const struct hmapx_node *); /* Counting. */ +static inline bool hmapx_is_empty (const struct hmapx *); static inline size_t hmapx_count (const struct hmapx *); static inline size_t hmapx_capacity (const struct hmapx *); @@ -404,6 +405,14 @@ hmapx_next (const struct hmapx *map, const struct hmapx_node *node) return HMAP_NEXT (node, struct hmapx_node, hmap_node, &map->hmap); } +/* Returns true if MAP currently contains no data items, false + otherwise. */ +static inline bool +hmapx_is_empty (const struct hmapx *map) +{ + return hmap_is_empty (&map->hmap); +} + /* Returns the number of data items currently in MAP. */ static inline size_t hmapx_count (const struct hmapx *map) diff --git a/tests/libpspp/hmapx-test.c b/tests/libpspp/hmapx-test.c index fc08ca61..5ad5d572 100644 --- a/tests/libpspp/hmapx-test.c +++ b/tests/libpspp/hmapx-test.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -262,6 +262,7 @@ check_hmapx (struct hmapx *hmapx, const int data[], size_t cnt, size_t i, j; int *order; + check (hmapx_is_empty (hmapx) == (cnt == 0)); check (hmapx_count (hmapx) == cnt); check (cnt <= hmapx_capacity (hmapx)); -- 2.30.2