mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-24 13:24:56 +08:00
Fix up binary search
This commit is contained in:
parent
7b0da28939
commit
c45a6f5c23
@ -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
|
||||
|
||||
for( i=ids[0]; i; i-- ) {
|
||||
if( id > ids[i] ) {
|
||||
break;
|
||||
}
|
||||
|
||||
return i+1;
|
||||
}
|
||||
|
||||
return i+1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user