mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-05-04 16:57:58 +00:00
[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.
This commit is contained in:
parent
88922354fb
commit
482b00d1b4
@ -27,6 +27,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
|
#include <common/eb32tree.h>
|
||||||
#include <proto/fd.h>
|
#include <proto/fd.h>
|
||||||
|
|
||||||
/****** string-specific macros and functions ******/
|
/****** string-specific macros and functions ******/
|
||||||
@ -331,4 +332,9 @@ static inline unsigned int mul32hi(unsigned int a, unsigned int b)
|
|||||||
/* copies at most <n> characters from <src> and always terminates with '\0' */
|
/* copies at most <n> characters from <src> and always terminates with '\0' */
|
||||||
char *my_strndup(const char *src, int n);
|
char *my_strndup(const char *src, int n);
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
|
||||||
#endif /* _COMMON_STANDARD_H */
|
#endif /* _COMMON_STANDARD_H */
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
|
#include <common/eb32tree.h>
|
||||||
#include <common/standard.h>
|
#include <common/standard.h>
|
||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
|
|
||||||
@ -730,6 +731,23 @@ char *my_strndup(const char *src, int n)
|
|||||||
return ret;
|
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:
|
* Local variables:
|
||||||
* c-indent-level: 8
|
* c-indent-level: 8
|
||||||
|
Loading…
Reference in New Issue
Block a user