X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fshash.c;h=caac460e9da9fb185be66194f61f894ce1a5ab67;hb=6c4bf0b0070d474ac6cf97b3fda2e262cd060703;hp=5257de12aad4c4df7acb03809224e1e0bdd70e0c;hpb=7634353824f1631c3008dc43a4a1cc0aebff3caa;p=openvswitch diff --git a/lib/shash.c b/lib/shash.c index 5257de12..caac460e 100644 --- a/lib/shash.c +++ b/lib/shash.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 Nicira Networks. + * Copyright (c) 2009, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +40,18 @@ shash_destroy(struct shash *sh) } } +void +shash_swap(struct shash *a, struct shash *b) +{ + hmap_swap(&a->map, &b->map); +} + +void +shash_moved(struct shash *sh) +{ + hmap_moved(&sh->map); +} + void shash_clear(struct shash *sh) { @@ -87,6 +99,13 @@ shash_add_once(struct shash *sh, const char *name, const void *data) } } +void +shash_add_assert(struct shash *sh, const char *name, const void *data) +{ + bool added OVS_UNUSED = shash_add_once(sh, name, data); + assert(added); +} + void shash_delete(struct shash *sh, struct shash_node *node) { @@ -130,6 +149,14 @@ shash_find_and_delete(struct shash *sh, const char *name) } } +void * +shash_find_and_delete_assert(struct shash *sh, const char *name) +{ + void *data = shash_find_and_delete(sh, name); + assert(data != NULL); + return data; +} + struct shash_node * shash_first(const struct shash *shash) { @@ -168,3 +195,21 @@ shash_sort(const struct shash *sh) return nodes; } } + +/* Returns true if 'a' and 'b' contain the same keys (regardless of their + * values), false otherwise. */ +bool +shash_equal_keys(const struct shash *a, const struct shash *b) +{ + struct shash_node *node; + + if (hmap_count(&a->map) != hmap_count(&b->map)) { + return false; + } + SHASH_FOR_EACH (node, a) { + if (!shash_find(b, node->name)) { + return false; + } + } + return true; +}