X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fhmap.c;h=6b850fddcbf6d68206a560a4e3b127ce11a4fc3e;hb=6f20002c1201c1fc78fc7cedb49b103d8afe9da6;hp=1b4816d9ddbeeb60cedb10723cf8c0da4c6d96ee;hpb=f2f7be8696e030dbe6f7c859c4e2bd76fd363036;p=openvswitch diff --git a/lib/hmap.c b/lib/hmap.c index 1b4816d9..6b850fdd 100644 --- a/lib/hmap.c +++ b/lib/hmap.c @@ -18,10 +18,16 @@ #include "hmap.h" #include #include +#include #include "coverage.h" #include "random.h" #include "util.h" +COVERAGE_DEFINE(hmap_pathological); +COVERAGE_DEFINE(hmap_expand); +COVERAGE_DEFINE(hmap_shrink); +COVERAGE_DEFINE(hmap_reserve); + /* Initializes 'hmap' as an empty hash table. */ void hmap_init(struct hmap *hmap) @@ -42,6 +48,22 @@ hmap_destroy(struct hmap *hmap) } } +/* Removes all node from 'hmap', leaving it ready to accept more nodes. Does + * not free memory allocated for 'hmap'. + * + * This function is appropriate when 'hmap' will soon have about as many + * elements as it before. If 'hmap' will likely have fewer elements than + * before, use hmap_destroy() followed by hmap_clear() to save memory and + * iteration time. */ +void +hmap_clear(struct hmap *hmap) +{ + if (hmap->n > 0) { + hmap->n = 0; + memset(hmap->buckets, 0, (hmap->mask + 1) * sizeof *hmap->buckets); + } +} + /* Exchanges hash maps 'a' and 'b'. */ void hmap_swap(struct hmap *a, struct hmap *b)