From 9fe11c724b4b58bf59de17ff029692ca9c0631f1 Mon Sep 17 00:00:00 2001 From: Tyge Løvset <60263450+tylov@users.noreply.github.com> Date: Mon, 20 Sep 2021 22:12:36 +0200 Subject: Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 28e955a8..1ee52fdf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![STC](docs/pics/containers.jpg) -STC - Smart Templated Containers for C +STC - Smart Template Containers for C ====================================== News -- cgit v1.2.3 From 8c4c412dfa1995a68e18510bb7ba0401ec96abb5 Mon Sep 17 00:00:00 2001 From: Camel Coder <69110542+camel-cdr@users.noreply.github.com> Date: Mon, 20 Sep 2021 20:26:17 +0000 Subject: Added proper fallback for stc64_uniform --- include/stc/crandom.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/include/stc/crandom.h b/include/stc/crandom.h index 38ab6b4b..eef4b6a4 100644 --- a/include/stc/crandom.h +++ b/include/stc/crandom.h @@ -118,13 +118,20 @@ STC_INLINE double stc64_uniformf(stc64_t* rng, stc64_uniformf_t* dist) { } /* Unbiased bounded uniform distribution. */ -#ifdef c_umul128 STC_INLINE int64_t stc64_uniform(stc64_t* rng, stc64_uniform_t* d) { +#ifdef c_umul128 uint64_t lo, hi; do { c_umul128(stc64_rand(rng), d->range, &lo, &hi); } while (lo < d->threshold); return d->lower + hi; -} +#else + uint64_t x, r; + do { + x = stc64_rand(rng); + r = x % d->range; + } while (x - r > -d->range); + return d->lower + r; #endif +} STC_INLINE int32_t stc32_uniform(stc32_t* rng, stc32_uniform_t* d) { uint64_t val; @@ -165,14 +172,14 @@ STC_DEF stc32_t stc32_with_seq(uint32_t seed, uint32_t seq) { for (int i = 0; i < 6; ++i) stc32_rand(&rng); return rng; } -#ifdef c_umul128 + /* Init unbiased uniform uint RNG with bounds [low, high] */ STC_DEF stc64_uniform_t stc64_uniform_init(int64_t low, int64_t high) { stc64_uniform_t dist = {low, (uint64_t) (high - low + 1)}; dist.threshold = (uint64_t)(-dist.range) % dist.range; return dist; } -#endif + STC_DEF stc32_uniform_t stc32_uniform_init(int32_t low, int32_t high) { stc32_uniform_t dist = {low, (uint32_t) (high - low + 1)}; dist.threshold = (uint32_t)(-dist.range) % dist.range; -- cgit v1.2.3 From bcd6e966bd9702e0c315213917d445c2370dd1ec Mon Sep 17 00:00:00 2001 From: Tyge Løvset <60263450+tylov@users.noreply.github.com> Date: Tue, 21 Sep 2021 08:57:43 +0200 Subject: Update README.md Added example suggested by ibgeek --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 1ee52fdf..4fd34197 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,22 @@ int main(void) { cvec_float_del(&vec); } ``` +In order to include two **cvec**s with different element types, include cvec.h twice. For structs, specify a compare function (or none), as `<` and `==` operators does not work on them (this enables sorting and searching). +```c +#define i_val struct One +#define i_tag one +#define i_cmp c_no_compare +#include + +#define i_val struct Two +#define i_tag two +#define i_cmp c_no_compare +#include +... +cvec_one v1 = cvec_one_init(); +cvec_two v2 = cvec_two_init(); +``` + With six different containers: ```c #include -- cgit v1.2.3