]> Dogcows Code - chaz/openbox/blobdiff - obt/bsearch.h
Merge branch 'm4/master'
[chaz/openbox] / obt / bsearch.h
index ca5ae5b27a05158b93a328cbf1473965c2aff217..9613c51b36dda4f86cddabfc19bec7a4033cc9a6 100644 (file)
 
 G_BEGIN_DECLS
 
+/*! Setup to do a binary search on an array holding elements of type @t */
 #define BSEARCH_SETUP(t) \
     register t l_BSEARCH, r_BSEARCH, out_BSEARCH;
 
+/*! Search an array @ar holding elements of type @t, starting at index @start,
+  with @size elements, looking for value @val. */
 #define BSEARCH(t, ar, start, size, val)         \
 { \
     l_BSEARCH = (start);              \
@@ -37,14 +40,18 @@ G_BEGIN_DECLS
         if ((val) == (ar)[out_BSEARCH]) {                           \
             break; \
         } \
-        else if ((val) < (ar)[out_BSEARCH])                       \
+        else if ((val) < (ar)[out_BSEARCH] && out_BSEARCH > 0) {     \
             r_BSEARCH = out_BSEARCH-1; /* search to the left side */ \
+        } \
         else \
             l_BSEARCH = out_BSEARCH+1; /* search to the left side */ \
     } \
 }
 
+/*! Returns true if the element last searched for was found in the array */
 #define BSEARCH_FOUND() (l_BSEARCH <= r_BSEARCH)
+/*! Returns the position in the array at which the element last searched for
+  was found. */
 #define BSEARCH_AT() (out_BSEARCH)
 
 
This page took 0.022417 seconds and 4 git commands to generate.