[MINOR] tools: add a new get_next_id() function
This function returns the next unused key in a tree. This will be
used to find spare IDs.
diff --git a/src/standard.c b/src/standard.c
index eecc360..6b0be2d 100644
--- a/src/standard.c
+++ b/src/standard.c
@@ -20,6 +20,7 @@
#include <arpa/inet.h>
#include <common/config.h>
+#include <common/eb32tree.h>
#include <common/standard.h>
#include <proto/log.h>
@@ -730,6 +731,23 @@
return ret;
}
+/* This function returns the first unused key greater than or equal to <key> in
+ * ID tree <root>. Zero is returned if no place is found.
+ */
+unsigned int get_next_id(struct eb_root *root, unsigned int key)
+{
+ struct eb32_node *used;
+
+ do {
+ used = eb32_lookup_ge(root, key);
+ if (!used || used->key > key)
+ return key; /* key is available */
+ key++;
+ } while (key);
+ return key;
+}
+
+
/*
* Local variables:
* c-indent-level: 8