diff options
| author | Tyge Løvset <[email protected]> | 2021-02-19 18:44:19 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-02-19 18:44:19 +0100 |
| commit | ac14ed84b111762544bb850e869c5e98cfe89092 (patch) | |
| tree | fac34d7e879a373332f009e7694b21fca90a035a | |
| parent | cfd14e93d275e5b4daa95321058ef5a13e1e4ff4 (diff) | |
| download | STC-modified-ac14ed84b111762544bb850e869c5e98cfe89092.tar.gz STC-modified-ac14ed84b111762544bb850e869c5e98cfe89092.zip | |
Fixed bug in insert_or_assign(). cmap/csmap.
| -rw-r--r-- | stc/cmap.h | 5 | ||||
| -rw-r--r-- | stc/cptr.h | 26 | ||||
| -rw-r--r-- | stc/csmap.h | 5 |
3 files changed, 19 insertions, 17 deletions
@@ -262,9 +262,8 @@ 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); res.first->second = mapped; \
- return res; \
+ if (res.second) res.first->first = key; else {keyDel(&key); mappedDel(&res.first->second);} \
+ res.first->second = mapped; return res; \
} \
STC_INLINE C##_##X##_mapped_t* \
C##_##X##_at(const C##_##X* self, RawKey rkey) { \
@@ -44,8 +44,8 @@ int Person_compare(const Person* p, const Person* q) { return cmp == 0 ? strcmp(p->last.str, q->last.str) : cmp;
}
-using_cptr(pe, Person, Person_compare, Person_del, c_no_clone);
-using_cvec(pe, Person*, cptr_pe_compare, cptr_pe_del, c_no_clone);
+using_cptr(pe, Person, Person_compare, Person_del);
+using_cvec(pe, Person*, cptr_pe_compare, cptr_pe_del);
int main() {
cvec_pe vec = cvec_pe_init();
@@ -65,9 +65,9 @@ int main() { using_cptr_3(X, Value, c_default_compare)
#define using_cptr_3(X, Value, valueCompare) \
- using_cptr_5(X, Value, valueCompare, c_default_del, c_default_clone)
+ using_cptr_4(X, Value, valueCompare, c_default_del)
-#define using_cptr_5(X, Value, valueCompare, valueDestroy, valueClone) \
+#define using_cptr_4(X, Value, valueCompare, valueDestroy) \
typedef Value cptr_##X##_value_t; \
typedef cptr_##X##_value_t *cptr_##X; \
\
@@ -77,11 +77,7 @@ int main() { c_free(*self); \
} \
STC_INLINE cptr_##X \
- cptr_##X##_clone(cptr_##X ptr) { \
- cptr_##X clone = c_new_1(Value); \
- *clone = valueClone(*ptr); \
- return clone; \
- } \
+ cptr_##X##_clone(cptr_##X ptr) { return ptr; } \
\
STC_INLINE void \
cptr_##X##_reset(cptr_##X* self, cptr_##X##_value_t* p) { \
@@ -93,12 +89,16 @@ int main() { cptr_##X##_compare(cptr_##X* x, cptr_##X* y) { \
return valueCompare(*x, *y); \
} \
+ STC_INLINE int \
+ cptr_##X##_equals(cptr_##X* x, cptr_##X* y) { \
+ return valueCompare(*x, *y) == 0; \
+ } \
typedef cptr_##X cptr_##X##_t
-/* csptr: std::shared_ptr -like type: */
-/*
+/* csptr: std::shared_ptr -like type:
+
#include <stc/cptr.h>
#include <stc/cstr.h>
@@ -201,6 +201,10 @@ typedef long atomic_count_t; csptr_##X##_compare(csptr_##X* x, csptr_##X* y) { \
return valueCompare(x->get, y->get); \
} \
+ STC_INLINE int \
+ csptr_##X##_equals(csptr_##X* x, csptr_##X* y) { \
+ return valueCompare(x->get, y->get) == 0; \
+ } \
typedef csptr_##X csptr_##X##_t
#endif
diff --git a/stc/csmap.h b/stc/csmap.h index 751b9845..53da6653 100644 --- a/stc/csmap.h +++ b/stc/csmap.h @@ -259,9 +259,8 @@ 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); res.first->second = mapped; \
- return res; \
+ if (res.second) res.first->first = key; else {keyDel(&key); mappedDel(&res.first->second);} \
+ res.first->second = mapped; return res; \
} \
STC_INLINE C##_##X##_mapped_t* \
C##_##X##_at(const C##_##X* self, RawKey rkey) { \
|
