From 2da0a2c2d5fa154ea0151156b4e35a1ac8d50bc4 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Mon, 22 Feb 2021 18:53:09 +0100 Subject: Small changes. Added back csmap/cmap put() but now with Key,Mapped args (not RawKey,RawMapped). --- stc/cmap.h | 21 ++++++++++++--------- stc/csmap.h | 21 ++++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'stc') 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; ifirst = 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; ifirst = 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; \ -- cgit v1.2.3