]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: add hash_to_list()
authorQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 24 May 2018 15:44:54 +0000 (15:44 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Fri, 25 May 2018 16:16:22 +0000 (16:16 +0000)
Convenience function to convert hash table to an unsorted linked list.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/hash.c
lib/hash.h

index 4894b65affedf705d1eb6de797408c8378c5a326..01f160f94addab3fbde429addc1c40c690db82ae 100644 (file)
@@ -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)
index b6fe27e257ece05d05d0b9ba60623a8e7a99ef1d..2510422e219d34c60bc23d1d06d18ffeb7ea48d8 100644 (file)
@@ -106,6 +106,15 @@ extern void hash_walk(struct hash *, int (*)(struct hash_backet *, void *),
 extern void hash_clean(struct hash *, void (*)(void *));
 extern void hash_free(struct hash *);
 
+/*
+ * Converts a hash table to an unsorted linked list.
+ * Does not modify the hash table in any way.
+ *
+ * hash
+ *    the hash to convert
+ */
+extern struct list *hash_to_list(struct hash *hash);
+
 extern unsigned int string_hash_make(const char *);
 
 extern void hash_cmd_init(void);