diff options
| author | Tyge Løvset <[email protected]> | 2022-04-08 17:27:38 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-04-08 17:27:38 +0200 |
| commit | 03065ed6ef93f88003cd6754ca4d50ba20a76ebd (patch) | |
| tree | ccc6535af3da9efce24210ad3d000e79f589ae2d /include/stc/cvec.h | |
| parent | 770764da916b9e3783f2a95b2da62cb930b6702b (diff) | |
| download | STC-modified-03065ed6ef93f88003cd6754ca4d50ba20a76ebd.tar.gz STC-modified-03065ed6ef93f88003cd6754ca4d50ba20a76ebd.zip | |
Fix of previous commit (bug in bsearch).
Diffstat (limited to 'include/stc/cvec.h')
| -rw-r--r-- | include/stc/cvec.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 2b210519..1990b15d 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -218,8 +218,10 @@ _cx_memb(_get_mut)(const _cx_self* self, i_valraw raw) { return (_cx_value*) _cx_memb(_get)(self, raw); }
STC_INLINE _cx_iter
-_cx_memb(_bsearch)(const _cx_self* self, i_valraw raw)
- { return _cx_memb(_bsearch_in)(_cx_memb(_begin)(self), _cx_memb(_end)(self), raw, NULL); }
+_cx_memb(_bsearch)(const _cx_self* self, i_valraw raw) {
+ _cx_iter lower;
+ return _cx_memb(_bsearch_in)(_cx_memb(_begin)(self), _cx_memb(_end)(self), raw, &lower);
+}
STC_INLINE _cx_iter
_cx_memb(_lower_bound)(const _cx_self* self, i_valraw raw) {
@@ -386,11 +388,11 @@ _cx_memb(_bsearch_in)(_cx_iter i1, _cx_iter i2, i_valraw raw, _cx_iter* lower_bo while (i1.ref != i2.ref) {
mid.ref = i1.ref + ((i2.ref - i1.ref) >> 1);
int c; i_valraw m = i_valto(mid.ref);
- if ((c = i_cmp(&raw, &m)) == 0) return mid;
+ if ((c = i_cmp(&raw, &m)) == 0) return *lower_bound = mid;
else if (c < 0) i2.ref = mid.ref;
else i1.ref = mid.ref + 1;
}
- if (lower_bound) *lower_bound = i1;
+ *lower_bound = i1;
return last;
}
|
