diff options
| author | Tyge Løvset <[email protected]> | 2021-01-18 12:25:46 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-01-18 12:25:46 +0100 |
| commit | 595fc0f3ba75fa2ce7899376e7281f2c46b19865 (patch) | |
| tree | 854eeda5e17ee813bb6e708e28738f19f17966f1 | |
| parent | 080939b4e36fa06a3b22d4d11911bd651404ddaa (diff) | |
| download | STC-modified-595fc0f3ba75fa2ce7899376e7281f2c46b19865.tar.gz STC-modified-595fc0f3ba75fa2ce7899376e7281f2c46b19865.zip | |
Moved c_try_emplace to ccommon.h
| -rw-r--r-- | stc/ccommon.h | 5 | ||||
| -rw-r--r-- | stc/cmap.h | 17 |
2 files changed, 11 insertions, 11 deletions
diff --git a/stc/ccommon.h b/stc/ccommon.h index 0de4fb1e..d9689875 100644 --- a/stc/ccommon.h +++ b/stc/ccommon.h @@ -134,5 +134,10 @@ for (size_t __i=0; __i<sizeof __arr/sizeof *__arr; ++__i) \
ctype##_del(__arr[__i]); \
} while (0)
+/* For cmap_X and csmap_X only: */
+#define c_try_emplace(self, ctype, rkey, mapped) do { \
+ ctype##_result_t __r = ctype##_insert_key(self, rkey); \
+ if (__r.second) __r.first->second = mapped; \
+} while (0)
#endif
@@ -58,11 +58,6 @@ int main(void) { #define cmap_inits {NULL, NULL, 0, 0, 0.15f, 0.85f}
#define cset_inits cmap_inits
-#define c_try_emplace(self, C, key, val) do { \
- C##_result_t __r = C##_insert_key_(self, key); \
- if (__r.second) __r.first->second = val; \
-} while (0)
-
/* https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction */
#define chash_reduce(x, N) ((uint32_t) (((uint64_t) (x) * (N)) >> 32))
#define chash_entry_index(h, entryPtr) ((entryPtr) - (h).table)
@@ -235,26 +230,26 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; C##_##X##_contains(const C##_##X* self, RawKey rkey); \
\
STC_API C##_##X##_result_t \
- C##_##X##_insert_key_(C##_##X* self, RawKey rkey); \
+ C##_##X##_insert_key(C##_##X* self, RawKey rkey); \
STC_API C##_bucket_t \
C##_##X##_bucket(const C##_##X* self, const C##_##X##_rawkey_t* rkeyptr); \
\
STC_INLINE C##_##X##_result_t \
C##_##X##_emplace(C##_##X* self, RawKey rkey MAP_ONLY_##C(, RawMapped rmapped)) { \
- C##_##X##_result_t res = C##_##X##_insert_key_(self, rkey); \
+ C##_##X##_result_t res = C##_##X##_insert_key(self, rkey); \
MAP_ONLY_##C( if (res.second) res.first->second = mappedFromRaw(rmapped); ) \
return res; \
} \
STC_INLINE C##_##X##_result_t \
C##_##X##_insert(C##_##X* self, C##_##X##_rawvalue_t raw) { \
- return SET_ONLY_##C(C##_##X##_insert_key_(self, raw)) \
+ return SET_ONLY_##C(C##_##X##_insert_key(self, raw)) \
MAP_ONLY_##C(C##_##X##_emplace(self, raw.first, raw.second)); \
} \
\
MAP_ONLY_##C( \
STC_INLINE C##_##X##_result_t \
C##_##X##_put(C##_##X* self, RawKey rkey, RawMapped rmapped) { \
- C##_##X##_result_t res = C##_##X##_insert_key_(self, rkey); \
+ C##_##X##_result_t res = C##_##X##_insert_key(self, rkey); \
if (!res.second) mappedDel(&res.first->second); \
res.first->second = mappedFromRaw(rmapped); return res; \
} \
@@ -264,7 +259,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; } \
STC_INLINE C##_##X##_result_t \
C##_##X##_put_mapped(C##_##X* self, RawKey rkey, Mapped mapped) { \
- C##_##X##_result_t res = C##_##X##_insert_key_(self, rkey); \
+ C##_##X##_result_t res = C##_##X##_insert_key(self, rkey); \
if (!res.second) mappedDel(&res.first->second); \
res.first->second = mapped; return res; \
} \
@@ -383,7 +378,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; C##_##X##_reserve(self, 5 + self->size * 3 / 2); \
} \
STC_DEF C##_##X##_result_t \
- C##_##X##_insert_key_(C##_##X* self, RawKey rkey) { \
+ C##_##X##_insert_key(C##_##X* self, RawKey rkey) { \
C##_##X##_reserve_expand_(self); \
C##_bucket_t b = C##_##X##_bucket(self, &rkey); \
C##_##X##_result_t res = {&self->table[b.idx], !self->_hashx[b.idx]}; \
|
