summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-01-27 16:10:45 +0100
committerTyge Løvset <[email protected]>2023-01-27 16:10:45 +0100
commite1c95c261e973b97620ec15b3dfb3cb25f6df916 (patch)
treefa694140cbb74717d7c66be8349b6be64d4392cb /include
parent8c81c9642b5f7564f06654562d929703f2d2dd0a (diff)
downloadSTC-modified-e1c95c261e973b97620ec15b3dfb3cb25f6df916.tar.gz
STC-modified-e1c95c261e973b97620ec15b3dfb3cb25f6df916.zip
Removed branch in cvec_lower_bound().
Diffstat (limited to 'include')
-rw-r--r--include/stc/cvec.h15
1 files changed, 7 insertions, 8 deletions
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index 0905526a..2ff2c58a 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -398,20 +398,19 @@ _cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, _cx_raw raw) {
STC_DEF _cx_iter
_cx_memb(_binary_search_in)(_cx_iter i1, _cx_iter i2, const _cx_raw raw,
_cx_iter* lower_bound) {
- const _cx_value* p2 = _it2_ptr(i1, i2);
+ _cx_value* w[2] = {i1.ref, _it2_ptr(i1, i2)};
_cx_iter mid = i1;
- while (i1.ref != p2) {
- mid.ref = i1.ref + (p2 - i1.ref)/2;
+ while (w[0] != w[1]) {
+ mid.ref = w[0] + (w[1] - w[0])/2;
const _cx_raw m = i_keyto(mid.ref);
const int c = i_cmp((&raw), (&m));
if (!c) return *lower_bound = mid;
- else if (c < 0) p2 = mid.ref;
- else i1.ref = mid.ref + 1;
+ w[c < 0] = mid.ref + (c > 0);
}
- i2.ref = NULL;
- *lower_bound = i1.ref == i2.end ? i2 : i1;
- return i2;
+ i1.ref = w[0] == i2.end ? NULL : w[0];
+ *lower_bound = i1;
+ i1.ref = NULL; return i1;
}
STC_DEF int