From 649060e1275f04985ded4b324ae8e2b004788e78 Mon Sep 17 00:00:00 2001 From: Tyge Lovset Date: Tue, 10 May 2022 08:58:04 +0200 Subject: Renamed (newish) functions expand_uninitialized to expand_uninit. + some minor changes. --- benchmarks/misc/prng_bench.cpp | 33 +++++++++++++++++++++++++++++++++ benchmarks/misc/sso_bench.cpp | 3 +-- docs/cstack_api.md | 2 +- docs/cstr_api.md | 2 +- docs/cvec_api.md | 2 +- include/stc/alt/csmap.h | 6 ++++-- include/stc/alt/cstr.h | 2 +- include/stc/csmap.h | 6 ++++-- include/stc/cstack.h | 2 +- include/stc/cstr.h | 2 +- include/stc/cvec.h | 14 +++++++------- 11 files changed, 55 insertions(+), 19 deletions(-) diff --git a/benchmarks/misc/prng_bench.cpp b/benchmarks/misc/prng_bench.cpp index e3524766..9d840316 100644 --- a/benchmarks/misc/prng_bench.cpp +++ b/benchmarks/misc/prng_bench.cpp @@ -41,6 +41,22 @@ static inline uint64_t sfc64(uint64_t s[4]) { return result; } +uint32_t sfc32(uint32_t s[4]) { + uint32_t t = s[0] + s[1] + s[3]++; + s[0] = s[1] ^ (s[1] >> 9); + s[1] = s[2] + (s[2] << 3); + s[2] = (s[2] << 21) | (s[2] >> 11) + t; + return t; +} + +uint32_t stc32(uint32_t s[5]) { + uint32_t t = (s[0] ^ (s[3] += s[4])) + s[1]; + s[0] = s[1] ^ (s[1] >> 9); + s[1] = s[2] + (s[2] << 3); + s[2] = (s[2] << 21) | (s[2] >> 11) + t; + return t; +} + /* xoshiro128+ */ uint64_t xoroshiro128plus(uint64_t s[2]) { @@ -128,6 +144,22 @@ int main(void) << (float(end - beg) / CLOCKS_PER_SEC) << "s: " << recipient[312] << endl; + beg = clock(); + for (size_t i = 0; i < N; i++) + recipient[i] = sfc32((uint32_t *)rng.state); + end = clock(); + cout << "sfc32:\t\t" + << (float(end - beg) / CLOCKS_PER_SEC) + << "s: " << recipient[312] << endl; + + beg = clock(); + for (size_t i = 0; i < N; i++) + recipient[i] = stc32((uint32_t *)rng.state); + end = clock(); + cout << "stc32:\t\t" + << (float(end - beg) / CLOCKS_PER_SEC) + << "s: " << recipient[312] << endl; + beg = clock(); for (size_t i = 0; i < N; i++) recipient[i] = sfc64(rng.state); @@ -144,6 +176,7 @@ int main(void) << (float(end - beg) / CLOCKS_PER_SEC) << "s: " << recipient[312] << endl; + beg = clock(); for (size_t i = 0; i < N; i++) recipient[i] = xoroshiro128plus(rng.state); diff --git a/benchmarks/misc/sso_bench.cpp b/benchmarks/misc/sso_bench.cpp index e8ecd9ba..f503ffb0 100644 --- a/benchmarks/misc/sso_bench.cpp +++ b/benchmarks/misc/sso_bench.cpp @@ -12,7 +12,7 @@ using stdcon = std::vector; static const int BENCHMARK_SIZE = 5000000; -static const int MAX_STRING_LENGTH = 60; +static const int MAX_STRING_LENGTH = 40; static const char CHARS[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=+-"; using time_point = std::chrono::high_resolution_clock::time_point; @@ -86,7 +86,6 @@ int main() { std::cout << '\t' << *con.begin() << '\n'; } std::cout << "Avg:\t" << sum/n << '\n'; - csrandom(seed); sum = 0, n = 0; diff --git a/docs/cstack_api.md b/docs/cstack_api.md index b30957d1..0c5933d0 100644 --- a/docs/cstack_api.md +++ b/docs/cstack_api.md @@ -31,7 +31,7 @@ cstack_X cstack_X_clone(cstack_X st); void cstack_X_clear(cstack_X* self); bool cstack_X_reserve(cstack_X* self, size_t n); void cstack_X_shrink_to_fit(cstack_X* self); -i_val* cstack_X_expand_uninitialized(cstack_X* self, size_t n); +i_val* cstack_X_expand_uninit(cstack_X* self, size_t n); void cstack_X_copy(cstack_X* self, cstack_X other); void cstack_X_drop(cstack_X* self); // destructor diff --git a/docs/cstr_api.md b/docs/cstr_api.md index 66a604a0..54178d29 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -42,7 +42,7 @@ bool cstr_empty(cstr s); size_t cstr_reserve(cstr* self, size_t capacity); void cstr_resize(cstr* self, size_t len, char fill); void cstr_shrink_to_fit(cstr* self); -char* cstr_expand_uninitialized(cstr* self, size_t n); // return ptr to uninit data +char* cstr_expand_uninit(cstr* self, size_t n); // return ptr to uninit data void cstr_clear(cstr* self); cstr* cstr_assign(cstr* self, const char* str); diff --git a/docs/cvec_api.md b/docs/cvec_api.md index d60ee5fe..3e12e5e2 100644 --- a/docs/cvec_api.md +++ b/docs/cvec_api.md @@ -36,7 +36,7 @@ void cvec_X_clear(cvec_X* self); void cvec_X_copy(cvec_X* self, cvec_X other); bool cvec_X_reserve(cvec_X* self, size_t cap); bool cvec_X_resize(cvec_X* self, size_t size, i_val null); -cvec_X_value* cvec_X_expand_uninitialized(cvec_X* self, size_t n); // return start of uninit +cvec_X_value* cvec_X_expand_uninit(cvec_X* self, size_t n); // return start of uninit void cvec_X_shrink_to_fit(cvec_X* self); void cvec_X_swap(cvec_X* a, cvec_X* b); void cvec_X_drop(cvec_X* self); // destructor diff --git a/include/stc/alt/csmap.h b/include/stc/alt/csmap.h index b7c4fe39..1e6f1836 100644 --- a/include/stc/alt/csmap.h +++ b/include/stc/alt/csmap.h @@ -448,9 +448,11 @@ _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) { for (;;) { if (memcmp(&k1, &k2, sizeof k1) == 0) return it1; - _cx_memb(_next)(&it1); k1 = *_i_keyref(it1.ref); + _cx_memb(_next)(&it1); + k1 = *_i_keyref(it1.ref); _cx_memb(_erase)(self, r1); - _cx_memb(_find_it)(self, (r1 = i_keyto((&k1))), &it1); + r1 = i_keyto((&k1)); + _cx_memb(_find_it)(self, r1, &it1); } } diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h index 98f5c8f5..ef116ade 100644 --- a/include/stc/alt/cstr.h +++ b/include/stc/alt/cstr.h @@ -137,7 +137,7 @@ STC_INLINE cstr cstr_with_size(const size_t len, const char fill) { return s; } -STC_INLINE char* cstr_expand_uninitialized(cstr *self, size_t n) { +STC_INLINE char* cstr_expand_uninit(cstr *self, size_t n) { size_t len = cstr_size(*self); char* d; if (!(d = cstr_reserve(self, len + n))) return NULL; _cstr_p(self)->size += n; diff --git a/include/stc/csmap.h b/include/stc/csmap.h index 405ca5bb..d1db9031 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -522,9 +522,11 @@ _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) { for (;;) { if (memcmp(&k1, &k2, sizeof k1) == 0) return it1; - _cx_memb(_next)(&it1); k1 = *_i_keyref(it1.ref); + _cx_memb(_next)(&it1); + k1 = *_i_keyref(it1.ref); _cx_memb(_erase)(self, r1); - _cx_memb(_find_it)(self, (r1 = i_keyto((&k1))), &it1); + r1 = i_keyto((&k1)); + _cx_memb(_find_it)(self, r1, &it1); } } diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 3705c247..61d69f0c 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -78,7 +78,7 @@ STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, size_t n) { } STC_INLINE _cx_value* -_cx_memb(_expand_uninitialized)(_cx_self *self, size_t n) { +_cx_memb(_expand_uninit)(_cx_self *self, size_t n) { size_t len = self->size; if (!_cx_memb(_reserve)(self, len + n)) return NULL; self->size += n; diff --git a/include/stc/cstr.h b/include/stc/cstr.h index dadb6ee5..959714d1 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -174,7 +174,7 @@ STC_INLINE size_t cstr_length(cstr s) STC_INLINE size_t cstr_capacity(cstr s) { return cstr_is_long(&s) ? cstr_l_cap(&s) : cstr_s_cap; } -STC_INLINE char* cstr_expand_uninitialized(cstr *self, size_t n) { +STC_INLINE char* cstr_expand_uninit(cstr *self, size_t n) { size_t len = cstr_size(*self); char* d; if (!(d = cstr_reserve(self, len + n))) return NULL; _cstr_set_size(self, len + n); diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 83c8680d..488fa9cb 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -86,7 +86,7 @@ STC_API _cx_value* _cx_memb(_push)(_cx_self* self, i_key value); STC_API _cx_iter _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2); STC_API _cx_value* _cx_memb(_insert_range_p)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2); -STC_API _cx_value* _cx_memb(_expand_uninitialized_at_p)(_cx_self* self, _cx_value* pos, const size_t n); +STC_API _cx_value* _cx_memb(_expand_uninit_p)(_cx_self* self, _cx_value* pos, const size_t n); #if !c_option(c_no_cmp) STC_API int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y); STC_API _cx_iter _cx_memb(_find_in)(_cx_iter it1, _cx_iter it2, i_keyraw raw); @@ -169,8 +169,8 @@ _cx_memb(_shrink_to_fit)(_cx_self *self) { } STC_INLINE _cx_value* -_cx_memb(_expand_uninitialized)(_cx_self *self, const size_t n) { - return _cx_memb(_expand_uninitialized_at_p)(self, self->data + _cx_memb(_size)(*self), n); +_cx_memb(_expand_uninit)(_cx_self *self, const size_t n) { + return _cx_memb(_expand_uninit_p)(self, self->data + _cx_memb(_size)(*self), n); } STC_INLINE _cx_value* @@ -321,7 +321,7 @@ _cx_memb(_push)(_cx_self* self, i_key value) { } STC_DEF _cx_value* -_cx_memb(_expand_uninitialized_at_p)(_cx_self* self, _cx_value* pos, const size_t n) { +_cx_memb(_expand_uninit_p)(_cx_self* self, _cx_value* pos, const size_t n) { const size_t idx = pos - self->data; struct cvec_rep* r = cvec_rep_(self); if (!n) return pos; @@ -339,7 +339,7 @@ _cx_memb(_expand_uninitialized_at_p)(_cx_self* self, _cx_value* pos, const size_ STC_DEF _cx_value* _cx_memb(_insert_range_p)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2) { - pos = _cx_memb(_expand_uninitialized_at_p)(self, pos, p2 - p1); + pos = _cx_memb(_expand_uninit_p)(self, pos, p2 - p1); if (pos) memcpy(pos, p1, (p2 - p1)*sizeof *p1); return pos; } @@ -369,7 +369,7 @@ _cx_memb(_clone)(_cx_self cx) { STC_DEF _cx_value* _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2) { - pos = _cx_memb(_expand_uninitialized_at_p)(self, pos, p2 - p1); + pos = _cx_memb(_expand_uninit_p)(self, pos, p2 - p1); _cx_value* it = pos; if (pos) for (; p1 != p2; ++p1) *pos++ = i_keyclone((*p1)); @@ -380,7 +380,7 @@ _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos, STC_DEF _cx_value* _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, const _cx_raw* p2) { - pos = _cx_memb(_expand_uninitialized_at_p)(self, pos, p2 - p1); + pos = _cx_memb(_expand_uninit_p)(self, pos, p2 - p1); _cx_value* it = pos; if (pos) for (; p1 != p2; ++p1) *pos++ = i_keyfrom((*p1)); -- cgit v1.2.3