From: Ben Pfaff Date: Tue, 8 Dec 2009 01:02:00 +0000 (-0800) Subject: hmap: Add function to mark an hmap_node as "null" and check for the mark. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e68c0730d0753e9a796a0d6d4b95933f7cdfbd2;p=openvswitch hmap: Add function to mark an hmap_node as "null" and check for the mark. This is useful in cases where one might want to know whether an hmap_node is actually part of an hmap, without using a separate variable to indicate it. --- diff --git a/lib/hmap.h b/lib/hmap.h index 5396c79b..c78dddac 100644 --- a/lib/hmap.h +++ b/lib/hmap.h @@ -33,6 +33,24 @@ static inline size_t hmap_node_hash(const struct hmap_node *node) return node->hash; } +#define HMAP_NODE_NULL ((struct hmap_node *) 1) + +/* Returns true if 'node' has been set to null by hmap_node_nullify() and has + * not been un-nullified by being inserted into an hmap. */ +static inline bool +hmap_node_is_null(const struct hmap_node *node) +{ + return node->next == HMAP_NODE_NULL; +} + +/* Marks 'node' with a distinctive value that can be tested with + * hmap_node_is_null(). */ +static inline void +hmap_node_nullify(struct hmap_node *node) +{ + node->next = HMAP_NODE_NULL; +} + /* A hash map. */ struct hmap { struct hmap_node **buckets;