From: Ben Pfaff Date: Thu, 26 Nov 2009 05:19:04 +0000 (-0800) Subject: hmapx: New function hmapx_is_empty(). X-Git-Tag: lenny-x64-build62~1 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5043ca7450640f23c1a5957c967f377f0fbefa19;p=pspp-builds.git hmapx: New function hmapx_is_empty(). --- 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));