From: Ben Pfaff Date: Sat, 28 Feb 2009 00:55:54 +0000 (-0800) Subject: hmap: New function hmap_moved(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9abe935a96d9da850a03eceacb3ad146ea0d619;p=openvswitch hmap: New function hmap_moved(). --- 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) {