From: Kurt Zeilenga Date: Wed, 26 Sep 2001 03:50:48 +0000 (+0000) Subject: Fix up binary search X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~1053 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c45a6f5c23c9f0390779b47f379e5ec3fa422868;p=openldap Fix up binary search --- diff --git a/servers/slapd/back-bdb/idl.c b/servers/slapd/back-bdb/idl.c index a2b54c20a2..71666bc862 100644 --- a/servers/slapd/back-bdb/idl.c +++ b/servers/slapd/back-bdb/idl.c @@ -65,11 +65,7 @@ static void idl_dump( ID *ids ) unsigned bdb_idl_search( ID *ids, ID id ) { -#if IDL_DEBUG > 0 - idl_check( ids ); -#endif - -#undef IDL_BINARY_SEARCH +#define IDL_BINARY_SEARCH 1 #ifdef IDL_BINARY_SEARCH /* * binary search of id in ids @@ -81,6 +77,10 @@ unsigned bdb_idl_search( ID *ids, ID id ) int val; unsigned n = ids[0]; +#if IDL_DEBUG > 0 + idl_check( ids ); +#endif + while( 0 < n ) { int pivot = n >> 1; cursor = base + pivot; @@ -106,17 +106,19 @@ unsigned bdb_idl_search( ID *ids, ID id ) #else /* (reverse) linear search */ - { - int i; + int i; - for( i=ids[0]; i; i-- ) { - if( id > ids[i] ) { - break; - } - } +#if IDL_DEBUG > 0 + idl_check( ids ); +#endif - return i+1; + for( i=ids[0]; i; i-- ) { + if( id > ids[i] ) { + break; + } } + + return i+1; #endif }