summaryrefslogtreecommitdiff
path: root/source4/lib/idtree.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-05-10 01:55:18 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:16:34 -0500
commit61d95606d06b7ee9541b2097c693afd042459f31 (patch)
treede384a10c2c6904179c734283543dcf6e6a6bc24 /source4/lib/idtree.c
parent00f4b34d95da1152f2cd12bd3bf38dc08f2af187 (diff)
downloadsamba-61d95606d06b7ee9541b2097c693afd042459f31.tar.gz
samba-61d95606d06b7ee9541b2097c693afd042459f31.tar.bz2
samba-61d95606d06b7ee9541b2097c693afd042459f31.zip
r6687: added a idr helper function for creating random IDs
(This used to be commit ef573df2a012e9a192487f207502ef1027c66d4b)
Diffstat (limited to 'source4/lib/idtree.c')
-rw-r--r--source4/lib/idtree.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/source4/lib/idtree.c b/source4/lib/idtree.c
index 82c1cdd42a..a67a80940a 100644
--- a/source4/lib/idtree.c
+++ b/source4/lib/idtree.c
@@ -345,6 +345,24 @@ int idr_get_new_above(struct idr_context *idp, void *ptr, int starting_id, int l
}
/*
+ allocate a new id randomly in the given range
+*/
+int idr_get_new_random(struct idr_context *idp, void *ptr, int limit)
+{
+ int id;
+
+ /* first try a random starting point in the whole range, and if that fails,
+ then start randomly in the bottom half of the range. This can only
+ fail if the range is over half full */
+ id = idr_get_new_above(idp, ptr, 1+(generate_random() % limit), limit);
+ if (id == -1) {
+ id = idr_get_new_above(idp, ptr, 1+(generate_random()%(limit/2)), limit);
+ }
+
+ return id;
+}
+
+/*
find a pointer value previously set with idr_get_new given an id
*/
void *idr_find(struct idr_context *idp, int id)