diff options
| -rw-r--r-- | include/stc/cmap.h | 27 | ||||
| -rw-r--r-- | include/stc/cvec.h | 6 |
2 files changed, 18 insertions, 15 deletions
diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 58774fb2..b88e2722 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -188,6 +188,15 @@ _cx_memb(_push)(_cx_self* self, _cx_value _val) { return _res; } +STC_INLINE _cx_iter +_cx_memb(_begin)(const _cx_self* self) { + _cx_iter it = {self->table, self->table+self->bucket_count, self->_hashx}; + if (it._hx) + while (*it._hx == 0) + ++it.ref, ++it._hx; + if (it.ref == it.end) it.ref = NULL; + return it; +} STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) @@ -208,9 +217,11 @@ _cx_memb(_advance)(_cx_iter it, size_t n) { STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) { i_size idx; - if (!(self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx])) - return _cx_memb(_end)(self); - return c_make(_cx_iter){self->table+idx, self->table+self->bucket_count, self->_hashx+idx}; + if (self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx]) + return c_make(_cx_iter){self->table + idx, + self->table + self->bucket_count, + self->_hashx + idx}; + return _cx_memb(_end)(self); } STC_INLINE const _cx_value* @@ -225,16 +236,6 @@ STC_INLINE _cx_value* _cx_memb(_get_mut)(_cx_self* self, _cx_rawkey rkey) { return (_cx_value*)_cx_memb(_get)(self, rkey); } -STC_INLINE _cx_iter -_cx_memb(_begin)(const _cx_self* self) { - _cx_iter it = {self->table, self->table+self->bucket_count, self->_hashx}; - if (it._hx) - while (*it._hx == 0) - ++it.ref, ++it._hx; - if (it.ref == it.end) it.ref = NULL; - return it; -} - STC_INLINE size_t _cx_memb(_erase)(_cx_self* self, _cx_rawkey rkey) { if (self->size == 0) diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 6b120ff0..fcf05c10 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -411,7 +411,8 @@ _cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, _cx_raw raw) { if (i_eq((&raw), (&r))) return i1; } - i2.ref = NULL; return i2; // NB! + i2.ref = NULL; // NB! + return i2; } STC_DEF _cx_iter @@ -428,8 +429,9 @@ _cx_memb(_binary_search_in)(_cx_iter i1, _cx_iter i2, const _cx_raw raw, else if (c < 0) p2 = mid.ref; else i1.ref = mid.ref + 1; } + i2.ref = NULL; // NB! *lower_bound = i1.ref == i2.end ? i2 : i1; - i2.ref = NULL; return i2; // NB! + return i2; } STC_DEF int |
