X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fhmap.h;h=1592f803bedb17bd9c1ca4dc285f5bd6e72fd1c4;hb=84bbf9c2cabe154765e406114b5386bf309aed27;hp=e73d84fd153764ec96935c6242dc2388820c5757;hpb=9a331fe64eb814ae5c1322e21717a04fb254bf65;p=pspp-builds.git diff --git a/src/libpspp/hmap.h b/src/libpspp/hmap.h index e73d84fd..1592f803 100644 --- a/src/libpspp/hmap.h +++ b/src/libpspp/hmap.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 @@ -115,13 +115,16 @@ } */ +#include #include +#include /* Returns the data structure corresponding to the given NODE, assuming that NODE is embedded as the given MEMBER name in data type STRUCT. NODE must not be a null pointer. */ #define HMAP_DATA(NODE, STRUCT, MEMBER) \ - ((STRUCT *) ((char *) (NODE) - offsetof (STRUCT, MEMBER))) + (CHECK_POINTER_HAS_TYPE (NODE, struct hmap_node *), \ + UP_CAST (NODE, STRUCT, MEMBER)) /* Like HMAP_DATA, except that a null NODE yields a null pointer result. */ @@ -180,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 *); @@ -440,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)