summaryrefslogtreecommitdiff
path: root/lib/hash.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2018-05-24 15:44:54 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2018-05-25 16:16:22 +0000
commit91f1037064d503f2e5f1756f66c10f3926960836 (patch)
tree0f2a75ac569e7f9127c856b7e34287db65f1188e /lib/hash.c
parent3a5c3bcb17451e3275a29d1f72d91274391a2cd5 (diff)
lib: add hash_to_list()
Convenience function to convert hash table to an unsorted linked list. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/hash.c')
-rw-r--r--lib/hash.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/hash.c b/lib/hash.c
index 4894b65aff..01f160f94a 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -312,6 +312,21 @@ void hash_clean(struct hash *hash, void (*free_func)(void *))
hash->stats.empty = hash->size;
}
+static void hash_to_list_iter(struct hash_backet *hb, void *arg)
+{
+ struct list *list = arg;
+
+ listnode_add(list, hb->data);
+}
+
+struct list *hash_to_list(struct hash *hash)
+{
+ struct list *list = list_new();
+
+ hash_iterate(hash, hash_to_list_iter, list);
+ return list;
+}
+
/* Free hash memory. You may call hash_clean before call this
function. */
void hash_free(struct hash *hash)