summaryrefslogtreecommitdiff
path: root/ot_vector.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_vector.c')
-rw-r--r--ot_vector.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/ot_vector.c b/ot_vector.c
index aa71279..1cfa4df 100644
--- a/ot_vector.c
+++ b/ot_vector.c
@@ -16,7 +16,7 @@
16void *binary_search( const void * const key, const void * base, const size_t member_count, const size_t member_size, 16void *binary_search( const void * const key, const void * base, const size_t member_count, const size_t member_size,
17 size_t compare_size, int *exactmatch ) { 17 size_t compare_size, int *exactmatch ) {
18 size_t mc = member_count; 18 size_t mc = member_count;
19 ot_byte *lookat = ((ot_byte*)base) + member_size * (member_count >> 1); 19 uint8_t *lookat = ((uint8_t*)base) + member_size * (member_count >> 1);
20 *exactmatch = 1; 20 *exactmatch = 1;
21 21
22 while( mc ) { 22 while( mc ) {
@@ -27,7 +27,7 @@ void *binary_search( const void * const key, const void * base, const size_t mem
27 --mc; 27 --mc;
28 } 28 }
29 mc >>= 1; 29 mc >>= 1;
30 lookat = ((ot_byte*)base) + member_size * (mc >> 1); 30 lookat = ((uint8_t*)base) + member_size * (mc >> 1);
31 } 31 }
32 *exactmatch = 0; 32 *exactmatch = 0;
33 return (void*)lookat; 33 return (void*)lookat;
@@ -41,22 +41,22 @@ void *binary_search( const void * const key, const void * base, const size_t mem
41 took place. If resizing the vector failed, NULL is returned, else the pointer to the object in vector. 41 took place. If resizing the vector failed, NULL is returned, else the pointer to the object in vector.
42*/ 42*/
43void *vector_find_or_insert( ot_vector *vector, void *key, size_t member_size, size_t compare_size, int *exactmatch ) { 43void *vector_find_or_insert( ot_vector *vector, void *key, size_t member_size, size_t compare_size, int *exactmatch ) {
44 ot_byte *match = binary_search( key, vector->data, vector->size, member_size, compare_size, exactmatch ); 44 uint8_t *match = binary_search( key, vector->data, vector->size, member_size, compare_size, exactmatch );
45 45
46 if( *exactmatch ) return match; 46 if( *exactmatch ) return match;
47 47
48 if( vector->size + 1 >= vector->space ) { 48 if( vector->size + 1 >= vector->space ) {
49 size_t new_space = vector->space ? OT_VECTOR_GROW_RATIO * vector->space : OT_VECTOR_MIN_MEMBERS; 49 size_t new_space = vector->space ? OT_VECTOR_GROW_RATIO * vector->space : OT_VECTOR_MIN_MEMBERS;
50 ot_byte *new_data = realloc( vector->data, new_space * member_size ); 50 uint8_t *new_data = realloc( vector->data, new_space * member_size );
51 if( !new_data ) return NULL; 51 if( !new_data ) return NULL;
52 52
53 /* Adjust pointer if it moved by realloc */ 53 /* Adjust pointer if it moved by realloc */
54 match = new_data + (match - (ot_byte*)vector->data); 54 match = new_data + (match - (uint8_t*)vector->data);
55 55
56 vector->data = new_data; 56 vector->data = new_data;
57 vector->space = new_space; 57 vector->space = new_space;
58 } 58 }
59 memmove( match + member_size, match, ((ot_byte*)vector->data) + member_size * vector->size - match ); 59 memmove( match + member_size, match, ((uint8_t*)vector->data) + member_size * vector->size - match );
60 vector->size++; 60 vector->size++;
61 return match; 61 return match;
62} 62}