summaryrefslogtreecommitdiff
path: root/ot_vector.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-26 16:59:39 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-26 16:59:39 +0100
commit6871825565d0ba24436dbd5b92cc09e02f93af6a (patch)
tree0fbd4f05de5997d74bbc4f65d55a611e650ee83f /ot_vector.c
parent5e86efde052760a53ca92ddd411db095fcf4a970 (diff)
First run of making variable names more readable
Diffstat (limited to 'ot_vector.c')
-rw-r--r--ot_vector.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/ot_vector.c b/ot_vector.c
index 7f18246..924d468 100644
--- a/ot_vector.c
+++ b/ot_vector.c
@@ -19,7 +19,7 @@ static int vector_compare_peer4(const void *peer1, const void *peer2) { return m
19 no exact match is found. In that case it sets exactmatch 0 and gives 19 no exact match is found. In that case it sets exactmatch 0 and gives
20 calling functions the chance to insert data 20 calling functions the chance to insert data
21*/ 21*/
22void *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) { 22void *vector_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) {
23 size_t interval = member_count; 23 size_t interval = member_count;
24 24
25 while (interval) { 25 while (interval) {
@@ -50,13 +50,13 @@ static uint8_t vector_hash_peer(ot_peer const *peer, size_t compare_size, size_t
50 50
51/* This is the generic insert operation for our vector type. 51/* This is the generic insert operation for our vector type.
52 It tries to locate the object at "key" with size "member_size" by comparing its first "compare_size" bytes with 52 It tries to locate the object at "key" with size "member_size" by comparing its first "compare_size" bytes with
53 those of objects in vector. Our special "binary_search" function does that and either returns the match or a 53 those of objects in vector. Our special "vector_binary_search" function does that and either returns the match or a
54 pointer to where the object is to be inserted. vector_find_or_insert makes space for the object and copies it, 54 pointer to where the object is to be inserted. vector_find_or_insert makes space for the object and copies it,
55 if it wasn't found in vector. Caller needs to check the passed "exactmatch" variable to see, whether an insert 55 if it wasn't found in vector. Caller needs to check the passed "exactmatch" variable to see, whether an insert
56 took place. If resizing the vector failed, NULL is returned, else the pointer to the object in vector. 56 took place. If resizing the vector failed, NULL is returned, else the pointer to the object in vector.
57*/ 57*/
58void *vector_find_or_insert(ot_vector *vector, void *key, size_t member_size, size_t compare_size, int *exactmatch) { 58void *vector_find_or_insert(ot_vector *vector, void *key, size_t member_size, size_t compare_size, int *exactmatch) {
59 uint8_t *match = binary_search(key, vector->data, vector->size, member_size, compare_size, exactmatch); 59 uint8_t *match = vector_binary_search(key, vector->data, vector->size, member_size, compare_size, exactmatch);
60 60
61 if (*exactmatch) 61 if (*exactmatch)
62 return match; 62 return match;
@@ -89,7 +89,7 @@ ot_peer *vector_find_or_insert_peer(ot_vector *vector, ot_peer const *peer, size
89 /* If space is zero but size is set, we're dealing with a list of vector->size buckets */ 89 /* If space is zero but size is set, we're dealing with a list of vector->size buckets */
90 if (vector->space < vector->size) 90 if (vector->space < vector->size)
91 vector = ((ot_vector *)vector->data) + vector_hash_peer(peer, compare_size, vector->size); 91 vector = ((ot_vector *)vector->data) + vector_hash_peer(peer, compare_size, vector->size);
92 match = binary_search(peer, vector->data, vector->size, peer_size, compare_size, exactmatch); 92 match = vector_binary_search(peer, vector->data, vector->size, peer_size, compare_size, exactmatch);
93 93
94 if (*exactmatch) 94 if (*exactmatch)
95 return match; 95 return match;
@@ -137,7 +137,7 @@ int vector_remove_peer(ot_vector *vector, ot_peer const *peer, size_t peer_size)
137 vector = ((ot_vector *)vector->data) + vector_hash_peer(peer, compare_size, vector->size); 137 vector = ((ot_vector *)vector->data) + vector_hash_peer(peer, compare_size, vector->size);
138 138
139 end = ((ot_peer *)vector->data) + peer_size * vector->size; 139 end = ((ot_peer *)vector->data) + peer_size * vector->size;
140 match = (ot_peer *)binary_search(peer, vector->data, vector->size, peer_size, compare_size, &exactmatch); 140 match = (ot_peer *)vector_binary_search(peer, vector->data, vector->size, peer_size, compare_size, &exactmatch);
141 if (!exactmatch) 141 if (!exactmatch)
142 return 0; 142 return 0;
143 143