To be used in ovs-vsctl in an upcoming commit.
struct hmap tmp = *a;
*a = *b;
*b = tmp;
- if (a->buckets == &b->one) {
- a->buckets = &a->one;
- }
- if (b->buckets == &a->one) {
- b->buckets = &b->one;
+ hmap_moved(a);
+ hmap_moved(b);
+}
+
+/* Adjusts 'hmap' to compensate for having moved position in memory (e.g. due
+ * to realloc()). */
+void
+hmap_moved(struct hmap *hmap)
+{
+ if (!hmap->mask) {
+ hmap->buckets = &hmap->one;
}
}
/* A hash map. */
struct hmap {
- struct hmap_node **buckets;
+ struct hmap_node **buckets; /* Must point to 'one' iff 'mask' == 0. */
struct hmap_node *one;
size_t mask;
size_t n;
void hmap_init(struct hmap *);
void hmap_destroy(struct hmap *);
void hmap_swap(struct hmap *a, struct hmap *b);
+void hmap_moved(struct hmap *);
static inline size_t hmap_count(const struct hmap *);
static inline bool hmap_is_empty(const struct hmap *);
hmap_swap(&a->map, &b->map);
}
+void
+shash_moved(struct shash *sh)
+{
+ hmap_moved(&sh->map);
+}
+
void
shash_clear(struct shash *sh)
{
void shash_init(struct shash *);
void shash_destroy(struct shash *);
void shash_swap(struct shash *, struct shash *);
+void shash_moved(struct shash *);
void shash_clear(struct shash *);
bool shash_is_empty(const struct shash *);
size_t shash_count(const struct shash *);