diff options
| author | Tyge Løvset <[email protected]> | 2021-04-12 15:13:35 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-04-12 15:13:35 +0200 |
| commit | 63806444e21d46e7873654701f5808d6c33a034d (patch) | |
| tree | 131148f38d208b351a1fb4670e7cf7cb0315ab24 | |
| parent | 8dcc8600eb7b4cb11df377a8ae78a24281657873 (diff) | |
| download | STC-modified-63806444e21d46e7873654701f5808d6c33a034d.tar.gz STC-modified-63806444e21d46e7873654701f5808d6c33a034d.zip | |
Fix another issue with local var in csmap_X_erase_at(), and a constness issue in csmap_erase_range(). Reduced iter size.
| -rw-r--r-- | stc/cmap.h | 14 | ||||
| -rw-r--r-- | stc/csmap.h | 14 | ||||
| -rw-r--r-- | stc/csptr.h | 2 |
3 files changed, 15 insertions, 15 deletions
@@ -346,14 +346,14 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) \ \
STC_DEF chash_bucket_t \
CX##_bucket_(const CX* self, const CX##_rawkey_t* rkeyptr) { \
- const uint64_t hash = keyHashRaw(rkeyptr, sizeof(RawKey)); \
+ const uint64_t hash = keyHashRaw(rkeyptr, sizeof *rkeyptr); \
uint_fast8_t sx; size_t cap = self->bucket_count; \
chash_bucket_t b = {_c_SELECT(fastrange,CMAP_SIZE_T)(hash, cap), (uint_fast8_t)(hash | 0x80)}; \
const uint8_t* hashx = self->_hashx; \
while ((sx = hashx[b.idx])) { \
if (sx == b.hx) { \
- RawKey r = keyToRaw(KEY_REF_##C(self->table + b.idx)); \
- if (keyEqualsRaw(&r, rkeyptr)) break; \
+ CX##_rawkey_t raw = keyToRaw(KEY_REF_##C(self->table + b.idx)); \
+ if (keyEqualsRaw(&raw, rkeyptr)) break; \
} \
if (++b.idx == cap) b.idx = 0; \
} \
@@ -415,8 +415,8 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) \ uint8_t* hashx = self->_hashx; \
for (size_t i = 0; i < oldcap; ++i, ++e) \
if (tmp._hashx[i]) { \
- RawKey r = keyToRaw(KEY_REF_##C(e)); \
- chash_bucket_t b = CX##_bucket_(self, &r); \
+ CX##_rawkey_t raw = keyToRaw(KEY_REF_##C(e)); \
+ chash_bucket_t b = CX##_bucket_(self, &raw); \
slot[b.idx] = *e, \
hashx[b.idx] = (uint8_t) b.hx; \
} \
@@ -434,8 +434,8 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) \ if (++j == cap) j = 0; \
if (! hashx[j]) \
break; \
- RawKey r = keyToRaw(KEY_REF_##C(slot + j)); \
- k = _c_SELECT(fastrange,CMAP_SIZE_T)(keyHashRaw(&r, sizeof(RawKey)), cap); \
+ CX##_rawkey_t raw = keyToRaw(KEY_REF_##C(slot + j)); \
+ k = _c_SELECT(fastrange,CMAP_SIZE_T)(keyHashRaw(&raw, sizeof raw), cap); \
if ((j < i) ^ (k <= i) ^ (k > j)) /* is k outside (i, j]? */ \
slot[i] = slot[j], hashx[i] = hashx[j], i = j; \
} \
diff --git a/stc/csmap.h b/stc/csmap.h index 2c0b817a..7e433c1d 100644 --- a/stc/csmap.h +++ b/stc/csmap.h @@ -171,7 +171,7 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; CX##_value_t *ref; \
CX##_node_t *_d; \
int _top; \
- CX##_size_t _tn, _st[48]; \
+ CX##_size_t _tn, _st[40]; \
} CX##_iter_t; \
\
STC_API CX CX##_init(void); \
@@ -359,8 +359,8 @@ static struct csmap_rep _csmap_inits = {0, 0, 0, 0}; CX##_node_t *d = out->_d = self->nodes; \
out->_top = 0; \
while (tn) { \
- int c; RawKey rx = keyToRaw(KEY_REF_##C(&d[tn].value)); \
- if ((c = keyCompareRaw(&rx, &rkey)) < 0) \
+ int c; CX##_rawkey_t raw = keyToRaw(KEY_REF_##C(&d[tn].value)); \
+ if ((c = keyCompareRaw(&raw, &rkey)) < 0) \
tn = d[tn].link[1]; \
else if (c > 0) \
{ out->_st[out->_top++] = tn; tn = d[tn].link[0]; } \
@@ -501,7 +501,7 @@ static struct csmap_rep _csmap_inits = {0, 0, 0, 0}; \
STC_DEF CX##_iter_t \
CX##_erase_at(CX* self, CX##_iter_t it) { \
- RawKey raw = keyToRaw(KEY_REF_##C(it.ref)), nxt; \
+ CX##_rawkey_t raw = keyToRaw(KEY_REF_##C(it.ref)), nxt; \
CX##_next(&it); \
if (it.ref) nxt = keyToRaw(KEY_REF_##C(it.ref)); \
CX##_erase(self, raw); \
@@ -511,14 +511,14 @@ static struct csmap_rep _csmap_inits = {0, 0, 0, 0}; \
STC_DEF CX##_iter_t \
CX##_erase_range(CX* self, CX##_iter_t it1, CX##_iter_t it2) { \
- CX##_rawkey_t *arr = NULL, nxt; size_t sz=0, cap=0; \
+ CX##_rawkey_t nxt, *arr = NULL; size_t sz=0, cap=0; \
for (; it1.ref != it2.ref; CX##_next(&it1), ++sz) { \
- if (sz == cap) arr = (CX##_rawkey_t*) c_realloc(arr, sizeof arr[0]*(cap = (sz + 6)*1.5)); \
+ if (sz == cap) arr = (CX##_rawkey_t*) c_realloc((void *) arr, sizeof arr[0]*(cap = (sz + 6)*1.5)); \
arr[sz] = keyToRaw(KEY_REF_##C(it1.ref)); \
} \
if (it2.ref) nxt = keyToRaw(KEY_REF_##C(it2.ref)); \
for (size_t i=0; i<sz; ++i) CX##_erase(self, arr[i]); \
- c_free(arr); \
+ c_free((void *) arr); \
if (it2.ref) CX##_find_it(self, nxt, &it2); \
return it2; \
} \
diff --git a/stc/csptr.h b/stc/csptr.h index 382ae59c..6c2f1a36 100644 --- a/stc/csptr.h +++ b/stc/csptr.h @@ -90,7 +90,7 @@ typedef long atomic_count_t; using_csptr_3(X, Value, c_default_compare)
#define using_csptr_3(X, Value, valueCompare) \
using_csptr_4(X, Value, valueCompare, c_trivial_del)
-#define using_csptr_4(X, Value, valueCompare, valueDel) \
+#define using_csptr_4(X, Value, valueCompare, valueDel) \
_c_using_csptr(csptr_##X, Value, valueCompare, valueDel)
|
