Browse Source

binary search speedup was buggy.

dynamic-accesslists
erdgeist 15 years ago
parent
commit
c3a58d248b
  1. 6
      ot_vector.c

6
ot_vector.c

@ -27,10 +27,10 @@ static int vector_compare_peer(const void *peer1, const void *peer2 ) {
*/ */
void *binary_search( const void * const key, const void * base, const size_t member_count, const size_t member_size, void *binary_search( const void * const key, const void * base, const size_t member_count, const size_t member_size,
size_t compare_size, int *exactmatch ) { size_t compare_size, int *exactmatch ) {
size_t interval = member_count * member_size; size_t interval = member_count;
while( interval ) { while( interval ) {
uint8_t *lookat = ((uint8_t*)base) + interval / 2; uint8_t *lookat = ((uint8_t*)base) + member_size * ( interval / 2 );
int cmp = memcmp( lookat, key, compare_size ); int cmp = memcmp( lookat, key, compare_size );
if(cmp == 0 ) { if(cmp == 0 ) {
base = lookat; base = lookat;
@ -38,7 +38,7 @@ void *binary_search( const void * const key, const void * base, const size_t mem
} }
if(cmp < 0) { if(cmp < 0) {
base = lookat + member_size; base = lookat + member_size;
interval -= member_size; interval --;
} }
interval /= 2; interval /= 2;
} }

Loading…
Cancel
Save