summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-09-29 15:45:27 -0700
committerAndrew Tridgell <tridge@samba.org>2010-09-29 16:36:22 -0700
commit3b52b6249b94e104077ead134c35402fa1439493 (patch)
tree942208a188801f05cb78e1caac0652b572f58a8f /lib
parent44c891a35acae620566901bb6e038df45f411e02 (diff)
downloadsamba-3b52b6249b94e104077ead134c35402fa1439493.tar.gz
samba-3b52b6249b94e104077ead134c35402fa1439493.tar.bz2
samba-3b52b6249b94e104077ead134c35402fa1439493.zip
util: added BINARY_ARRAY_SEARCH_V()
this is used to search an array of values
Diffstat (limited to 'lib')
-rw-r--r--lib/util/binsearch.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/util/binsearch.h b/lib/util/binsearch.h
index ac83990072..f85d11694e 100644
--- a/lib/util/binsearch.h
+++ b/lib/util/binsearch.h
@@ -65,4 +65,20 @@
if (_r < 0) _e = _i - 1; else _b = _i + 1; \
}} } while (0)
+/*
+ like BINARY_ARRAY_SEARCH_P, but assumes that the array is an array
+ of elements, rather than pointers to structures
+
+ result points to the found structure, or NULL
+ */
+#define BINARY_ARRAY_SEARCH_V(array, array_size, target, comparison_fn, result) do { \
+ int32_t _b, _e; \
+ (result) = NULL; \
+ if (array_size) { for (_b = 0, _e = (array_size)-1; _b <= _e; ) { \
+ int32_t _i = (_b+_e)/2; \
+ int _r = comparison_fn(target, array[_i]); \
+ if (_r == 0) { (result) = &array[_i]; break; } \
+ if (_r < 0) _e = _i - 1; else _b = _i + 1; \
+ }} } while (0)
+
#endif