From f9abe935a96d9da850a03eceacb3ad146ea0d619 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 27 Feb 2009 16:55:54 -0800 Subject: [PATCH] hmap: New function hmap_moved(). --- lib/hmap.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/hmap.h b/lib/hmap.h index 5c6a54b1..9a35c42c 100644 --- a/lib/hmap.h +++ b/lib/hmap.h @@ -78,6 +78,8 @@ static inline void hmap_insert_fast(struct hmap *, struct hmap_node *, size_t hash); static inline void hmap_insert(struct hmap *, struct hmap_node *, size_t hash); static inline void hmap_remove(struct hmap *, struct hmap_node *); +static inline void hmap_moved(struct hmap *, + struct hmap_node *, struct hmap_node *); /* Search. */ #define HMAP_FOR_EACH_WITH_HASH(NODE, STRUCT, MEMBER, HASH, HMAP) \ @@ -165,6 +167,19 @@ hmap_remove(struct hmap *hmap, struct hmap_node *node) hmap->n--; } +/* Adjusts 'hmap' to compensate for 'old_node' having moved position in memory + * to 'node' (e.g. due to realloc()). */ +static inline void +hmap_moved(struct hmap *hmap, + struct hmap_node *old_node, struct hmap_node *node) +{ + struct hmap_node **bucket = &hmap->buckets[node->hash & hmap->mask]; + while (*bucket != old_node) { + bucket = &(*bucket)->next; + } + *bucket = node; +} + static inline struct hmap_node * hmap_next_with_hash__(const struct hmap_node *node, size_t hash) { -- 2.30.2