X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fhmap.h;fp=lib%2Fhmap.h;h=2f4a302fa4180eaf7f214ff88204abf2299cec59;hb=a4af00400a835eb87569ba40e21874c05e872c0f;hp=abf380be4606c376a9dc6a77c51b6d286799bee4;hpb=93ff0290fda0f02904686989243089faaa9229e6;p=sliver-openvswitch.git diff --git a/lib/hmap.h b/lib/hmap.h index abf380be4..2f4a302fa 100644 --- a/lib/hmap.h +++ b/lib/hmap.h @@ -21,6 +21,10 @@ #include #include "util.h" +#ifdef __cplusplus +extern "C" { +#endif + /* A hash map node, to be embedded inside the data structure being mapped. */ struct hmap_node { size_t hash; /* Hash value. */ @@ -66,7 +70,7 @@ struct hmap { void hmap_init(struct hmap *); void hmap_destroy(struct hmap *); void hmap_swap(struct hmap *a, struct hmap *b); -void hmap_moved(struct hmap *); +void hmap_moved(struct hmap *hmap); static inline size_t hmap_count(const struct hmap *); static inline bool hmap_is_empty(const struct hmap *); @@ -80,6 +84,7 @@ 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 *); + void hmap_node_moved(struct hmap *, struct hmap_node *, struct hmap_node *); static inline void hmap_replace(struct hmap *, const struct hmap_node *old, struct hmap_node *new); @@ -207,24 +212,24 @@ hmap_remove(struct hmap *hmap, struct hmap_node *node) hmap->n--; } -/* Puts 'new' in the position in 'hmap' currently occupied by 'old'. The 'new' - * node must hash to the same value as 'old'. The client is responsible for - * ensuring that the replacement does not violate any client-imposed - * invariants (e.g. uniqueness of keys within a map). +/* Puts 'new_node' in the position in 'hmap' currently occupied by 'old_node'. + * The 'new_node' must hash to the same value as 'old_node'. The client is + * responsible for ensuring that the replacement does not violate any + * client-imposed invariants (e.g. uniqueness of keys within a map). * - * Afterward, 'old' is not part of 'hmap', and the client is responsible for - * freeing it (if this is desirable). */ + * Afterward, 'old_node' is not part of 'hmap', and the client is responsible + * for freeing it (if this is desirable). */ static inline void hmap_replace(struct hmap *hmap, - const struct hmap_node *old, struct hmap_node *new) + const struct hmap_node *old_node, struct hmap_node *new_node) { - struct hmap_node **bucket = &hmap->buckets[old->hash & hmap->mask]; - while (*bucket != old) { + struct hmap_node **bucket = &hmap->buckets[old_node->hash & hmap->mask]; + while (*bucket != old_node) { bucket = &(*bucket)->next; } - *bucket = new; - new->hash = old->hash; - new->next = old->next; + *bucket = new_node; + new_node->hash = old_node->hash; + new_node->next = old_node->next; } static inline struct hmap_node * @@ -316,4 +321,8 @@ hmap_next(const struct hmap *hmap, const struct hmap_node *node) : hmap_next__(hmap, (node->hash & hmap->mask) + 1)); } +#ifdef __cplusplus +} +#endif + #endif /* hmap.h */