diff options
author | erdgeist <> | 2009-08-26 21:12:32 +0000 |
---|---|---|
committer | erdgeist <> | 2009-08-26 21:12:32 +0000 |
commit | c3a58d248b3c7f39979633376b92fd271464f864 (patch) | |
tree | 870048e497164c95a3c794deca906c3e50858048 /ot_vector.c | |
parent | 0c8a17cbef002b60b7e458f110f9d930d17aa73e (diff) |
binary search speedup was buggy.
Diffstat (limited to 'ot_vector.c')
-rw-r--r-- | ot_vector.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/ot_vector.c b/ot_vector.c index 056fafb..66797f1 100644 --- a/ot_vector.c +++ b/ot_vector.c | |||
@@ -27,10 +27,10 @@ static int vector_compare_peer(const void *peer1, const void *peer2 ) { | |||
27 | */ | 27 | */ |
28 | void *binary_search( const void * const key, const void * base, const size_t member_count, const size_t member_size, | 28 | void *binary_search( const void * const key, const void * base, const size_t member_count, const size_t member_size, |
29 | size_t compare_size, int *exactmatch ) { | 29 | size_t compare_size, int *exactmatch ) { |
30 | size_t interval = member_count * member_size; | 30 | size_t interval = member_count; |
31 | 31 | ||
32 | while( interval ) { | 32 | while( interval ) { |
33 | uint8_t *lookat = ((uint8_t*)base) + interval / 2; | 33 | uint8_t *lookat = ((uint8_t*)base) + member_size * ( interval / 2 ); |
34 | int cmp = memcmp( lookat, key, compare_size ); | 34 | int cmp = memcmp( lookat, key, compare_size ); |
35 | if(cmp == 0 ) { | 35 | if(cmp == 0 ) { |
36 | base = lookat; | 36 | base = lookat; |
@@ -38,7 +38,7 @@ void *binary_search( const void * const key, const void * base, const size_t mem | |||
38 | } | 38 | } |
39 | if(cmp < 0) { | 39 | if(cmp < 0) { |
40 | base = lookat + member_size; | 40 | base = lookat + member_size; |
41 | interval -= member_size; | 41 | interval --; |
42 | } | 42 | } |
43 | interval /= 2; | 43 | interval /= 2; |
44 | } | 44 | } |