summaryrefslogtreecommitdiffhomepage
path: root/stc
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-02-22 18:53:09 +0100
committerTyge Løvset <[email protected]>2021-02-22 18:53:09 +0100
commit2da0a2c2d5fa154ea0151156b4e35a1ac8d50bc4 (patch)
treedb17be6a41db5de83f21ac7d5095aed384f407b7 /stc
parent7475268368b2364c87de171335d1a9254b88316f (diff)
downloadSTC-modified-2da0a2c2d5fa154ea0151156b4e35a1ac8d50bc4.tar.gz
STC-modified-2da0a2c2d5fa154ea0151156b4e35a1ac8d50bc4.zip
Small changes. Added back csmap/cmap put() but now with Key,Mapped args (not RawKey,RawMapped).
Diffstat (limited to 'stc')
-rw-r--r--stc/cmap.h21
-rw-r--r--stc/csmap.h21
2 files changed, 24 insertions, 18 deletions
diff --git a/stc/cmap.h b/stc/cmap.h
index 203f0263..db15eeaa 100644
--- a/stc/cmap.h
+++ b/stc/cmap.h
@@ -261,14 +261,6 @@ typedef struct {size_t idx; uint32_t hx;} chash_bucket_t;
} \
return res; \
} \
- STC_INLINE C##_##X##_result_t \
- C##_##X##_emplace_or_assign(C##_##X* self, RawKey rkey MAP_ONLY_##C(, RawMapped rmapped)) { \
- C##_##X##_result_t res = C##_##X##_insert_entry_(self, rkey); \
- if (res.second) *KEY_REF_##C(res.first) = keyFromRaw(rkey); \
- MAP_ONLY_##C( else mappedDel(&res.first->second); \
- res.first->second = mappedFromRaw(rmapped); ) \
- return res; \
- } \
STC_INLINE void \
C##_##X##_emplace_n(C##_##X* self, const C##_##X##_rawvalue_t arr[], size_t n) { \
for (size_t i=0; i<n; ++i) SET_ONLY_##C( C##_##X##_emplace(self, arr[i]); ) \
@@ -287,9 +279,20 @@ typedef struct {size_t idx; uint32_t hx;} chash_bucket_t;
STC_INLINE C##_##X##_result_t \
C##_##X##_insert_or_assign(C##_##X* self, Key key, Mapped mapped) { \
C##_##X##_result_t res = C##_##X##_insert_entry_(self, keyToRaw(&key)); \
- if (res.second) res.first->first = key; else {keyDel(&key); mappedDel(&res.first->second);} \
+ if (res.second) res.first->first = key; \
+ else {keyDel(&key); mappedDel(&res.first->second);} \
res.first->second = mapped; return res; \
} \
+ STC_INLINE C##_##X##_result_t \
+ C##_##X##_put(C##_##X* self, Key k, Mapped m) \
+ {return C##_##X##_insert_or_assign(self, k, m);} \
+ STC_INLINE C##_##X##_result_t \
+ C##_##X##_emplace_or_assign(C##_##X* self, RawKey rkey, RawMapped rmapped) { \
+ C##_##X##_result_t res = C##_##X##_insert_entry_(self, rkey); \
+ if (res.second) res.first->first = keyFromRaw(rkey); \
+ else mappedDel(&res.first->second); \
+ res.first->second = mappedFromRaw(rmapped); return res; \
+ } \
STC_INLINE C##_##X##_mapped_t* \
C##_##X##_at(const C##_##X* self, RawKey rkey) { \
chash_bucket_t b = C##_##X##_bucket_(self, &rkey); \
diff --git a/stc/csmap.h b/stc/csmap.h
index 7b6b04bd..c261801d 100644
--- a/stc/csmap.h
+++ b/stc/csmap.h
@@ -253,14 +253,6 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; };
} \
return res; \
} \
- STC_INLINE C##_##X##_result_t \
- C##_##X##_emplace_or_assign(C##_##X* self, RawKey rkey MAP_ONLY_##C(, RawMapped rmapped)) { \
- C##_##X##_result_t res = C##_##X##_insert_entry_(self, rkey); \
- if (res.second) *KEY_REF_##C(res.first) = keyFromRaw(rkey); \
- MAP_ONLY_##C( else mappedDel(&res.first->second); \
- res.first->second = mappedFromRaw(rmapped); ) \
- return res; \
- } \
STC_INLINE void \
C##_##X##_emplace_n(C##_##X* self, const C##_##X##_rawvalue_t arr[], size_t n) { \
for (size_t i=0; i<n; ++i) SET_ONLY_##C( C##_##X##_emplace(self, arr[i]); ) \
@@ -279,9 +271,20 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; };
STC_INLINE C##_##X##_result_t \
C##_##X##_insert_or_assign(C##_##X* self, Key key, Mapped mapped) { \
C##_##X##_result_t res = C##_##X##_insert_entry_(self, keyToRaw(&key)); \
- if (res.second) res.first->first = key; else {keyDel(&key); mappedDel(&res.first->second);} \
+ if (res.second) res.first->first = key; \
+ else {keyDel(&key); mappedDel(&res.first->second);} \
res.first->second = mapped; return res; \
} \
+ STC_INLINE C##_##X##_result_t \
+ C##_##X##_put(C##_##X* self, Key k, Mapped m) \
+ {return C##_##X##_insert_or_assign(self, k, m);} \
+ STC_INLINE C##_##X##_result_t \
+ C##_##X##_emplace_or_assign(C##_##X* self, RawKey rkey, RawMapped rmapped) { \
+ C##_##X##_result_t res = C##_##X##_insert_entry_(self, rkey); \
+ if (res.second) res.first->first = keyFromRaw(rkey); \
+ else mappedDel(&res.first->second); \
+ res.first->second = mappedFromRaw(rmapped); return res; \
+ } \
STC_INLINE C##_##X##_mapped_t* \
C##_##X##_at(const C##_##X* self, RawKey rkey) { \
C##_##X##_iter_t it; \