summaryrefslogtreecommitdiffstats
path: root/zix
diff options
context:
space:
mode:
Diffstat (limited to 'zix')
-rw-r--r--zix/btree.c57
-rw-r--r--zix/ring.c12
-rw-r--r--zix/sorted_array.c4
-rw-r--r--zix/strindex.c22
-rw-r--r--zix/tree.c4
5 files changed, 61 insertions, 38 deletions
diff --git a/zix/btree.c b/zix/btree.c
index ba2ad0d..d8bca23 100644
--- a/zix/btree.c
+++ b/zix/btree.c
@@ -373,7 +373,9 @@ zix_btree_insert(ZixBTree* const t, void* const e)
const int cmp = t->cmp(parent->data.inode.vals[i], e, t->cmp_data);
if (cmp == 0) {
return ZIX_STATUS_EXISTS;
- } else if (cmp < 0) {
+ }
+
+ if (cmp < 0) {
// Move to new RHS
n = rhs;
++i;
@@ -386,7 +388,9 @@ zix_btree_insert(ZixBTree* const t, void* const e)
i = zix_btree_node_find(t, n, e, &equal);
if (equal) {
return ZIX_STATUS_EXISTS;
- } else if (!n->is_leaf) {
+ }
+
+ if (!n->is_leaf) {
// Descend to child node left of value
parent = n;
n = zix_btree_child(n, i);
@@ -640,15 +644,18 @@ zix_btree_remove(ZixBTree* const t,
}
--t->size;
return ZIX_STATUS_SUCCESS;
- } else {
- // Not found in leaf node, or tree
- if (ti && !user_iter) {
- zix_btree_iter_free(ti);
- *next = NULL;
- }
- return ZIX_STATUS_NOT_FOUND;
}
- } else if (equal) {
+
+ // Not found in leaf node, or tree
+ if (ti && !user_iter) {
+ zix_btree_iter_free(ti);
+ *next = NULL;
+ }
+
+ return ZIX_STATUS_NOT_FOUND;
+ }
+
+ if (equal) {
// Found in internal node
ZixBTreeNode* const lhs = zix_btree_child(n, i);
ZixBTreeNode* const rhs = zix_btree_child(n, i + 1);
@@ -738,12 +745,14 @@ zix_btree_find(const ZixBTree* const t,
if (equal) {
return ZIX_STATUS_SUCCESS;
- } else if (n->is_leaf) {
+ }
+
+ if (n->is_leaf) {
break;
- } else {
- ++(*ti)->level;
- n = zix_btree_child(n, i);
}
+
+ ++(*ti)->level;
+ n = zix_btree_child(n, i);
}
zix_btree_iter_free(*ti);
@@ -759,7 +768,9 @@ zix_btree_lower_bound(const ZixBTree* const t,
if (!t) {
*ti = NULL;
return ZIX_STATUS_BAD_ARG;
- } else if (!t->root) {
+ }
+
+ if (!t->root) {
*ti = NULL;
return ZIX_STATUS_SUCCESS;
}
@@ -784,11 +795,11 @@ zix_btree_lower_bound(const ZixBTree* const t,
if (n->is_leaf) {
break;
- } else {
- ++(*ti)->level;
- n = zix_btree_child(n, i);
- assert(n);
}
+
+ ++(*ti)->level;
+ n = zix_btree_child(n, i);
+ assert(n);
}
const ZixBTreeIterFrame* const frame = &(*ti)->stack[(*ti)->level];
@@ -822,7 +833,9 @@ zix_btree_begin(const ZixBTree* const t)
ZixBTreeIter* const i = zix_btree_iter_new(t);
if (!i) {
return NULL;
- } else if (t->size == 0) {
+ }
+
+ if (t->size == 0) {
i->level = 0;
i->stack[0].node = NULL;
} else {
@@ -871,7 +884,9 @@ zix_btree_iter_equals(const ZixBTreeIter* const lhs, const ZixBTreeIter* const r
{
if (zix_btree_iter_is_end(lhs) && zix_btree_iter_is_end(rhs)) {
return true;
- } else if (zix_btree_iter_is_end(lhs) || zix_btree_iter_is_end(rhs) ||
+ }
+
+ if (zix_btree_iter_is_end(lhs) || zix_btree_iter_is_end(rhs) ||
lhs->level != rhs->level) {
return false;
}
diff --git a/zix/ring.c b/zix/ring.c
index cdbcea8..35ebd63 100644
--- a/zix/ring.c
+++ b/zix/ring.c
@@ -103,9 +103,9 @@ read_space_internal(const ZixRing* ring, uint32_t r, uint32_t w)
{
if (r < w) {
return w - r;
- } else {
- return (w - r + ring->size) & ring->size_mask;
}
+
+ return (w - r + ring->size) & ring->size_mask;
}
uint32_t
@@ -119,11 +119,13 @@ write_space_internal(const ZixRing* ring, uint32_t r, uint32_t w)
{
if (r == w) {
return ring->size - 1;
- } else if (r < w) {
+ }
+
+ if (r < w) {
return ((r - w + ring->size) & ring->size_mask) - 1;
- } else {
- return (r - w) - 1;
}
+
+ return (r - w) - 1;
}
uint32_t
diff --git a/zix/sorted_array.c b/zix/sorted_array.c
index ffab77c..c96ea2b 100644
--- a/zix/sorted_array.c
+++ b/zix/sorted_array.c
@@ -151,7 +151,9 @@ zix_sorted_array_find(const ZixSortedArray* a,
if (cmp == 0) {
*ai = elem_i;
return ZIX_STATUS_SUCCESS;
- } else if (cmp > 0) {
+ }
+
+ if (cmp > 0) {
upper = i - 1;
} else {
lower = i + 1;
diff --git a/zix/strindex.c b/zix/strindex.c
index cbc218d..2fdd04f 100644
--- a/zix/strindex.c
+++ b/zix/strindex.c
@@ -234,18 +234,20 @@ zix_strindex_find(ZixStrindex* strindex, const char* const str, char** match)
*match = n->children[child_i].first;
assert(!strncmp(*match, orig_p, strlen(orig_p)));
return ZIX_STATUS_SUCCESS;
- } else if (strindex_is_leaf(n)) {
+ }
+
+ if (strindex_is_leaf(n)) {
/* Hit leaf early, no match */
return ZIX_STATUS_NOT_FOUND;
- } else {
- /* Match at this node, continue search downwards (or match) */
- p += label_len;
- n = &n->children[child_i];
- if (label_len >= p_len) {
- assert(strstr(strindex->s, orig_p) != NULL);
- assert(strncmp(orig_p, *match, max_len));
- return ZIX_STATUS_SUCCESS;
- }
+ }
+
+ /* Match at this node, continue search downwards (or match) */
+ p += label_len;
+ n = &n->children[child_i];
+ if (label_len >= p_len) {
+ assert(strstr(strindex->s, orig_p) != NULL);
+ assert(strncmp(orig_p, *match, max_len));
+ return ZIX_STATUS_SUCCESS;
}
} else {
diff --git a/zix/tree.c b/zix/tree.c
index baeb6a3..21a5806 100644
--- a/zix/tree.c
+++ b/zix/tree.c
@@ -598,7 +598,9 @@ zix_tree_find(const ZixTree* t, const void* e, ZixTreeIter** ti)
const int cmp = t->cmp(e, n->data, t->cmp_data);
if (cmp == 0) {
break;
- } else if (cmp < 0) {
+ }
+
+ if (cmp < 0) {
n = n->left;
} else {
n = n->right;