summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-04-28 17:01:58 +0200
committerTyge Løvset <[email protected]>2023-04-28 17:01:58 +0200
commit49e7d9cc0a888b0b19aa4e737d55a2bc33bec824 (patch)
tree6e4aea9d457fe89a3dd1be441c88000539614b54 /include
parenta922157394a9a3e0cffe26a5fa4d29c9d78ecc06 (diff)
downloadSTC-modified-49e7d9cc0a888b0b19aa4e737d55a2bc33bec824.tar.gz
STC-modified-49e7d9cc0a888b0b19aa4e737d55a2bc33bec824.zip
Removed crandom.h and altnames.h. Housholding.
Diffstat (limited to 'include')
-rw-r--r--include/stc/algo/crange.h4
-rw-r--r--include/stc/algo/csort.h20
-rw-r--r--include/stc/carc.h2
-rw-r--r--include/stc/cbox.h2
-rw-r--r--include/stc/ccommon.h1
-rw-r--r--include/stc/clist.h2
-rw-r--r--include/stc/cmap.h21
-rw-r--r--include/stc/cpque.h3
-rw-r--r--include/stc/cqueue.h2
-rw-r--r--include/stc/crandom.h197
-rw-r--r--include/stc/cset.h3
-rw-r--r--include/stc/csmap.h13
-rw-r--r--include/stc/csset.h3
-rw-r--r--include/stc/cstack.h2
-rw-r--r--include/stc/cvec.h2
-rw-r--r--include/stc/priv/altnames.h34
16 files changed, 26 insertions, 285 deletions
diff --git a/include/stc/algo/crange.h b/include/stc/algo/crange.h
index ca06c258..56c317da 100644
--- a/include/stc/algo/crange.h
+++ b/include/stc/algo/crange.h
@@ -63,10 +63,10 @@ STC_INLINE crange crange_make_3(crange_value start, crange_value stop, crange_va
STC_INLINE crange_iter crange_begin(crange* self)
{ self->value = self->start; crange_iter it = {&self->value, self->end, self->step}; return it; }
-STC_INLINE crange_iter crange_end(crange* self)
+STC_INLINE crange_iter crange_end(crange* self)
{ crange_iter it = {NULL}; return it; }
-STC_INLINE void crange_next(crange_iter* it)
+STC_INLINE void crange_next(crange_iter* it)
{ *it->ref += it->step; if ((it->step > 0) == (*it->ref > it->end)) it->ref = NULL; }
#endif
diff --git a/include/stc/algo/csort.h b/include/stc/algo/csort.h
index 53fe9fcc..e01a2893 100644
--- a/include/stc/algo/csort.h
+++ b/include/stc/algo/csort.h
@@ -20,9 +20,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#include "../ccommon.h"
-#include "../priv/template.h"
-
/* Generic Quicksort in C, performs as fast as c++ std::sort().
template params:
#define i_val - value type [required]
@@ -44,10 +41,13 @@ int main() {
puts("");
}
*/
+#include "../ccommon.h"
+#define _i_prefix csort_
+#include "../priv/template.h"
-typedef i_val c_PASTE(c_CONCAT(csort_, i_tag), _value);
+typedef i_val _cx_value;
-static inline void c_PASTE(cisort_, i_tag)(i_val arr[], intptr_t lo, intptr_t hi) {
+static inline void _cx_memb(_insertion)(i_val arr[], intptr_t lo, intptr_t hi) {
for (intptr_t j = lo, i = lo + 1; i <= hi; j = i, ++i) {
i_val key = arr[i];
while (j >= 0 && (i_less((&key), (&arr[j])))) {
@@ -58,7 +58,7 @@ static inline void c_PASTE(cisort_, i_tag)(i_val arr[], intptr_t lo, intptr_t hi
}
}
-static inline void c_PASTE(cqsort_, i_tag)(i_val arr[], intptr_t lo, intptr_t hi) {
+static inline void _cx_memb(_quicksort)(i_val arr[], intptr_t lo, intptr_t hi) {
intptr_t i = lo, j;
while (lo < hi) {
i_val pivot = arr[lo + (hi - lo)*7/16];
@@ -77,13 +77,13 @@ static inline void c_PASTE(cqsort_, i_tag)(i_val arr[], intptr_t lo, intptr_t hi
c_swap(intptr_t, &hi, &j);
}
- if (j - lo > 64) c_PASTE(cqsort_, i_tag)(arr, lo, j);
- else if (j > lo) c_PASTE(cisort_, i_tag)(arr, lo, j);
+ if (j - lo > 64) _cx_memb(_quicksort)(arr, lo, j);
+ else if (j > lo) _cx_memb(_insertion)(arr, lo, j);
lo = i;
}
}
-static inline void c_PASTE(csort_, i_tag)(i_val arr[], intptr_t n)
- { c_PASTE(cqsort_, i_tag)(arr, 0, n - 1); }
+static inline void _cx_self(i_val arr[], intptr_t n)
+ { _cx_memb(_quicksort)(arr, 0, n - 1); }
#include "../priv/template2.h"
diff --git a/include/stc/carc.h b/include/stc/carc.h
index 8ef80b12..74205caf 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -74,9 +74,7 @@ int main() {
#define carc_NULL {NULL, NULL}
#endif // CARC_H_INCLUDED
-#ifndef _i_prefix
#define _i_prefix carc_
-#endif
#ifdef i_eq
#define _i_eq
#endif
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index ca88fc66..393b904b 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -67,9 +67,7 @@ int main() {
#define cbox_NULL {NULL}
#endif // CBOX_H_INCLUDED
-#ifndef _i_prefix
#define _i_prefix cbox_
-#endif
#ifdef i_eq
#define _i_eq
#endif
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 73a3d5ef..1882646c 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -29,7 +29,6 @@
#include <stdbool.h>
#include <string.h>
#include <assert.h>
-#include "priv/altnames.h"
#include "priv/raii.h"
#define c_NPOS INTPTR_MAX
diff --git a/include/stc/clist.h b/include/stc/clist.h
index f7fb4152..65a1ac87 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -77,9 +77,7 @@
#endif // CLIST_H_INCLUDED
-#ifndef _i_prefix
#define _i_prefix clist_
-#endif
#include "priv/template.h"
#ifndef i_is_forward
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index cd8878ea..ec3238f6 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -58,17 +58,16 @@ typedef struct { intptr_t idx; uint8_t hashx, found; } chash_bucket;
#endif // CMAP_H_INCLUDED
#ifndef _i_prefix
-#define _i_prefix cmap_
-#endif
-#ifdef _i_isset
- #define _i_MAP_ONLY c_false
- #define _i_SET_ONLY c_true
- #define _i_keyref(vp) (vp)
-#else
+ #define _i_prefix cmap_
#define _i_ismap
#define _i_MAP_ONLY c_true
#define _i_SET_ONLY c_false
#define _i_keyref(vp) (&(vp)->first)
+#else
+ #define _i_isset
+ #define _i_MAP_ONLY c_false
+ #define _i_SET_ONLY c_true
+ #define _i_keyref(vp) (vp)
#endif
#include "priv/template.h"
#ifndef i_is_forward
@@ -421,11 +420,9 @@ _cx_memb(_reserve)(_cx_self* self, const intptr_t _newcap) {
const intptr_t _oldbucks = self->bucket_count;
if (_newcap != self->size && _newcap <= _oldbucks)
return true;
- intptr_t _newbucks = (intptr_t)((float)_newcap / (i_max_load_factor)) + 4;
+ intptr_t _newbucks = (intptr_t)((float)_newcap / (i_max_load_factor)) | 1;
#if i_expandby == 2
_newbucks = (intptr_t)next_power_of_2((uint64_t)_newbucks);
- #else
- _newbucks |= 1;
#endif
_cx_self m = {
(_cx_value *)i_malloc(_newbucks*c_sizeof(_cx_value)),
@@ -472,11 +469,9 @@ _cx_memb(_erase_entry)(_cx_self* self, _cx_value* _val) {
s[i].hashx = 0;
--self->size;
}
+#endif // i_implement
#undef i_max_load_factor
#undef i_expandby
-#elif defined i_max_load_factor || defined i_expandby
-#error i_max_load_factor and i_expandby may only be defined for the implementation.
-#endif // i_implement
#undef _i_isset
#undef _i_ismap
#undef _i_keyref
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index b95b5020..c76621cd 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -27,10 +27,7 @@
#include "forward.h"
#endif
-#ifndef _i_prefix
#define _i_prefix cpque_
-#endif
-
#include "priv/template.h"
#ifndef i_is_forward
_cx_deftypes(_c_cpque_types, _cx_self, i_key);
diff --git a/include/stc/cqueue.h b/include/stc/cqueue.h
index 1934305a..254bc834 100644
--- a/include/stc/cqueue.h
+++ b/include/stc/cqueue.h
@@ -53,9 +53,7 @@ int main() {
}
*/
-#ifndef _i_prefix
#define _i_prefix cqueue_
-#endif
#define _i_queue
#define _pop_front _pop
diff --git a/include/stc/crandom.h b/include/stc/crandom.h
deleted file mode 100644
index a9374602..00000000
--- a/include/stc/crandom.h
+++ /dev/null
@@ -1,197 +0,0 @@
-/* MIT License
- *
- * Copyright (c) 2023 Tyge Løvset
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-#include "ccommon.h"
-
-#ifndef CRANDOM_H_INCLUDED
-#define CRANDOM_H_INCLUDED
-/*
-// crandom: Pseudo-random number generator
-#include "stc/crandom.h"
-int main() {
- uint64_t seed = 123456789;
- stc64_t rng = stc64_new(seed);
- stc64_uniform_t dist1 = stc64_uniform_new(1, 6);
- stc64_uniformf_t dist2 = stc64_uniformf_new(1.0, 10.0);
- stc64_normalf_t dist3 = stc64_normalf_new(1.0, 10.0);
-
- uint64_t i = stc64_rand(&rng);
- int64_t iu = stc64_uniform(&rng, &dist1);
- double xu = stc64_uniformf(&rng, &dist2);
- double xn = stc64_normalf(&rng, &dist3);
-}
-*/
-#include <string.h>
-#include <math.h>
-
-typedef struct stc64 { uint64_t state[5]; } stc64_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; int 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
- * 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
- * PractRand to multiple TB input.
- */
-
-/* Global stc64 PRNGs */
-STC_API void csrandom(uint64_t seed);
-STC_API uint64_t crandom(void);
-STC_API double crandomf(void);
-
-/* Init stc64 prng with and without sequence number */
-STC_API stc64_t stc64_with_seq(uint64_t seed, uint64_t seq);
-STC_INLINE stc64_t stc64_new(uint64_t seed)
- { return stc64_with_seq(seed, seed + 0x3504f333d3aa0b37); }
-
-/* Unbiased bounded uniform distribution. range [low, high] */
-STC_API stc64_uniform_t stc64_uniform_new(int64_t low, int64_t high);
-STC_API int64_t stc64_uniform(stc64_t* rng, stc64_uniform_t* dist);
-
-/* Normal distribution PRNG */
-STC_API double stc64_normalf(stc64_t* rng, stc64_normalf_t* dist);
-
-
-/* Main stc64 prng */
-STC_INLINE uint64_t stc64_rand(stc64_t* rng) {
- uint64_t *s = rng->state; enum {LR=24, RS=11, LS=3};
- const uint64_t result = (s[0] ^ (s[3] += s[4])) + s[1];
- s[0] = s[1] ^ (s[1] >> RS);
- s[1] = s[2] + (s[2] << LS);
- s[2] = ((s[2] << LR) | (s[2] >> (64 - LR))) + result;
- return result;
-}
-
-/* Float64 random number in range [0.0, 1.0). */
-STC_INLINE double stc64_randf(stc64_t* rng) {
- union {uint64_t i; double f;} u = {0x3FF0000000000000ull | (stc64_rand(rng) >> 12)};
- return u.f - 1.0;
-}
-
-/* Float64 uniform distributed RNG, range [low, high). */
-STC_INLINE double stc64_uniformf(stc64_t* rng, stc64_uniformf_t* dist) {
- return stc64_randf(rng)*dist->range + dist->lower;
-}
-
-/* Init uniform distributed float64 RNG, range [low, high). */
-STC_INLINE stc64_uniformf_t stc64_uniformf_new(double low, double high) {
- return c_LITERAL(stc64_uniformf_t){low, high - low};
-}
-
-/* Marsaglia polar method for gaussian/normal distribution, float64. */
-STC_INLINE stc64_normalf_t stc64_normalf_new(double mean, double stddev) {
- return c_LITERAL(stc64_normalf_t){mean, stddev, 0.0, 0};
-}
-
-/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_implement)
-
-/* Global random() */
-static stc64_t stc64_global = {{
- 0x26aa069ea2fb1a4d, 0x70c72c95cd592d04,
- 0x504f333d3aa0b359, 0x9e3779b97f4a7c15,
- 0x6a09e667a754166b
-}};
-
-STC_DEF void csrandom(uint64_t seed) {
- stc64_global = stc64_new(seed);
-}
-
-STC_DEF uint64_t crandom(void) {
- return stc64_rand(&stc64_global);
-}
-
-STC_DEF double crandomf(void) {
- return stc64_randf(&stc64_global);
-}
-
-/* rng.state[4] must be odd */
-STC_DEF stc64_t stc64_with_seq(uint64_t seed, uint64_t seq) {
- stc64_t rng = {{seed+0x26aa069ea2fb1a4d, seed+0x70c72c95cd592d04,
- seed+0x504f333d3aa0b359, seed, seq<<1 | 1}};
- for (int i = 0; i < 6; ++i) stc64_rand(&rng);
- return rng;
-}
-
-/* Init unbiased uniform uint RNG with bounds [low, high] */
-STC_DEF stc64_uniform_t stc64_uniform_new(int64_t low, int64_t high) {
- stc64_uniform_t dist = {low, (uint64_t) (high - low + 1)};
- dist.threshold = (uint64_t)(0 - dist.range) % dist.range;
- return dist;
-}
-
-#if defined(__SIZEOF_INT128__)
- #define c_umul128(a, b, lo, hi) \
- do { __uint128_t _z = (__uint128_t)(a)*(b); \
- *(lo) = (uint64_t)_z, *(hi) = (uint64_t)(_z >> 64U); } while(0)
-#elif defined(_MSC_VER) && defined(_WIN64)
- #include <intrin.h>
- #define c_umul128(a, b, lo, hi) ((void)(*(lo) = _umul128(a, b, hi)))
-#elif defined(__x86_64__)
- #define c_umul128(a, b, lo, hi) \
- asm("mulq %3" : "=a"(*(lo)), "=d"(*(hi)) : "a"(a), "rm"(b))
-#endif
-
-/* Int uniform distributed RNG, range [low, high]. */
-STC_DEF 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 + (int64_t)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
-}
-
-/* Normal distribution PRNG */
-STC_DEF double stc64_normalf(stc64_t* rng, stc64_normalf_t* dist) {
- double u1, u2, s, m;
- if (dist->has_next++ & 1)
- return dist->next * dist->stddev + dist->mean;
- do {
- u1 = 2.0 * stc64_randf(rng) - 1.0;
- u2 = 2.0 * stc64_randf(rng) - 1.0;
- s = u1*u1 + u2*u2;
- } while (s >= 1.0 || s == 0.0);
- m = sqrt(-2.0 * log(s) / s);
- dist->next = u2 * m;
- return (u1 * m) * dist->stddev + dist->mean;
-}
-
-#endif
-#endif
-#undef i_opt
-#undef i_static
-#undef i_header
-#undef i_implement
-#undef i_extern
diff --git a/include/stc/cset.h b/include/stc/cset.h
index 58cbeb3e..c89a144d 100644
--- a/include/stc/cset.h
+++ b/include/stc/cset.h
@@ -39,8 +39,5 @@ int main(void) {
}
*/
-#ifndef _i_prefix
#define _i_prefix cset_
-#endif
-#define _i_isset
#include "cmap.h"
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index cd7c1d95..6b8475eb 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -58,17 +58,16 @@ int main(void) {
#endif // CSMAP_H_INCLUDED
#ifndef _i_prefix
-#define _i_prefix csmap_
-#endif
-#ifdef _i_isset
- #define _i_MAP_ONLY c_false
- #define _i_SET_ONLY c_true
- #define _i_keyref(vp) (vp)
-#else
+ #define _i_prefix csmap_
#define _i_ismap
#define _i_MAP_ONLY c_true
#define _i_SET_ONLY c_false
#define _i_keyref(vp) (&(vp)->first)
+#else
+ #define _i_isset
+ #define _i_MAP_ONLY c_false
+ #define _i_SET_ONLY c_true
+ #define _i_keyref(vp) (vp)
#endif
#include "priv/template.h"
#ifndef i_is_forward
diff --git a/include/stc/csset.h b/include/stc/csset.h
index c14d2a6a..29810c7c 100644
--- a/include/stc/csset.h
+++ b/include/stc/csset.h
@@ -42,8 +42,5 @@ int main(void) {
}
*/
-#ifndef _i_prefix
#define _i_prefix csset_
-#endif
-#define _i_isset
#include "csmap.h"
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index c2792358..87ef9405 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -28,9 +28,7 @@
#include "forward.h"
#endif // CSTACK_H_INCLUDED
-#ifndef _i_prefix
#define _i_prefix cstack_
-#endif
#include "priv/template.h"
#ifndef i_is_forward
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index a1aa74b2..3cbd90b7 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -68,9 +68,7 @@ int main() {
#define _it_ptr(it) (it.ref ? it.ref : it.end)
#endif // CVEC_H_INCLUDED
-#ifndef _i_prefix
#define _i_prefix cvec_
-#endif
#include "priv/template.h"
#ifndef i_is_forward
diff --git a/include/stc/priv/altnames.h b/include/stc/priv/altnames.h
deleted file mode 100644
index 723b6a66..00000000
--- a/include/stc/priv/altnames.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* MIT License
- *
- * Copyright (c) 2023 Tyge Løvset
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-#define c_FORLIST c_forlist
-#define c_FORRANGE c_forrange
-#define c_FOREACH c_foreach
-#define c_FORPAIR c_forpair
-#define c_FORFILTER c_forfilter
-#define c_FORMATCH c_formatch
-#define c_FORTOKEN c_fortoken
-#define c_FORTOKEN_SV c_fortoken_sv
-#define c_AUTO c_auto
-#define c_WITH c_with
-#define c_SCOPE c_scope
-#define c_DEFER c_defer