From 3f8b2dc63df4745b41aab23a9af1cec107fb1df8 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Mon, 6 Sep 2021 07:29:55 +0200 Subject: Some more additions. --- include/stc/cbits.h | 8 ++++---- include/stc/crandom.h | 20 ++++++++++---------- include/stc/cstr.h | 6 +++--- include/stc/csview.h | 12 ++++++------ include/stc/vec_test_new.c | 16 ++++++++++------ 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/include/stc/cbits.h b/include/stc/cbits.h index 2424f70f..af767207 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -56,10 +56,10 @@ int main() { #include #include "ccommon.h" -typedef struct { - uint64_t *data64; - size_t size; -} cbits; +struct cbits { + uint64_t *data64; + size_t size; +} typedef cbits; STC_API cbits cbits_with_size(size_t size, bool value); STC_API cbits cbits_with_values(size_t size, uint64_t pattern); diff --git a/include/stc/crandom.h b/include/stc/crandom.h index 7be7ea6c..978e8740 100644 --- a/include/stc/crandom.h +++ b/include/stc/crandom.h @@ -43,20 +43,20 @@ int main() { #include #include -typedef struct { uint64_t state[5]; } stc64_t; -typedef struct { uint32_t state[5]; } stc32_t; -typedef struct { int64_t lower; uint64_t range, threshold; } stc64_uniform_t; -typedef struct { double lower, range; } stc64_uniformf_t; -typedef struct { double mean, stddev, next; unsigned has_next; } stc64_normalf_t; +typedef struct stc64 { uint64_t state[5]; } stc64_t; +typedef struct stc32 { uint32_t state[5]; } stc32_t; +typedef struct stc64_uniform { int64_t lower; uint64_t range, threshold; } stc64_uniform_t; +typedef struct stc64_uniformf { double lower, range; } stc64_uniformf_t; +typedef struct stc64_normalf { double mean, stddev, next; unsigned has_next; } stc64_normalf_t; /* PRNG stc64. * Very fast PRNG suited for parallel usage with Weyl-sequence parameter. * 320-bit state, 256 bit is mutable. - * Noticable faster than xoshiro and pcg, slighly slower than wyrand64 and + * Noticable faster than xoshiro and pcg, slighly slower than wyrand64 and * Romu, but these have restricted capacity for larger parallel jobs or unknown minimum periods. * stc64 supports 2^63 unique threads with a minimum 2^64 period lengths each. * Passes all statistical tests, e.g PractRand and correlation tests, i.e. interleaved - * streams with one-bit diff state. Even the 16-bit version (LR=6, RS=5, LS=3) passes + * streams with one-bit diff state. Even the 16-bit version (LR=6, RS=5, LS=3) passes * PractRand to multiple TB input. */ @@ -137,15 +137,15 @@ static stc64_t stc64_global = {{ 0x6a09e667a754166b }}; -STC_DEF void stc64_srandom(uint64_t seed) { - stc64_global = stc64_init(seed); +STC_DEF void stc64_srandom(uint64_t seed) { + stc64_global = stc64_init(seed); } STC_DEF uint64_t stc64_random(void) { return stc64_rand(&stc64_global); } -/* rng.state[4] must be odd */ +/* rng.state[4] must be odd */ STC_DEF stc64_t stc64_with_seq(uint64_t seed, uint64_t seq) { stc64_t rng = {{seed, seed+0x26aa069ea2fb1a4d, seed+0x70c72c95cd592d04, seed+0x504f333d3aa0b359, (seq << 1) | 1}}; diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 67f1a0a5..a14c4f72 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -30,9 +30,9 @@ #include /* vsnprintf */ #include -typedef struct { char* str; } cstr; -typedef struct { char *ref; } cstr_iter_t; -typedef char cstr_value_t; +typedef struct cstr { char* str; } cstr; +typedef struct cstr_iter { char *ref; } cstr_iter_t; +typedef char cstr_value_t; #define cstr_npos (SIZE_MAX >> 1) STC_LIBRARY_ONLY( extern const cstr cstr_null; ) diff --git a/include/stc/csview.h b/include/stc/csview.h index d5d6d246..6733912d 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -25,8 +25,8 @@ #include "cstr.h" -typedef struct { const char* str; size_t size; } csview; -typedef struct { const char *ref; } csview_iter_t; +typedef struct csview { const char* str; size_t size; } csview; +typedef struct csview_iter { const char *ref; } csview_iter_t; typedef char csview_value_t; #define csview_null c_make(csview){"", 0} @@ -81,12 +81,12 @@ STC_INLINE void csview_next(csview_iter_t* it) { ++it->ref; } STC_INLINE cstr cstr_from_v(csview sv) { return cstr_from_n(sv.str, sv.size); } -STC_INLINE cstr cstr_from_replace_all_v(csview sv, csview find, csview repl) +STC_INLINE cstr cstr_from_replace_all_v(csview sv, csview find, csview repl) { return cstr_from_replace_all(sv.str, sv.size, find.str, find.size, repl.str, repl.size); } STC_INLINE csview cstr_to_v(const cstr* self) { return c_make(csview){self->str, _cstr_rep(self)->size}; } -STC_INLINE csview cstr_substr(cstr s, intptr_t pos, size_t n) +STC_INLINE csview cstr_substr(cstr s, intptr_t pos, size_t n) { return csview_substr(csview_from_s(s), pos, n); } STC_INLINE csview cstr_slice(cstr s, intptr_t p1, intptr_t p2) { return csview_slice(csview_from_s(s), p1, p2); } @@ -133,12 +133,12 @@ STC_DEF csview csview_slice(csview sv, intptr_t p1, intptr_t p2) { if (p1 < 0) { p1 += sv.size; if (p1 < 0) p1 = 0; } if (p2 < 0) p2 += sv.size; if (p2 > sv.size) p2 = sv.size; - sv.str += p1, sv.size = p2 > p1 ? p2 - p1 : 0; return sv; + sv.str += p1, sv.size = p2 > p1 ? p2 - p1 : 0; return sv; } STC_DEF csview csview_first_token(csview sv, csview sep) { - const char* res = c_strnstrn(sv.str, sep.str, sv.size, sep.size); + const char* res = c_strnstrn(sv.str, sep.str, sv.size, sep.size); return c_make(csview){sv.str, (res ? res - sv.str : sv.size)}; } diff --git a/include/stc/vec_test_new.c b/include/stc/vec_test_new.c index 65bb0ff9..c64f633c 100644 --- a/include/stc/vec_test_new.c +++ b/include/stc/vec_test_new.c @@ -14,10 +14,6 @@ struct MyStruct { #define i_VAL int #include "cvec.h" -#define i_TAG f32 -#define i_VAL float -#include "cvec.h" - struct Point { int x, y; } typedef Point; int point_compare(const Point* a, const Point* b) { int c = c_default_compare(&a->x, &b->x); @@ -28,6 +24,9 @@ int point_compare(const Point* a, const Point* b) { #define i_CMP point_compare #include "cvec.h" +#define i_VAL float +#include "cvec.h" + #define i_VAL_str #include "cvec.h" @@ -36,9 +35,11 @@ int main() { cvec_i32 vec = cvec_i32_init(); cvec_i32_push_back(&vec, 123); + cvec_i32_del(&vec); - cvec_f32 fvec = cvec_f32_init(); - cvec_f32_push_back(&fvec, 123.3); + cvec_float fvec = cvec_float_init(); + cvec_float_push_back(&fvec, 123.3); + cvec_float_del(&fvec); cvec_pnt pvec = cvec_pnt_init(); cvec_pnt_push_back(&pvec, (Point){42, 14}); @@ -48,6 +49,9 @@ int main() c_foreach (i, cvec_pnt, pvec) printf(" (%d %d)", i.ref->x, i.ref->y); puts(""); + cvec_pnt_del(&pvec); + cvec_str svec = cvec_str_init(); cvec_str_emplace_back(&svec, "Hello, friend"); + cvec_str_del(&svec); } \ No newline at end of file -- cgit v1.2.3