X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fshash.c;h=a5bfecf04a0d53b4b8fdd28a6e718aef4495a040;hb=c6278d208924bb04c41266ddca276712f95533bc;hp=e6cb6b0db8eccfe4cad50c7b7076b9bd1cbc7192;hpb=55213fd581a13f5f6af61db6002ab6e6cc284546;p=openvswitch diff --git a/lib/shash.c b/lib/shash.c index e6cb6b0d..a5bfecf0 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) { @@ -76,6 +88,17 @@ shash_add(struct shash *sh, const char *name, const void *data) return node; } +bool +shash_add_once(struct shash *sh, const char *name, const void *data) +{ + if (!shash_find(sh, name)) { + shash_add(sh, name, data); + return true; + } else { + return false; + } +} + void shash_delete(struct shash *sh, struct shash_node *node) { @@ -157,3 +180,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; +}