From 92b950333c6c7002bdbf1b60af44a249dc0cef9c Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sun, 19 Dec 2021 12:21:44 +0100 Subject: First commit for Version 3 of STC. Main changes are consistent rename of '_del' to '_drop' and '_compare' to '_cmp'. Also i_key_ref (earlier i_key_sptr) and i_val_ref replaced by more general i_key_bind/i_val_bind. --- benchmarks/plotbench/cmap_benchmark.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'benchmarks/plotbench/cmap_benchmark.cpp') diff --git a/benchmarks/plotbench/cmap_benchmark.cpp b/benchmarks/plotbench/cmap_benchmark.cpp index 4c9c6c16..16aec8c0 100644 --- a/benchmarks/plotbench/cmap_benchmark.cpp +++ b/benchmarks/plotbench/cmap_benchmark.cpp @@ -82,7 +82,7 @@ Sample test_stc_unordered_map() { c_forrange (N) cmap_x_erase(&con, stc64_random() & mask1); s.test[ERASE].t2 = clock(); s.test[ERASE].sum = cmap_x_size(con); - cmap_x_del(&con); + cmap_x_drop(&con); }{ container con = cmap_x_init(); stc64_srandom(seed); @@ -103,7 +103,7 @@ Sample test_stc_unordered_map() { s.test[ITER].t2 = clock(); s.test[ITER].sum = sum; s.test[DESTRUCT].t1 = clock(); - cmap_x_del(&con); + cmap_x_drop(&con); } s.test[DESTRUCT].t2 = clock(); s.test[DESTRUCT].sum = 0; -- cgit v1.2.3 From de411007bceda17457fb27ea72b4433adf744797 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 23 Dec 2021 13:21:21 +0100 Subject: Removed emplace functions if not i_valraw or i_keyraw is defined. Safety/optimize measure. --- benchmarks/picobench/picobench_cmap.cpp | 12 ++++++------ benchmarks/picobench/picobench_csmap.cpp | 12 ++++++------ benchmarks/plotbench/cmap_benchmark.cpp | 8 ++++---- benchmarks/plotbench/csmap_benchmark.cpp | 8 ++++---- examples/birthday.c | 4 ++-- examples/box2.c | 4 ++-- examples/csmap_find.c | 14 +++++++------- examples/demos.c | 4 ++-- examples/ex_gauss1.c | 2 +- examples/new_sptr.c | 4 ++-- include/stc/carc.h | 2 +- include/stc/cbox.h | 4 ++-- include/stc/cdeq.h | 12 ++++++++---- include/stc/clist.h | 17 +++++++++-------- include/stc/cmap.h | 7 ++++--- include/stc/cpque.h | 8 ++++---- include/stc/csmap.h | 7 ++++--- include/stc/cstack.h | 4 ++-- include/stc/cvec.h | 17 ++++++++++------- include/stc/template.h | 10 ++++++---- 20 files changed, 86 insertions(+), 74 deletions(-) (limited to 'benchmarks/plotbench/cmap_benchmark.cpp') diff --git a/benchmarks/picobench/picobench_cmap.cpp b/benchmarks/picobench/picobench_cmap.cpp index a045cb7c..f54b3d32 100644 --- a/benchmarks/picobench/picobench_cmap.cpp +++ b/benchmarks/picobench/picobench_cmap.cpp @@ -82,11 +82,11 @@ static void ins_and_erase_cmap_i(picobench::state& s) picobench::scope scope(s); c_forrange (s.iterations()) - cmap_i_emplace(&map, stc64_random(), 0); + cmap_i_insert(&map, stc64_random(), 0); cmap_i_clear(&map); stc64_srandom(seed); c_forrange (s.iterations()) - cmap_i_emplace(&map, stc64_random(), 0); + cmap_i_insert(&map, stc64_random(), 0); stc64_srandom(seed); c_forrange (s.iterations()) cmap_i_erase(&map, stc64_random()); @@ -102,11 +102,11 @@ static void ins_and_erase_cmap_x(picobench::state& s) picobench::scope scope(s); c_forrange (s.iterations()) - cmap_x_emplace(&map, stc64_random(), 0); + cmap_x_insert(&map, stc64_random(), 0); cmap_x_clear(&map); stc64_srandom(seed); c_forrange (s.iterations()) - cmap_x_emplace(&map, stc64_random(), 0); + cmap_x_insert(&map, stc64_random(), 0); stc64_srandom(seed); c_forrange (s.iterations()) cmap_x_erase(&map, stc64_random()); @@ -151,7 +151,7 @@ static void ins_and_access_cmap_i(picobench::state& s) picobench::scope scope(s); c_forrange (N1) - result += ++cmap_i_emplace(&map, stc64_random() & mask, 0).ref->second; + result += ++cmap_i_insert(&map, stc64_random() & mask, 0).ref->second; s.set_result(result); cmap_i_drop(&map); } @@ -270,7 +270,7 @@ static void iterate_cmap_x(picobench::state& s) // measure insert then iterate whole map c_forrange (n, s.iterations()) { - cmap_x_emplace_or_assign(&map, stc64_random(), n); + cmap_x_insert_or_assign(&map, stc64_random(), n); if (!(n & K)) c_foreach (i, cmap_x, map) result += i.ref->second; } diff --git a/benchmarks/picobench/picobench_csmap.cpp b/benchmarks/picobench/picobench_csmap.cpp index 90681cd5..71d54832 100644 --- a/benchmarks/picobench/picobench_csmap.cpp +++ b/benchmarks/picobench/picobench_csmap.cpp @@ -50,7 +50,7 @@ static void ctor_and_ins_one_csmap_i(picobench::state& s) picobench::scope scope(s); c_forrange (n, s.iterations()) { csmap_i map = csmap_i_init(); - csmap_i_emplace(&map, n, 0); + csmap_i_insert(&map, n, 0); result += csmap_i_size(map); csmap_i_drop(&map); } @@ -84,7 +84,7 @@ static void insert_csmap_i(picobench::state& s) stc64_srandom(seed); picobench::scope scope(s); c_forrange (n, s.iterations()) - csmap_i_emplace(&map, stc64_random() & 0xfffffff, n); + csmap_i_insert(&map, stc64_random() & 0xfffffff, n); s.set_result(csmap_i_size(map)); csmap_i_drop(&map); } @@ -130,13 +130,13 @@ static void ins_and_erase_csmap_i(picobench::state& s) picobench::scope scope(s); c_forrange (i, s.iterations()) - csmap_i_emplace(&map, stc64_random() & mask, i); + csmap_i_insert(&map, stc64_random() & mask, i); result = csmap_i_size(map); csmap_i_clear(&map); stc64_srandom(seed); c_forrange (i, s.iterations()) - csmap_i_emplace_or_assign(&map, stc64_random() & mask, i); + csmap_i_insert_or_assign(&map, stc64_random() & mask, i); stc64_srandom(seed); c_forrange (s.iterations()) @@ -178,7 +178,7 @@ static void ins_and_access_csmap_i(picobench::state& s) picobench::scope scope(s); c_forrange (s.iterations()) { - result += ++csmap_i_emplace(&map, stc64_random() & mask, 0).ref->second; + result += ++csmap_i_insert(&map, stc64_random() & mask, 0).ref->second; const csmap_i_value* val = csmap_i_get(&map, stc64_random() & mask); if (val) csmap_i_erase(&map, val->first); } @@ -294,7 +294,7 @@ static void iterate_csmap_x(picobench::state& s) // measure insert then iterate whole map c_forrange (n, s.iterations()) { - csmap_x_emplace_or_assign(&map, stc64_random(), n); + csmap_x_insert_or_assign(&map, stc64_random(), n); if (!(n & K)) c_foreach (i, csmap_x, map) result += i.ref->second; } diff --git a/benchmarks/plotbench/cmap_benchmark.cpp b/benchmarks/plotbench/cmap_benchmark.cpp index 16aec8c0..d8d1c6ab 100644 --- a/benchmarks/plotbench/cmap_benchmark.cpp +++ b/benchmarks/plotbench/cmap_benchmark.cpp @@ -73,8 +73,8 @@ Sample test_stc_unordered_map() { stc64_srandom(seed); s.test[INSERT].t1 = clock(); container con = cmap_x_init(); - c_forrange (i, N/2) cmap_x_emplace(&con, stc64_random() & mask1, i); - c_forrange (i, N/2) cmap_x_emplace(&con, i, i); + c_forrange (i, N/2) cmap_x_insert(&con, stc64_random() & mask1, i); + c_forrange (i, N/2) cmap_x_insert(&con, i, i); s.test[INSERT].t2 = clock(); s.test[INSERT].sum = cmap_x_size(con); stc64_srandom(seed); @@ -86,8 +86,8 @@ Sample test_stc_unordered_map() { }{ container con = cmap_x_init(); stc64_srandom(seed); - c_forrange (i, N/2) cmap_x_emplace(&con, stc64_random() & mask1, i); - c_forrange (i, N/2) cmap_x_emplace(&con, i, i); + c_forrange (i, N/2) cmap_x_insert(&con, stc64_random() & mask1, i); + c_forrange (i, N/2) cmap_x_insert(&con, i, i); stc64_srandom(seed); s.test[FIND].t1 = clock(); size_t sum = 0; diff --git a/benchmarks/plotbench/csmap_benchmark.cpp b/benchmarks/plotbench/csmap_benchmark.cpp index 4d1621e3..e7603b58 100644 --- a/benchmarks/plotbench/csmap_benchmark.cpp +++ b/benchmarks/plotbench/csmap_benchmark.cpp @@ -73,8 +73,8 @@ Sample test_stc_map() { stc64_srandom(seed); s.test[INSERT].t1 = clock(); container con = csmap_x_init(); - c_forrange (i, N/2) csmap_x_emplace(&con, stc64_random() & mask1, i); - c_forrange (i, N/2) csmap_x_emplace(&con, i, i); + c_forrange (i, N/2) csmap_x_insert(&con, stc64_random() & mask1, i); + c_forrange (i, N/2) csmap_x_insert(&con, i, i); s.test[INSERT].t2 = clock(); s.test[INSERT].sum = csmap_x_size(con); stc64_srandom(seed); @@ -86,8 +86,8 @@ Sample test_stc_map() { }{ container con = csmap_x_init(); stc64_srandom(seed); - c_forrange (i, N/2) csmap_x_emplace(&con, stc64_random() & mask1, i); - c_forrange (i, N/2) csmap_x_emplace(&con, i, i); + c_forrange (i, N/2) csmap_x_insert(&con, stc64_random() & mask1, i); + c_forrange (i, N/2) csmap_x_insert(&con, i, i); stc64_srandom(seed); s.test[FIND].t1 = clock(); size_t sum = 0; diff --git a/examples/birthday.c b/examples/birthday.c index f9b777c0..f848436c 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -23,7 +23,7 @@ static void test_repeats(void) cmap_ic_reserve(&m, N); c_forrange (i, N) { uint64_t k = stc64_rand(&rng) & mask; - int v = cmap_ic_emplace(&m, k, 0).ref->second += 1; + int v = cmap_ic_insert(&m, k, 0).ref->second += 1; if (v > 1) printf("repeated value %zu (%d) at 2^%d\n", k, v, (int) log2((double) i)); } } @@ -44,7 +44,7 @@ void test_distribution(void) c_auto (cmap_x, map) { c_forrange (N) { uint64_t k = stc64_rand(&rng); - cmap_x_emplace(&map, k & 0xf, 0).ref->second += 1; + cmap_x_insert(&map, k & 0xf, 0).ref->second += 1; } uint64_t sum = 0; diff --git a/examples/box2.c b/examples/box2.c index d79ea32d..fd76f8eb 100644 --- a/examples/box2.c +++ b/examples/box2.c @@ -38,7 +38,7 @@ Point origin(void) { cbox_Point boxed_origin(void) { // Allocate this point on the heap, and return a pointer to it - return cbox_Point_new((Point){ .x=0.0, .y=0.0 }); + return cbox_Point_from((Point){ .x=0.0, .y=0.0 }); } @@ -56,7 +56,7 @@ int main(void) { c_auto (cbox_Point, boxed_point) c_auto (cbox_BoxPoint, box_in_a_box) { - boxed_rectangle = cbox_Rectangle_new((Rectangle){ + boxed_rectangle = cbox_Rectangle_from((Rectangle){ .top_left = origin(), .bottom_right = (Point){ .x=3.0, .y=-4.0 } }); diff --git a/examples/csmap_find.c b/examples/csmap_find.c index 078c7a11..ea86d71b 100644 --- a/examples/csmap_find.c +++ b/examples/csmap_find.c @@ -51,18 +51,18 @@ int main() print_collection_csmap_istr(m1); typedef cvec_istr_value pair; - cvec_istr_emplace_back(&v, (pair){43, "Tc"}); - cvec_istr_emplace_back(&v, (pair){41, "Nb"}); - cvec_istr_emplace_back(&v, (pair){46, "Pd"}); - cvec_istr_emplace_back(&v, (pair){42, "Mo"}); - cvec_istr_emplace_back(&v, (pair){44, "Ru"}); - cvec_istr_emplace_back(&v, (pair){44, "Ru"}); // attempt a duplicate + cvec_istr_push_back(&v, (pair){43, "Tc"}); + cvec_istr_push_back(&v, (pair){41, "Nb"}); + cvec_istr_push_back(&v, (pair){46, "Pd"}); + cvec_istr_push_back(&v, (pair){42, "Mo"}); + cvec_istr_push_back(&v, (pair){44, "Ru"}); + cvec_istr_push_back(&v, (pair){44, "Ru"}); // attempt a duplicate puts("Inserting the following vector data into m1:"); print_collection_cvec_istr(v); c_foreach (i, cvec_istr, cvec_istr_begin(&v), cvec_istr_end(&v)) - csmap_istr_emplace(&m1, i.ref->first, i.ref->second); + csmap_istr_emplace(&m1, c_pair(*i.ref)); puts("The modified map m1 is (key, value):"); print_collection_csmap_istr(m1); diff --git a/examples/demos.c b/examples/demos.c index 32e5dde0..93192ee5 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -130,8 +130,8 @@ void mapdemo1() { printf("\nMAPDEMO1\n"); cmap_ii nums = cmap_ii_init(); - cmap_ii_emplace(&nums, 8, 64); - cmap_ii_emplace(&nums, 11, 121); + cmap_ii_insert(&nums, 8, 64); + cmap_ii_insert(&nums, 11, 121); printf("val 8: %d\n", *cmap_ii_at(&nums, 8)); cmap_ii_drop(&nums); } diff --git a/examples/ex_gauss1.c b/examples/ex_gauss1.c index 6725393f..8a39732a 100644 --- a/examples/ex_gauss1.c +++ b/examples/ex_gauss1.c @@ -39,7 +39,7 @@ int main() { c_forrange (N) { int index = (int) round( stc64_normalf(&rng, &dist) ); - cmap_ii_emplace(&histmap, index, 0).ref->second += 1; + cmap_ii_insert(&histmap, index, 0).ref->second += 1; } // Transfer map to vec and sort it by map keys. diff --git a/examples/new_sptr.c b/examples/new_sptr.c index 045eef77..23fe5791 100644 --- a/examples/new_sptr.c +++ b/examples/new_sptr.c @@ -37,8 +37,8 @@ int main(void) { cstack_iptr_push(&stk, carc_int_from(10)); cstack_iptr_push(&stk, carc_int_from(20)); cstack_iptr_push(&stk, carc_int_from(30)); - cstack_iptr_emplace(&stk, *cstack_iptr_top(&stk)); - cstack_iptr_emplace(&stk, *cstack_iptr_begin(&stk).ref); + cstack_iptr_push(&stk, *cstack_iptr_top(&stk)); + cstack_iptr_push(&stk, *cstack_iptr_begin(&stk).ref); c_foreach (i, cstack_iptr, stk) printf(" %d", *i.ref->get); diff --git a/include/stc/carc.h b/include/stc/carc.h index 505b47d9..b4e2e435 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -144,7 +144,7 @@ _cx_memb(_reset_from)(_cx_self* self, i_val val) { *self = _cx_memb(_from)(val); } -#if !c_option(c_no_clone) && !defined _i_valraw_default +#if !c_option(c_no_clone) && !defined _i_no_raw STC_INLINE _cx_self _cx_memb(_new)(i_valraw raw) { return _cx_memb(_from)(i_valfrom(raw)); } diff --git a/include/stc/cbox.h b/include/stc/cbox.h index fdde5e8c..7ed0d641 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -120,12 +120,12 @@ _cx_memb(_reset_from)(_cx_self* self, i_val val) { } #if !c_option(c_no_clone) - //#ifndef _i_valraw_default +#if !defined _i_no_raw STC_INLINE _cx_self _cx_memb(_new)(i_valraw raw) { return c_make(_cx_self){c_new(i_val, i_valfrom(raw))}; } - //#endif +#endif STC_INLINE _cx_self _cx_memb(_clone)(_cx_self other) { diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index f0866dad..97a19311 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -45,13 +45,15 @@ STC_API void _cx_memb(_clear)(_cx_self* self); STC_API void _cx_memb(_drop)(_cx_self* self); STC_API _cx_value* _cx_memb(_push_back)(_cx_self* self, i_val value); STC_API bool _cx_memb(_expand_right_half_)(_cx_self* self, size_t idx, size_t n); +STC_API void _cx_memb(_shrink_to_fit)(_cx_self *self); #ifndef _i_queue #if !c_option(c_no_clone) -STC_API void _cx_memb(_shrink_to_fit)(_cx_self *self); STC_API _cx_iter _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2); +#if !defined _i_no_raw STC_API _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, const _cx_raw* p2); +#endif #endif // !c_no_clone #if !c_option(c_no_cmp) @@ -66,8 +68,10 @@ STC_API _cx_iter _cx_memb(_insert_range_p)(_cx_self* self, _cx_value* pos #if !c_option(c_no_clone) STC_API _cx_self _cx_memb(_clone)(_cx_self cx); +#if !defined _i_no_raw STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) { return _cx_memb(_push_back)(self, i_valfrom(raw)); } +#endif STC_INLINE i_val _cx_memb(_value_clone)(i_val val) { return i_valfrom(i_valto(&val)); } STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { @@ -150,7 +154,7 @@ _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) { return _cx_memb(_erase_range_p)(self, it1.ref, it2.ref); } -#if !c_option(c_no_clone) +#if !c_option(c_no_clone) && !defined _i_no_raw STC_INLINE _cx_iter _cx_memb(_emplace_range)(_cx_self* self, _cx_iter it, _cx_iter it1, _cx_iter it2) { @@ -367,7 +371,7 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) { } #if !c_option(c_no_clone) - +#if !defined _i_no_raw STC_DEF _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, const _cx_raw* p2) { pos = _cx_memb(_insert_space_)(self, pos, p2 - p1); @@ -375,7 +379,7 @@ _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, co for (; p1 != p2; ++p1) *pos++ = i_valfrom(*p1); return it; } - +#endif STC_DEF _cx_iter _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2) { diff --git a/include/stc/clist.h b/include/stc/clist.h index 2194067c..e2ff694e 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -109,20 +109,21 @@ STC_API _cx_node* _cx_memb(_erase_after_)(_cx_self* self, _cx_node* node); #if !c_option(c_no_clone) STC_API _cx_self _cx_memb(_clone)(_cx_self cx); -STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) - { return _cx_memb(_push_back)(self, i_valfrom(raw)); } -STC_INLINE _cx_value* _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw) - { return _cx_memb(_push_front)(self, i_valfrom(raw)); } -STC_INLINE _cx_iter _cx_memb(_emplace)(_cx_self* self, _cx_iter it, i_valraw raw) - { return _cx_memb(_insert)(self, it, i_valfrom(raw)); } STC_INLINE i_val _cx_memb(_value_clone)(i_val val) { return i_valfrom(i_valto(&val)); } - STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { if (self->last == other.last) return; _cx_memb(_drop)(self); *self = _cx_memb(_clone)(other); } +#if !defined _i_no_raw +STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) + { return _cx_memb(_push_back)(self, i_valfrom(raw)); } +STC_INLINE _cx_value* _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw) + { return _cx_memb(_push_front)(self, i_valfrom(raw)); } +STC_INLINE _cx_iter _cx_memb(_emplace)(_cx_self* self, _cx_iter it, i_valraw raw) + { return _cx_memb(_insert)(self, it, i_valfrom(raw)); } +#endif #endif STC_INLINE _cx_self _cx_memb(_init)(void) { return c_make(_cx_self){NULL}; } STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, size_t n) { return true; } @@ -190,7 +191,7 @@ _cx_memb(_get_mut)(_cx_self* self, i_valraw val) { STC_DEF _cx_self _cx_memb(_clone)(_cx_self cx) { _cx_self out = _cx_memb(_init)(); - c_foreach (it, _cx_self, cx) _cx_memb(_emplace_back)(&out, i_valto(it.ref)); + c_foreach (it, _cx_self, cx) _cx_memb(_push_back)(&out, i_valfrom(i_valto(it.ref))); return out; } #endif diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 87ed7c6c..2d0b11fc 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -111,7 +111,7 @@ STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, i_keyraw rkey) { return self->size && self->_hashx[_cx_memb(_bucket_)(self, &rkey).idx]; } #ifndef _i_isset - #if !c_option(c_no_clone) + #if !c_option(c_no_clone) && !defined _i_no_raw STC_API _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped); #endif STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped); @@ -141,7 +141,7 @@ _cx_memb(_value_clone)(_cx_value _val) { _i_MAP_ONLY( _val.second = i_valfrom(i_valto(&_val.second)); ) return _val; } - +#if !defined _i_no_raw STC_INLINE _cx_result _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped)) { _cx_result _res = _cx_memb(_insert_entry_)(self, rkey); @@ -151,6 +151,7 @@ _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped) } return _res; } +#endif #endif // !c_no_clone STC_INLINE _cx_raw @@ -273,7 +274,7 @@ STC_DEF void _cx_memb(_clear)(_cx_self* self) { else { i_keydrop(&_key); i_valdrop(&_res.ref->second); } _res.ref->second = _mapped; return _res; } - #if !c_option(c_no_clone) + #if !c_option(c_no_clone) && !defined _i_no_raw STC_DEF _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) { _cx_result _res = _cx_memb(_insert_entry_)(self, rkey); diff --git a/include/stc/cpque.h b/include/stc/cpque.h index caea1549..bf519125 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -99,12 +99,12 @@ STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { if (self->data == other.data) return; _cx_memb(_drop)(self); *self = _cx_memb(_clone)(other); } - -STC_INLINE void _cx_memb(_emplace)(_cx_self* self, _cx_value val) - { _cx_memb(_push)(self, i_valfrom(val)); } - STC_INLINE i_val _cx_memb(_value_clone)(_cx_value val) { return i_valfrom(val); } +#if !defined _i_no_raw +STC_INLINE void _cx_memb(_emplace)(_cx_self* self, _cx_value val) + { _cx_memb(_push)(self, i_valfrom(val)); } +#endif #endif /* -------------------------- IMPLEMENTATION ------------------------- */ diff --git a/include/stc/csmap.h b/include/stc/csmap.h index 8115cf46..fb8c868e 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -147,7 +147,7 @@ _cx_memb(_value_drop)(_cx_value* val) { } #ifndef _i_isset - #if !c_option(c_no_clone) + #if !c_option(c_no_clone) && !defined _i_no_raw STC_API _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped); #endif STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped); @@ -181,7 +181,7 @@ _cx_memb(_value_clone)(_cx_value _val) { _i_MAP_ONLY( _val.second = i_valfrom(i_valto(&_val.second)); ) return _val; } - +#if !defined _i_no_raw STC_INLINE _cx_result _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped)) { _cx_result res = _cx_memb(_insert_entry_)(self, rkey); @@ -191,6 +191,7 @@ _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped) } return res; } +#endif #endif // !c_no_clone STC_INLINE _cx_result @@ -289,7 +290,7 @@ _cx_memb(_node_new_)(_cx_self* self, int level) { else { i_keydrop(&key); i_valdrop(&res.ref->second); } res.ref->second = mapped; return res; } - #if !c_option(c_no_clone) + #if !c_option(c_no_clone) && !defined _i_no_raw STC_DEF _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) { _cx_result res = _cx_memb(_insert_entry_)(self, rkey); diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 387c0126..1ceec0cb 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -95,10 +95,10 @@ STC_INLINE const _cx_value* _cx_memb(_at)(const _cx_self* self, size_t idx) { assert(idx < self->size); return self->data + idx; } #if !c_option(c_no_clone) - +#if !defined _i_no_raw STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_raw raw) { return _cx_memb(_push)(self, i_valfrom(raw)); } - +#endif STC_INLINE _cx_self _cx_memb(_clone)(_cx_self v) { _cx_self out = {(_cx_value *) c_malloc(v.size*sizeof(_cx_value)), v.size, v.size}; for (size_t i = 0; i < v.size; ++i, ++v.data) out.data[i] = i_valfrom(i_valto(v.data)); diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 3486cc37..1faa16c3 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -97,20 +97,21 @@ STC_API _cx_iter _cx_memb(_bsearch_in)(_cx_iter it1, _cx_iter it2, i_valr STC_API _cx_self _cx_memb(_clone)(_cx_self cx); STC_API _cx_iter _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2); -STC_API _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, - const _cx_raw* p1, const _cx_raw* p2); STC_INLINE i_val _cx_memb(_value_clone)(_cx_value val) { return i_valfrom(i_valto(&val)); } STC_INLINE i_val _cx_memb(_value_fromraw)(i_valraw raw) { return i_valfrom(raw); } -STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) - { return _cx_memb(_push_back)(self, i_valfrom(raw)); } -STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, i_valraw raw) - { return _cx_memb(_push_back)(self, i_valfrom(raw)); } STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { if (self->data == other.data) return; _cx_memb(_drop)(self); *self = _cx_memb(_clone)(other); } +#if !defined _i_no_raw +STC_API _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, + const _cx_raw* p1, const _cx_raw* p2); +STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) + { return _cx_memb(_push_back)(self, i_valfrom(raw)); } +STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, i_valraw raw) + { return _cx_memb(_push_back)(self, i_valfrom(raw)); } STC_INLINE _cx_iter _cx_memb(_emplace_n)(_cx_self* self, const size_t idx, const _cx_raw arr[], const size_t n) { return _cx_memb(_emplace_range_p)(self, self->data + idx, arr, arr + n); @@ -124,6 +125,7 @@ _cx_memb(_emplace_range)(_cx_self* self, _cx_iter it, _cx_iter it1, _cx_iter it2 return _cx_memb(_clone_range_p)(self, it.ref, it1.ref, it2.ref); } #endif +#endif STC_INLINE size_t _cx_memb(_size)(_cx_self cx) { return cvec_rep_(&cx)->size; } STC_INLINE size_t _cx_memb(_capacity)(_cx_self cx) { return cvec_rep_(&cx)->cap; } @@ -347,7 +349,7 @@ _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos, for (; p1 != p2; ++p1) *pos++ = i_valfrom(i_valto(p1)); return it; } - +#if !defined _i_no_raw STC_DEF _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, const _cx_raw* p2) { @@ -357,6 +359,7 @@ _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, return it; } #endif +#endif #if !c_option(c_no_cmp) diff --git a/include/stc/template.h b/include/stc/template.h index 5efe3772..7d5c70b9 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -165,7 +165,7 @@ #define i_keyfrom c_default_clone #endif #ifndef i_keyraw - #define _i_keyraw_default + #define _i_no_keyraw #define i_keyraw i_key #define i_keyto c_default_toraw #endif @@ -191,7 +191,9 @@ #define i_valfrom c_default_clone #endif #ifndef i_valraw - #define _i_valraw_default + #if !defined i_key || defined _i_no_keyraw + #define _i_no_raw + #endif #define i_valraw i_val #define i_valto c_default_toraw #endif @@ -236,8 +238,8 @@ #undef i_keydrop #undef _i_prefix -#undef _i_valraw_default -#undef _i_keyraw_default +#undef _i_no_raw +#undef _i_no_keyraw #undef _i_has_internal_clone #undef _i_template #endif -- cgit v1.2.3