diff options
| author | Tyge Lovset <[email protected]> | 2023-02-01 08:38:45 +0100 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2023-02-01 08:38:45 +0100 |
| commit | 6ce6ef3307e52db5813d3c8d6a2cba52df06daf8 (patch) | |
| tree | 25af4be9fcd5e72778715b83ff312e157ca63b59 | |
| parent | b677a0c3950b8294ba6458e682a885351273ac08 (diff) | |
| download | STC-modified-6ce6ef3307e52db5813d3c8d6a2cba52df06daf8.tar.gz STC-modified-6ce6ef3307e52db5813d3c8d6a2cba52df06daf8.zip | |
Massive update from unsigned sizes and indices to signed.
58 files changed, 313 insertions, 320 deletions
@@ -112,7 +112,7 @@ int main(void) FVec_push_back(&vec, 20.f); FVec_push_back(&vec, 30.f); - for (size_t i = 0; i < FVec_size(vec); ++i) + for (intptr_t i = 0; i < FVec_size(vec); ++i) printf(" %g", vec.data[i]); FVec_drop(&vec); // cleanup memory diff --git a/docs/cbits_api.md b/docs/cbits_api.md index b21611df..726fb68b 100644 --- a/docs/cbits_api.md +++ b/docs/cbits_api.md @@ -21,34 +21,34 @@ All cbits definitions and prototypes are available by including a single header ```c cbits cbits_init(void); cbits cbits_from(const char* str); -cbits cbits_with_size(size_t size, bool value); // size must be <= N if N is defined -cbits cbits_with_pattern(size_t size, uint64_t pattern); +cbits cbits_with_size(intptr_t size, bool value); // size must be <= N if N is defined +cbits cbits_with_pattern(intptr_t size, uint64_t pattern); cbits cbits_clone(cbits other); void cbits_clear(cbits* self); cbits* cbits_copy(cbits* self, const cbits* other); -void cbits_resize(cbits* self, size_t size, bool value); // only if i_len is not defined +void cbits_resize(cbits* self, intptr_t size, bool value); // only if i_len is not defined void cbits_drop(cbits* self); cbits* cbits_take(cbits* self, const cbits* other); // give other to self cbits cbits_move(cbits* self); // transfer self to caller -size_t cbits_size(const cbits* self); -size_t cbits_count(const cbits* self); // count number of bits set +intptr_t cbits_size(const cbits* self); +intptr_t cbits_count(const cbits* self); // count number of bits set -bool cbits_test(const cbits* self, size_t i); -bool cbits_at(const cbits* self, size_t i); // same as cbits_test() +bool cbits_test(const cbits* self, intptr_t i); +bool cbits_at(const cbits* self, intptr_t i); // same as cbits_test() bool cbits_subset_of(const cbits* self, const cbits* other); // is set a subset of other? bool cbits_disjoint(const cbits* self, const cbits* other); // no common bits -char* cbits_to_str(const cbits* self, char* str, size_t start, size_t stop); +char* cbits_to_str(const cbits* self, char* str, intptr_t start, intptr_t stop); -void cbits_set(cbits* self, size_t i); -void cbits_reset(cbits* self, size_t i); -void cbits_set_value(cbits* self, size_t i, bool value); +void cbits_set(cbits* self, intptr_t i); +void cbits_reset(cbits* self, intptr_t i); +void cbits_set_value(cbits* self, intptr_t i, bool value); void cbits_set_all(cbits* self, bool value); void cbits_set_pattern(cbits* self, uint64_t pattern); void cbits_flip_all(cbits* self); -void cbits_flip(cbits* self, size_t i); +void cbits_flip(cbits* self, intptr_t i); void cbits_intersect(cbits* self, const cbits* other); void cbits_union(cbits* self, const cbits* other); @@ -70,19 +70,19 @@ void cbits_xor(cbits* self, const cbits* other); // set #include <math.h> #include <time.h> -cbits sieveOfEratosthenes(size_t n) +cbits sieveOfEratosthenes(intptr_t n) { cbits bits = cbits_with_size(n>>1, true); - size_t q = (size_t) sqrt(n); + intptr_t q = (intptr_t) sqrt(n); - for (size_t i = 3; i <= q; i += 2) { - for (size_t j = i; j < n; j += 2) { + for (intptr_t i = 3; i <= q; i += 2) { + for (intptr_t j = i; j < n; j += 2) { if (cbits_test(&bits, j>>1)) { i = j; break; } } - for (size_t j = i*i; j < n; j += i*2) + for (intptr_t j = i*i; j < n; j += i*2) cbits_reset(&bits, j>>1); } return bits; @@ -90,19 +90,19 @@ cbits sieveOfEratosthenes(size_t n) int main(void) { - size_t n = 100000000; - printf("computing prime numbers up to %" c_ZU "\n", n); + intptr_t n = 100000000; + printf("computing prime numbers up to %" c_ZI "\n", n); clock_t t1 = clock(); cbits primes = sieveOfEratosthenes(n + 1); - size_t nprimes = cbits_count(&primes); + intptr_t nprimes = cbits_count(&primes); clock_t t2 = clock(); - printf("number of primes: %" c_ZU ", time: %f\n", nprimes, (float)(t2 - t1)/CLOCKS_PER_SEC); + printf("number of primes: %" c_ZI ", time: %f\n", nprimes, (float)(t2 - t1)/CLOCKS_PER_SEC); printf(" 2"); - for (size_t i = 3; i < 1000; i += 2) - if (cbits_test(&primes, i>>1)) printf(" %" c_ZU, i); + for (intptr_t i = 3; i < 1000; i += 2) + if (cbits_test(&primes, i>>1)) printf(" %" c_ZI, i); puts(""); cbits_drop(&primes); diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index 18edbeba..43f747ab 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -361,5 +361,5 @@ Memory allocator for the entire library. Macros can be overridden by the user. - **c_ARRAYLEN(array)**: Return number of elements in an array. array must not be a pointer! ```c int array[] = {1, 2, 3, 4}; -size_t n = c_ARRAYLEN(array); +intptr_t n = c_ARRAYLEN(array); ``` diff --git a/docs/cdeq_api.md b/docs/cdeq_api.md index 584d382f..44a75fc2 100644 --- a/docs/cdeq_api.md +++ b/docs/cdeq_api.md @@ -27,21 +27,21 @@ See the c++ class [std::deque](https://en.cppreference.com/w/cpp/container/deque ```c cdeq_X cdeq_X_init(void); -cdeq_X cdeq_X_with_capacity(size_t size); +cdeq_X cdeq_X_with_capacity(intptr_t size); cdeq_X cdeq_X_clone(cdeq_X deq); void cdeq_X_clear(cdeq_X* self); void cdeq_X_copy(cdeq_X* self, const cdeq_X* other); cdeq_X_iter cdeq_X_copy_range(cdeq_X* self, i_val* pos, const i_val* p1, const i_val* p2); -bool cdeq_X_reserve(cdeq_X* self, size_t cap); +bool cdeq_X_reserve(cdeq_X* self, intptr_t cap); void cdeq_X_shrink_to_fit(cdeq_X* self); void cdeq_X_drop(cdeq_X* self); // destructor bool cdeq_X_empty(const cdeq_X* self); -size_t cdeq_X_size(const cdeq_X* self); -size_t cdeq_X_capacity(const cdeq_X* self); +intptr_t cdeq_X_size(const cdeq_X* self); +intptr_t cdeq_X_capacity(const cdeq_X* self); -const cdeq_X_value* cdeq_X_at(const cdeq_X* self, size_t idx); +const cdeq_X_value* cdeq_X_at(const cdeq_X* self, intptr_t idx); const cdeq_X_value* cdeq_X_get(const cdeq_X* self, i_valraw raw); // return NULL if not found cdeq_X_value* cdeq_X_get_mut(cdeq_X* self, i_valraw raw); // mutable get cdeq_X_iter cdeq_X_find(const cdeq_X* self, i_valraw raw); @@ -60,18 +60,18 @@ cdeq_X_value* cdeq_X_emplace_back(cdeq_X* self, i_valraw raw); cdeq_X_value* cdeq_X_emplace(cdeq_X* self, i_valraw raw); // alias for emplace_back() void cdeq_X_pop_back(cdeq_X* self); -cdeq_X_iter cdeq_X_insert(cdeq_X* self, size_t idx, i_val value); // move value -cdeq_X_iter cdeq_X_insert_n(cdeq_X* self, size_t idx, const i_val[] arr, size_t n); // move arr values +cdeq_X_iter cdeq_X_insert(cdeq_X* self, intptr_t idx, i_val value); // move value +cdeq_X_iter cdeq_X_insert_n(cdeq_X* self, intptr_t idx, const i_val[] arr, intptr_t n); // move arr values cdeq_X_iter cdeq_X_insert_at(cdeq_X* self, cdeq_X_iter it, i_val value); // move value cdeq_X_iter cdeq_X_insert_range(cdeq_X* self, i_val* pos, const i_val* p1, const i_val* p2); -cdeq_X_iter cdeq_X_emplace_n(cdeq_X* self, size_t idx, const i_valraw[] arr, size_t n); // clone values +cdeq_X_iter cdeq_X_emplace_n(cdeq_X* self, intptr_t idx, const i_valraw[] arr, intptr_t n); // clone values cdeq_X_iter cdeq_X_emplace_at(cdeq_X* self, cdeq_X_iter it, i_valraw raw); cdeq_X_iter cdeq_X_emplace_range(cdeq_X* self, i_val* pos, const i_valraw* p1, const i_valraw* p2); -cdeq_X_iter cdeq_X_erase_n(cdeq_X* self, size_t idx, size_t n); +cdeq_X_iter cdeq_X_erase_n(cdeq_X* self, intptr_t idx, intptr_t n); cdeq_X_iter cdeq_X_erase_at(cdeq_X* self, cdeq_X_iter it); cdeq_X_iter cdeq_X_erase_range(cdeq_X* self, cdeq_X_iter it1, cdeq_X_iter it2); cdeq_X_iter cdeq_X_erase_range_p(cdeq_X* self, i_val* p1, i_val* p2); @@ -83,7 +83,7 @@ void cdeq_X_sort_range(cdeq_X_iter i1, cdeq_X_iter i2, cdeq_X_iter cdeq_X_begin(const cdeq_X* self); cdeq_X_iter cdeq_X_end(const cdeq_X* self); void cdeq_X_next(cdeq_X_iter* it); -cdeq_X_iter cdeq_X_advance(cdeq_X_iter it, intptr_t n); +cdeq_X_iter cdeq_X_advance(cdeq_X_iter it, size_t n); cdeq_X_raw cdeq_X_value_toraw(cdeq_X_value* pval); cdeq_X_value cdeq_X_value_clone(cdeq_X_value val); diff --git a/docs/clist_api.md b/docs/clist_api.md index e97d7b5d..13c27308 100644 --- a/docs/clist_api.md +++ b/docs/clist_api.md @@ -48,7 +48,7 @@ void clist_X_copy(clist_X* self, const clist_X* other); void clist_X_drop(clist_X* self); // destructor bool clist_X_empty(const clist_X* list); -size_t clist_X_count(const clist_X* list); // size() in O(n) time +intptr_t clist_X_count(const clist_X* list); // size() in O(n) time clist_X_value* clist_X_back(const clist_X* self); clist_X_value* clist_X_front(const clist_X* self); @@ -67,7 +67,7 @@ clist_X_iter clist_X_emplace_at(clist_X* self, clist_X_iter it, i_valraw void clist_X_pop_front(clist_X* self); clist_X_iter clist_X_erase_at(clist_X* self, clist_X_iter it); // return iter after it clist_X_iter clist_X_erase_range(clist_X* self, clist_X_iter it1, clist_X_iter it2); -size_t clist_X_remove(clist_X* self, i_valraw raw); // removes all matches +intptr_t clist_X_remove(clist_X* self, i_valraw raw); // removes all matches clist_X clist_X_split_off(clist_X* self, clist_X_iter i1, clist_X_iter i2); // split off [i1, i2) clist_X_iter clist_X_splice(clist_X* self, clist_X_iter it, clist_X* other); // return updated valid it diff --git a/docs/cmap_api.md b/docs/cmap_api.md index 3848e67e..7b8fbb8f 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -48,20 +48,20 @@ See the c++ class [std::unordered_map](https://en.cppreference.com/w/cpp/contain ```c cmap_X cmap_X_init(void); -cmap_X cmap_X_with_capacity(size_t cap); +cmap_X cmap_X_with_capacity(intptr_t cap); cmap_X cmap_X_clone(cmap_x map); void cmap_X_clear(cmap_X* self); void cmap_X_copy(cmap_X* self, const cmap_X* other); -float cmap_X_max_load_factor(const cmap_X* self); // default: 0.85f -bool cmap_X_reserve(cmap_X* self, size_t size); +float cmap_X_max_load_factor(const cmap_X* self); // default: 0.85f +bool cmap_X_reserve(cmap_X* self, intptr_t size); void cmap_X_shrink_to_fit(cmap_X* self); void cmap_X_drop(cmap_X* self); // destructor -size_t cmap_X_size(const cmap_X* self); -size_t cmap_X_capacity(const cmap_X* self); // buckets * max_load_factor +intptr_t cmap_X_size(const cmap_X* self); +intptr_t cmap_X_capacity(const cmap_X* self); // buckets * max_load_factor bool cmap_X_empty(const cmap_X* self ); -size_t cmap_X_bucket_count(const cmap_X* self); // num. of allocated buckets +intptr_t cmap_X_bucket_count(const cmap_X* self); // num. of allocated buckets const cmap_X_mapped* cmap_X_at(const cmap_X* self, i_keyraw rkey); // rkey must be in map cmap_X_mapped* cmap_X_at_mut(cmap_X* self, i_keyraw rkey); // mutable at @@ -77,7 +77,7 @@ cmap_X_result cmap_X_push(cmap_X* self, cmap_X_value entry); cmap_X_result cmap_X_emplace(cmap_X* self, i_keyraw rkey, i_valraw rmapped); // no change if rkey in map cmap_X_result cmap_X_emplace_or_assign(cmap_X* self, i_keyraw rkey, i_valraw rmapped); // always update rmapped -size_t cmap_X_erase(cmap_X* self, i_keyraw rkey); // return 0 or 1 +intptr_t cmap_X_erase(cmap_X* self, i_keyraw rkey); // return 0 or 1 cmap_X_iter cmap_X_erase_at(cmap_X* self, cmap_X_iter it); // return iter after it void cmap_X_erase_entry(cmap_X* self, cmap_X_value* entry); @@ -93,7 +93,7 @@ Helpers: ```c uint64_t c_default_hash(const X *obj); // macro, calls cfasthash(obj, sizeof *obj) uint64_t cstrhash(const char *str); // string hash funcion, uses strlen() -uint64_t cfasthash(const void *data, size_t len); // base hash function +uint64_t cfasthash(const void *data, intptr_t len); // base hash function // equalto template parameter functions: bool c_default_eq(const i_keyraw* a, const i_keyraw* b); // *a == *b diff --git a/docs/cpque_api.md b/docs/cpque_api.md index 392d3149..48a5b29e 100644 --- a/docs/cpque_api.md +++ b/docs/cpque_api.md @@ -28,17 +28,17 @@ See the c++ class [std::priority_queue](https://en.cppreference.com/w/cpp/contai ```c cpque_X cpque_X_init(void); // create empty pri-queue. -cpque_X cpque_X_with_capacity(size_t cap); -cpque_X cpque_X_with_size(size_t size, i_val null); +cpque_X cpque_X_with_capacity(intptr_t cap); +cpque_X cpque_X_with_size(intptr_t size, i_val null); cpque_X cpque_X_clone(cpque_X pq); void cpque_X_clear(cpque_X* self); -bool cpque_X_reserve(cpque_X* self, size_t n); +bool cpque_X_reserve(cpque_X* self, intptr_t n); void cpque_X_shrink_to_fit(cpque_X* self); void cpque_X_copy(cpque_X* self, const cpque_X* other); void cpque_X_drop(cpque_X* self); // destructor -size_t cpque_X_size(const cpque_X* self); +intptr_t cpque_X_size(const cpque_X* self); bool cpque_X_empty(const cpque_X* self); i_val* cpque_X_top(const cpque_X* self); @@ -47,7 +47,7 @@ void cpque_X_push(cpque_X* self, i_val value); void cpque_X_emplace(cpque_X* self, i_valraw raw); // converts from raw void cpque_X_pop(cpque_X* self); -void cpque_X_erase_at(cpque_X* self, size_t idx); +void cpque_X_erase_at(cpque_X* self, intptr_t idx); i_val cpque_X_value_clone(i_val value); ``` @@ -71,7 +71,7 @@ i_val cpque_X_value_clone(i_val value); int main() { - size_t N = 10000000; + intptr_t N = 10000000; stc64_t rng = stc64_new(1234); stc64_uniform_t dist = stc64_uniform_new(0, N * 10); diff --git a/docs/cqueue_api.md b/docs/cqueue_api.md index 977fa855..212cdabe 100644 --- a/docs/cqueue_api.md +++ b/docs/cqueue_api.md @@ -32,7 +32,7 @@ void cqueue_X_clear(cqueue_X* self); void cqueue_X_copy(cqueue_X* self, const cqueue_X* other); void cqueue_X_drop(cqueue_X* self); // destructor -size_t cqueue_X_size(const cqueue_X* self); +intptr_t cqueue_X_size(const cqueue_X* self); bool cqueue_X_empty(const cqueue_X* self); cqueue_X_value* cqueue_X_front(const cqueue_X* self); cqueue_X_value* cqueue_X_back(const cqueue_X* self); diff --git a/docs/crandom_api.md b/docs/crandom_api.md index bd3bf848..7dced0eb 100644 --- a/docs/crandom_api.md +++ b/docs/crandom_api.md @@ -76,7 +76,7 @@ double stc64_normalf(stc64_t* rng, stc64_normalf_t* dist); // Declare int -> int sorted map. Uses typetag 'i' for ints. #define i_key int -#define i_val size_t +#define i_val intptr_t #define i_tag i #include <stc/csmap.h> @@ -102,7 +102,7 @@ int main() // Print the gaussian bar chart cstr bar = cstr_init(); c_FOREACH (i, csmap_i, mhist) { - size_t n = (size_t) (i.ref->second * StdDev * Scale * 2.5 / N); + int n = (int)(i.ref->second * StdDev * Scale * 2.5 / N); if (n > 0) { cstr_resize(&bar, n, '*'); printf("%4d %s\n", i.ref->first, cstr_str(&bar)); diff --git a/docs/cset_api.md b/docs/cset_api.md index e1d08a87..2e80a49b 100644 --- a/docs/cset_api.md +++ b/docs/cset_api.md @@ -30,20 +30,20 @@ A **cset** is an associative container that contains a set of unique objects of ```c cset_X cset_X_init(void); -cset_X cset_X_with_capacity(size_t cap); +cset_X cset_X_with_capacity(intptr_t cap); cset_X cset_X_clone(cset_x set); void cset_X_clear(cset_X* self); void cset_X_copy(cset_X* self, const cset_X* other); float cset_X_max_load_factor(const cset_X* self); // default: 0.85 -bool cset_X_reserve(cset_X* self, size_t size); +bool cset_X_reserve(cset_X* self, intptr_t size); void cset_X_shrink_to_fit(cset_X* self); void cset_X_drop(cset_X* self); // destructor -size_t cset_X_size(const cset_X* self); // num. of allocated buckets -size_t cset_X_capacity(const cset_X* self); // buckets * max_load_factor +intptr_t cset_X_size(const cset_X* self); // num. of allocated buckets +intptr_t cset_X_capacity(const cset_X* self); // buckets * max_load_factor bool cset_X_empty(const cset_X* self); -size_t cset_X_bucket_count(const cset_X* self); +intptr_t cset_X_bucket_count(const cset_X* self); bool cset_X_contains(const cset_X* self, i_keyraw rkey); const cset_X_value* cset_X_get(const cset_X* self, i_keyraw rkey); // return NULL if not found @@ -54,7 +54,7 @@ cset_X_result cset_X_insert(cset_X* self, i_key key); cset_X_result cset_X_push(cset_X* self, i_key key); // alias for insert. cset_X_result cset_X_emplace(cset_X* self, i_keyraw rkey); -size_t cset_X_erase(cset_X* self, i_keyraw rkey); // return 0 or 1 +intptr_t cset_X_erase(cset_X* self, i_keyraw rkey); // return 0 or 1 cset_X_iter cset_X_erase_at(cset_X* self, cset_X_iter it); // return iter after it void cset_X_erase_entry(cset_X* self, cset_X_value* entry); diff --git a/docs/csmap_api.md b/docs/csmap_api.md index 687a6cab..d0a57bdb 100644 --- a/docs/csmap_api.md +++ b/docs/csmap_api.md @@ -42,8 +42,8 @@ See the c++ class [std::map](https://en.cppreference.com/w/cpp/container/map) fo ```c csmap_X csmap_X_init(void); -csset_X csmap_X_with_capacity(size_t cap); -bool csmap_X_reserve(csmap_X* self, size_t cap); +csset_X csmap_X_with_capacity(intptr_t cap); +bool csmap_X_reserve(csmap_X* self, intptr_t cap); void csmap_X_shrink_to_fit(csmap_X* self); csmap_X csmap_X_clone(csmap_x map); @@ -51,7 +51,7 @@ void csmap_X_clear(csmap_X* self); void csmap_X_copy(csmap_X* self, const csmap_X* other); void csmap_X_drop(csmap_X* self); // destructor -size_t csmap_X_size(const csmap_X* self); +intptr_t csmap_X_size(const csmap_X* self); bool csmap_X_empty(const csmap_X* self); bool csmap_X_capacity(const csmap_X* self); @@ -74,7 +74,7 @@ csmap_X_result csmap_X_push(csmap_X* self, csmap_X_value entry); csmap_X_result csmap_X_emplace(csmap_X* self, i_keyraw rkey, i_valraw rmapped); // no change if rkey in map csmap_X_result csmap_X_emplace_or_assign(csmap_X* self, i_keyraw rkey, i_valraw rmapped); // always update rmapped -size_t csmap_X_erase(csmap_X* self, i_keyraw rkey); +intptr_t csmap_X_erase(csmap_X* self, i_keyraw rkey); csmap_X_iter csmap_X_erase_at(csmap_X* self, csmap_X_iter it); // returns iter after it csmap_X_iter csmap_X_erase_range(csmap_X* self, csmap_X_iter it1, csmap_X_iter it2); // returns updated it2 diff --git a/docs/cspan_api.md b/docs/cspan_api.md index c4cb7c16..8f6f695f 100644 --- a/docs/cspan_api.md +++ b/docs/cspan_api.md @@ -20,32 +20,32 @@ using_cspan4(S, ValueType); // define span types S, S2, S3, S4 with Note that `cspan_md()`, `cmake_from*()`, `cspan_atN()`, `and cspan_subspanN()` require a (safe) cast to its span-type on assignment, but not on initialization of a span variable. All functions are type-safe, and arguments are side-effect safe, except for SpanType arg. which must not have side-effects. ```c -SpanTypeN cspan_md(ValueType* data, size_t xdim, ...); // create a multi-dimensional cspan +SpanTypeN cspan_md(ValueType* data, intptr_t xdim, ...); // create a multi-dimensional cspan SpanType cspan_make(T SpanType, {v1, v2, ...}); // make a 1d-dimensional cspan from values SpanType cspan_from(STCContainer* cnt); // create a 1d cspan from a compatible STC container SpanType cspan_from_array(ValueType array[]); // create a 1d cspan from a C array -size_t cspan_size(const SpanTypeN* self); // return number of elements +intptr_t cspan_size(const SpanTypeN* self); // return number of elements unsigned cspan_rank(const SpanTypeN* self); // return number of dimensions -size_t cspan_index(const SpanTypeN* self, size_t x, ...); // index of element +intptr_t cspan_index(const SpanTypeN* self, intptr_t x, ...); // index of element -ValueType* cspan_at(SpanTypeN* self, size_t x, ...); // at(): num of args specifies rank of input span. +ValueType* cspan_at(SpanTypeN* self, intptr_t x, ...); // at(): num of args specifies rank of input span. ValueType* cspan_front(SpanTypeN* self); ValueType* cspan_back(SpanTypeN* self); // return a subspan of lower rank: -SpanType cspan_submd2(SpanType2* self, size_t x); // return a 1d subspan from a 2d span. -SpanTypeN cspan_submd3(SpanType3* self, size_t x, ...); // return a 1d or 2d subspan from a 3d span. -SpanTypeN cspan_submd4(SpanType4* self, size_t x, ...); // number of args determines rank of output span. +SpanType cspan_submd2(SpanType2* self, intptr_t x); // return a 1d subspan from a 2d span. +SpanTypeN cspan_submd3(SpanType3* self, intptr_t x, ...); // return a 1d or 2d subspan from a 3d span. +SpanTypeN cspan_submd4(SpanType4* self, intptr_t x, ...); // number of args determines rank of output span. // return a sliced span of same rank: void cspan_slice(SpanTypeN* self, {x0,x1}, {y0,y1},...); // slice multidim span into a md subspan. // return a subspan of same rank. Like e.g. cspan_slice(&ms3, {offset, offset+count}, {0}, {0}); -SpanType cspan_subspan(const SpanType* self, size_t offset, size_t count); -SpanType2 cspan_subspan2(const SpanType2 self, size_t offset, size_t count); -SpanType3 cspan_subspan3(const SpanType3 self, size_t offset, size_t count); -SpanType4 cspan_subspan4(const SpanType4 self, size_t offset, size_t count); +SpanType cspan_subspan(const SpanType* self, intptr_t offset, intptr_t count); +SpanType2 cspan_subspan2(const SpanType2 self, intptr_t offset, intptr_t count); +SpanType3 cspan_subspan3(const SpanType3 self, intptr_t offset, intptr_t count); +SpanType4 cspan_subspan4(const SpanType4 self, intptr_t offset, intptr_t count); SpanTypeN_iter SpanType_begin(const SpanTypeN* self); SpanTypeN_iter SpanType_end(const SpanTypeN* self); diff --git a/docs/csset_api.md b/docs/csset_api.md index 6276f486..7e068909 100644 --- a/docs/csset_api.md +++ b/docs/csset_api.md @@ -28,8 +28,8 @@ See the c++ class [std::set](https://en.cppreference.com/w/cpp/container/set) fo ```c csset_X csset_X_init(void); -csset_X csset_X_with_capacity(size_t cap); -bool csset_X_reserve(csset_X* self, size_t cap); +csset_X csset_X_with_capacity(intptr_t cap); +bool csset_X_reserve(csset_X* self, intptr_t cap); void csset_X_shrink_to_fit(csset_X* self); csset_X csset_X_clone(csset_x set); @@ -37,7 +37,7 @@ void csset_X_clear(csset_X* self); void csset_X_copy(csset_X* self, const csset_X* other); void csset_X_drop(csset_X* self); // destructor -size_t csset_X_size(const csset_X* self); +intptr_t csset_X_size(const csset_X* self); bool csset_X_empty(const csset_X* self); const csset_X_value* csset_X_get(const csset_X* self, i_keyraw rkey); // const get @@ -51,7 +51,7 @@ csset_X_result csset_X_insert(csset_X* self, i_key key); csset_X_result csset_X_push(csset_X* self, i_key key); // alias for insert() csset_X_result csset_X_emplace(csset_X* self, i_keyraw rkey); -size_t csset_X_erase(csset_X* self, i_keyraw rkey); +intptr_t csset_X_erase(csset_X* self, i_keyraw rkey); csset_X_iter csset_X_erase_at(csset_X* self, csset_X_iter it); // return iter after it csset_X_iter csset_X_erase_range(csset_X* self, csset_X_iter it1, csset_X_iter it2); // return updated it2 diff --git a/docs/cstack_api.md b/docs/cstack_api.md index e8423385..b1371f4e 100644 --- a/docs/cstack_api.md +++ b/docs/cstack_api.md @@ -26,24 +26,24 @@ See the c++ class [std::stack](https://en.cppreference.com/w/cpp/container/stack ```c cstack_X cstack_X_init(void); -cstack_X cstack_X_with_capacity(size_t cap); -cstack_X cstack_X_with_size(size_t size, i_val fill); +cstack_X cstack_X_with_capacity(intptr_t cap); +cstack_X cstack_X_with_size(intptr_t size, i_val fill); 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); +bool cstack_X_reserve(cstack_X* self, intptr_t n); void cstack_X_shrink_to_fit(cstack_X* self); -i_val* cstack_X_append_uninit(cstack_X* self, size_t n); +i_val* cstack_X_append_uninit(cstack_X* self, intptr_t n); void cstack_X_copy(cstack_X* self, const cstack_X* other); void cstack_X_drop(cstack_X* self); // destructor -size_t cstack_X_size(const cstack_X* self); -size_t cstack_X_capacity(const cstack_X* self); +intptr_t cstack_X_size(const cstack_X* self); +intptr_t cstack_X_capacity(const cstack_X* self); bool cstack_X_empty(const cstack_X* self); i_val* cstack_X_top(const cstack_X* self); -const i_val* cstack_X_at(const cstack_X* self, size_t idx); -i_val* cstack_X_at_mut(cstack_X* self, size_t idx); +const i_val* cstack_X_at(const cstack_X* self, intptr_t idx); +i_val* cstack_X_at_mut(cstack_X* self, intptr_t idx); i_val* cstack_X_push(cstack_X* self, i_val value); i_val* cstack_X_emplace(cstack_X* self, i_valraw raw); diff --git a/docs/cstr_api.md b/docs/cstr_api.md index 48999654..6bf5c723 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -21,10 +21,10 @@ All cstr definitions and prototypes are available by including a single header f cstr cstr_init(void); // constructor; same as cstr_NULL. cstr cstr_lit(const char literal_only[]); // cstr from literal; no strlen() call. cstr cstr_from(const char* str); // constructor using strlen() -cstr cstr_from_n(const char* str, size_t n); // constructor with n first bytes of str +cstr cstr_from_n(const char* str, intptr_t n); // constructor with n first bytes of str cstr cstr_from_sv(csview sv); // construct cstr from csview -cstr cstr_with_capacity(size_t cap); -cstr cstr_with_size(size_t len, char fill); // repeat fill len times +cstr cstr_with_capacity(intptr_t cap); +cstr cstr_with_size(intptr_t len, char fill); // repeat fill len times cstr cstr_from_fmt(const char* fmt, ...); // printf() formatting cstr cstr_clone(cstr s); @@ -37,49 +37,49 @@ char* cstr_data(cstr* self); // cast to csview cstr_sv(const cstr* self); // cast to string view cstr_buf cstr_buffer(cstr* self); // cast to mutable buffer (with capacity) -size_t cstr_size(const cstr* self); -size_t cstr_capacity(const cstr* self); +intptr_t cstr_size(const cstr* self); +intptr_t cstr_capacity(const cstr* self); bool cstr_empty(const cstr* self); -char* cstr_reserve(cstr* self, size_t capacity); // return pointer to buffer -void cstr_resize(cstr* self, size_t len, char fill); +char* cstr_reserve(cstr* self, intptr_t capacity); // return pointer to buffer +void cstr_resize(cstr* self, intptr_t len, char fill); void cstr_shrink_to_fit(cstr* self); void cstr_clear(cstr* self); char* cstr_assign(cstr* self, const char* str); -char* cstr_assign_n(cstr* self, const char* str, size_t n); // assign n first bytes of str +char* cstr_assign_n(cstr* self, const char* str, intptr_t n); // assign n first bytes of str char* cstr_assign_sv(cstr* self, csview sv); char* cstr_copy(cstr* self, cstr s); // copy-assign a cstr int cstr_printf(cstr* self, const char* fmt, ...); // source and target must not overlap. char* cstr_append(cstr* self, const char* str); -char* cstr_append_n(cstr* self, const char* str, size_t n); // append n first bytes of str +char* cstr_append_n(cstr* self, const char* str, intptr_t n); // append n first bytes of str char* cstr_append_sv(cstr* self, csview str); char* cstr_append_s(cstr* self, cstr str); int cstr_append_fmt(cstr* self, const char* fmt, ...); // printf() formatting -char* cstr_append_uninit(cstr* self, size_t len); // return ptr to start of uninited data +char* cstr_append_uninit(cstr* self, intptr_t len); // return ptr to start of uninited data void cstr_push(cstr* self, const char* chr); // append one utf8 char void cstr_pop(cstr* self); // pop one utf8 char -void cstr_insert(cstr* self, size_t pos, const char* ins); -void cstr_insert_sv(cstr* self, size_t pos, csview ins); -void cstr_insert_s(cstr* self, size_t pos, cstr ins); +void cstr_insert(cstr* self, intptr_t pos, const char* ins); +void cstr_insert_sv(cstr* self, intptr_t pos, csview ins); +void cstr_insert_s(cstr* self, intptr_t pos, cstr ins); -void cstr_erase(cstr* self, size_t pos, size_t len); // erase len bytes from pos +void cstr_erase(cstr* self, intptr_t pos, intptr_t len); // erase len bytes from pos void cstr_replace(cstr* self, const char* search, const char* repl, unsigned count = MAX_INT); cstr cstr_replace_sv(csview in, csview search, csview repl, unsigned count); -void cstr_replace_at(cstr* self, size_t pos, size_t len, const char* repl); // replace at a position -void cstr_replace_at_sv(cstr* self, size_t pos, size_t len, const csview repl); -void cstr_replace_at_s(cstr* self, size_t pos, size_t len, cstr repl); +void cstr_replace_at(cstr* self, intptr_t pos, intptr_t len, const char* repl); // replace at a position +void cstr_replace_at_sv(cstr* self, intptr_t pos, intptr_t len, const csview repl); +void cstr_replace_at_s(cstr* self, intptr_t pos, intptr_t len, cstr repl); bool cstr_equals(const cstr* self, const char* str); bool cstr_equals_sv(const cstr* self, csview sv); bool cstr_equals_s(const cstr* self, cstr s); -size_t cstr_find(const cstr* self, const char* search); -size_t cstr_find_at(const cstr* self, size_t pos, const char* search); // search from pos +intptr_t cstr_find(const cstr* self, const char* search); +intptr_t cstr_find_at(const cstr* self, intptr_t pos, const char* search); // search from pos bool cstr_contains(const cstr* self, const char* search); bool cstr_starts_with(const cstr* self, const char* str); @@ -96,13 +96,13 @@ bool cstr_getdelim(cstr *self, int delim, FILE *stream); // does no #### UTF8 methods ```c -size_t cstr_u8_size(const cstr* self); // number of utf8 codepoints -size_t cstr_u8_size_n(const cstr self, size_t nbytes); // utf8 size within n bytes -size_t cstr_u8_to_pos(const cstr* self, size_t u8idx); // byte pos offset at utf8 codepoint index -const char* cstr_u8_at(const cstr* self, size_t u8idx); // char* position at utf8 codepoint index -csview cstr_u8_chr(const cstr* self, size_t u8idx); // get utf8 character as a csview -void cstr_u8_replace_at(cstr* self, size_t bytepos, size_t u8len, csview repl); // replace u8len utf8 chars -void cstr_u8_erase(cstr* self, size_t bytepos, size_t u8len); // erase u8len codepoints from pos +intptr_t cstr_u8_size(const cstr* self); // number of utf8 codepoints +intptr_t cstr_u8_size_n(const cstr self, intptr_t nbytes); // utf8 size within n bytes +intptr_t cstr_u8_to_pos(const cstr* self, intptr_t u8idx); // byte pos offset at utf8 codepoint index +const char* cstr_u8_at(const cstr* self, intptr_t u8idx); // char* position at utf8 codepoint index +csview cstr_u8_chr(const cstr* self, intptr_t u8idx); // get utf8 character as a csview +void cstr_u8_replace_at(cstr* self, intptr_t bytepos, intptr_t u8len, csview repl); // replace u8len utf8 chars +void cstr_u8_erase(cstr* self, intptr_t bytepos, intptr_t u8len); // erase u8len codepoints from pos // iterate utf8 codepoints cstr_iter cstr_begin(const cstr* self); @@ -128,7 +128,7 @@ bool cstr_istarts_with(const cstr* self, const char* str); bool cstr_iends_with(const cstr* self, const char* str); // " ``` -Note that all methods with arguments `(..., const char* str, size_t n)`, `n` must be within the range of `str` length. +Note that all methods with arguments `(..., const char* str, intptr_t n)`, `n` must be within the range of `str` length. #### Helper methods: ```c @@ -136,7 +136,7 @@ int cstr_cmp(const cstr* s1, const cstr* s2); bool cstr_eq(const cstr* s1, const cstr* s2); bool cstr_hash(const cstr* self); -char* cstrnstrn(const char* str, const char* search, size_t slen, size_t nlen); +char* cstrnstrn(const char* str, const char* search, intptr_t slen, intptr_t nlen); ``` ## Types @@ -145,8 +145,8 @@ char* cstrnstrn(const char* str, const char* search, size_t slen, size_t |:----------------|:-------------------------------------------|:---------------------| | `cstr` | `struct { ... }` | The string type | | `cstr_value` | `char` | String element type | -| `csview` | `struct { const char *str; size_t size; }` | String view type | -| `cstr_buf` | `struct { char *data; size_t size, cap; }` | String buffer type | +| `csview` | `struct { const char *str; intptr_t size; }` | String view type | +| `cstr_buf` | `struct { char *data; intptr_t size, cap; }` | String buffer type | ## Constants and macros @@ -162,7 +162,7 @@ char* cstrnstrn(const char* str, const char* search, size_t slen, size_t int main() { c_AUTO (cstr, s0, s1, full_path) { s0 = cstr_lit("Initialization without using strlen()."); - printf("%s\nLength: %" c_ZU "\n\n", cstr_str(&s0), cstr_size(&s0)); + printf("%s\nLength: %" c_ZI "\n\n", cstr_str(&s0), cstr_size(&s0)); s1 = cstr_lit("one-nine-three-seven-five."); printf("%s\n", cstr_str(&s1)); diff --git a/docs/csview_api.md b/docs/csview_api.md index 4085a708..8064e4fd 100644 --- a/docs/csview_api.md +++ b/docs/csview_api.md @@ -27,31 +27,31 @@ All csview definitions and prototypes are available by including a single header ```c csview c_SV(const char literal_only[]); // construct from literal, no strlen() -csview c_SV(const char* str, size_t n); // construct from str and length n +csview c_SV(const char* str, intptr_t n); // construct from str and length n csview csview_lit(const char literal_only[]); // alias for c_SV(lit) csview csview_from(const char* str); // construct from const char* -csview csview_from_n(const char* str, size_t n); // alias for c_SV(str, n) +csview csview_from_n(const char* str, intptr_t n); // alias for c_SV(str, n) -size_t csview_size(csview sv); +intptr_t csview_size(csview sv); bool csview_empty(csview sv); void csview_clear(csview* self); bool csview_equals(csview sv, csview sv2); -size_t csview_find(csview sv, const char* str); -size_t csview_find_sv(csview sv, csview find); +intptr_t csview_find(csview sv, const char* str); +intptr_t csview_find_sv(csview sv, csview find); bool csview_contains(csview sv, const char* str); bool csview_starts_with(csview sv, const char* str); bool csview_ends_with(csview sv, const char* str); -csview csview_substr_ex(csview sv, intptr_t pos, size_t n); // negative pos count from end +csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n); // negative pos count from end csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2); // negative p1, p2 count from end -csview csview_token(csview sv, const char* sep, size_t* start); // *start > sv.size after last token +csview csview_token(csview sv, const char* sep, intptr_t* start); // *start > sv.size after last token ``` #### UTF8 methods ```c -size_t csview_u8_size(csview sv); -csview csview_u8_substr(csview sv, size_t bytepos, size_t u8len); +intptr_t csview_u8_size(csview sv); +csview csview_u8_substr(csview sv, intptr_t bytepos, intptr_t u8len); bool csview_valid_utf8(csview sv); // requires linking with src/utf8code.c csview_iter csview_begin(const csview* self); @@ -60,14 +60,14 @@ void csview_next(csview_iter* it); // utf8 csview_iter csview_advance(csview_iter it, intptr_t n); // from utf8.h -size_t utf8_size(const char *s); -size_t utf8_size_n(const char *s, size_t nbytes); // number of UTF8 codepoints within n bytes -const char* utf8_at(const char *s, size_t index); // from UTF8 index to char* position -size_t utf8_pos(const char* s, size_t index); // from UTF8 index to byte index position +intptr_t utf8_size(const char *s); +intptr_t utf8_size_n(const char *s, intptr_t nbytes); // number of UTF8 codepoints within n bytes +const char* utf8_at(const char *s, intptr_t index); // from UTF8 index to char* position +intptr_t utf8_pos(const char* s, intptr_t index); // from UTF8 index to byte index position unsigned utf8_chr_size(const char* s); // UTF8 character size: 1-4 // implemented in src/utf8code.c: bool utf8_valid(const char* s); -bool utf8_valid_n(const char* s, size_t nbytes); +bool utf8_valid_n(const char* s, intptr_t nbytes); uint32_t utf8_decode(utf8_decode_t *d, uint8_t byte); // decode next byte to utf8, return state. unsigned utf8_encode(char *out, uint32_t codepoint); // encode unicode cp into out buffer uint32_t utf8_peek(const char* s); // codepoint value of character at s @@ -76,11 +76,11 @@ uint32_t utf8_peek_off(const char* s, int offset); // code #### Extended cstr methods ```c -csview cstr_substr(const cstr* self, size_t pos, size_t n); -csview cstr_substr_ex(const cstr* s, intptr_t pos, size_t n); // negative pos count from end -csview cstr_u8_substr(const cstr* self, size_t bytepos, size_t u8len); +csview cstr_substr(const cstr* self, intptr_t pos, intptr_t n); +csview cstr_substr_ex(const cstr* s, intptr_t pos, intptr_t n); // negative pos count from end +csview cstr_u8_substr(const cstr* self, intptr_t bytepos, intptr_t u8len); -csview cstr_slice(const cstr* self, size_t p1, size_t p2); +csview cstr_slice(const cstr* self, intptr_t p1, intptr_t p2); csview cstr_slice_ex(const cstr* s, intptr_t p, intptr_t q); // negative p or q count from end ``` #### Iterate tokens with *c_FORTOKEN*, *c_FORTOKEN_SV* @@ -103,7 +103,7 @@ uint64_t csview_hash(const csview* x); | Type name | Type definition | Used to represent... | |:----------------|:-------------------------------------------|:-------------------------| -| `csview` | `struct { const char *str; size_t size; }` | The string view type | +| `csview` | `struct { const char *str; intptr_t size; }` | The string view type | | `csview_value` | `char` | The string element type | | `csview_iter` | `struct { csview_value *ref; }` | UTF8 iterator | @@ -125,7 +125,7 @@ int main () // (quoting Alfred N. Whitehead) csview sv1 = cstr_substr(&str1, 3, 5); // "think" - size_t pos = cstr_find(&str1, "live"); // position of "live" in str1 + intptr_t pos = cstr_find(&str1, "live"); // position of "live" in str1 csview sv2 = cstr_substr(&str1, pos, 4); // get "live" csview sv3 = cstr_slice(&str1, -8, -1); // get "details" printf("%.*s %.*s %.*s\n", diff --git a/docs/cvec_api.md b/docs/cvec_api.md index 08c404af..d67e80fd 100644 --- a/docs/cvec_api.md +++ b/docs/cvec_api.md @@ -31,26 +31,26 @@ See the c++ class [std::vector](https://en.cppreference.com/w/cpp/container/vect ```c cvec_X cvec_X_init(void); -cvec_X cvec_X_with_size(size_t size, i_val null); -cvec_X cvec_X_with_capacity(size_t size); +cvec_X cvec_X_with_size(intptr_t size, i_val null); +cvec_X cvec_X_with_capacity(intptr_t size); cvec_X cvec_X_clone(cvec_X vec); void cvec_X_clear(cvec_X* self); void cvec_X_copy(cvec_X* self, const cvec_X* other); cvec_X_iter cvec_X_copy_range(cvec_X* self, i_val* pos, const i_val* p1, const i_val* p2); -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_iter cvec_X_insert_uninit(cvec_X* self, i_val* pos, size_t n); // return pos iter +bool cvec_X_reserve(cvec_X* self, intptr_t cap); +bool cvec_X_resize(cvec_X* self, intptr_t size, i_val null); +cvec_X_iter cvec_X_insert_uninit(cvec_X* self, i_val* pos, intptr_t n); // return pos iter void cvec_X_shrink_to_fit(cvec_X* self); void cvec_X_drop(cvec_X* self); // destructor bool cvec_X_empty(const cvec_X* self); -size_t cvec_X_size(const cvec_X* self); -size_t cvec_X_capacity(const cvec_X* self); +intptr_t cvec_X_size(const cvec_X* self); +intptr_t cvec_X_capacity(const cvec_X* self); -const cvec_X_value* cvec_X_at(const cvec_X* self, size_t idx); +const cvec_X_value* cvec_X_at(const cvec_X* self, intptr_t idx); const cvec_X_value* cvec_X_get(const cvec_X* self, i_valraw raw); // return NULL if not found -cvec_X_value* cvec_X_at_mut(cvec_X* self, size_t idx); +cvec_X_value* cvec_X_at_mut(cvec_X* self, intptr_t idx); cvec_X_value* cvec_X_get_mut(cvec_X* self, i_valraw raw); // find mutable value, return value ptr cvec_X_iter cvec_X_find(const cvec_X* self, i_valraw raw); cvec_X_iter cvec_X_find_in(cvec_X_iter i1, cvec_X_iter i2, i_valraw raw); // return cvec_X_end() if not found @@ -71,18 +71,18 @@ cvec_X_value* cvec_X_emplace_back(cvec_X* self, i_valraw raw); void cvec_X_pop(cvec_X* self); void cvec_X_pop_back(cvec_X* self); // alias for pop -cvec_X_iter cvec_X_insert(cvec_X* self, size_t idx, i_val value); // move value -cvec_X_iter cvec_X_insert_n(cvec_X* self, size_t idx, const i_val[] arr, size_t n); // move n values +cvec_X_iter cvec_X_insert(cvec_X* self, intptr_t idx, i_val value); // move value +cvec_X_iter cvec_X_insert_n(cvec_X* self, intptr_t idx, const i_val[] arr, intptr_t n); // move n values cvec_X_iter cvec_X_insert_at(cvec_X* self, cvec_X_iter it, i_val value); // move value cvec_X_iter cvec_X_insert_range(cvec_X* self, i_val* pos, const i_val* p1, const i_val* p2); -cvec_X_iter cvec_X_emplace_n(cvec_X* self, size_t idx, const i_valraw[] arr, size_t n); // clone values +cvec_X_iter cvec_X_emplace_n(cvec_X* self, intptr_t idx, const i_valraw[] arr, intptr_t n); // clone values cvec_X_iter cvec_X_emplace_at(cvec_X* self, cvec_X_iter it, i_valraw raw); cvec_X_iter cvec_X_emplace_range(cvec_X* self, i_val* pos, const i_valraw* p1, const i_valraw* p2); -cvec_X_iter cvec_X_erase_n(cvec_X* self, size_t idx, size_t n); +cvec_X_iter cvec_X_erase_n(cvec_X* self, intptr_t idx, intptr_t n); cvec_X_iter cvec_X_erase_at(cvec_X* self, cvec_X_iter it); cvec_X_iter cvec_X_erase_range(cvec_X* self, cvec_X_iter it1, cvec_X_iter it2); cvec_X_iter cvec_X_erase_range_p(cvec_X* self, i_val* p1, i_val* p2); @@ -94,7 +94,7 @@ void cvec_X_sort_range(cvec_X_iter i1, cvec_X_iter i2, cvec_X_iter cvec_X_begin(const cvec_X* self); cvec_X_iter cvec_X_end(const cvec_X* self); void cvec_X_next(cvec_X_iter* iter); -cvec_X_iter cvec_X_advance(cvec_X_iter it, intptr_t n); +cvec_X_iter cvec_X_advance(cvec_X_iter it, size_t n); cvec_X_raw cvec_X_value_toraw(cvec_X_value* pval); cvec_X_value cvec_X_value_clone(cvec_X_value val); diff --git a/include/stc/algo/csort.h b/include/stc/algo/csort.h index 9c9bcd5b..c8c41257 100644 --- a/include/stc/algo/csort.h +++ b/include/stc/algo/csort.h @@ -99,7 +99,7 @@ static inline void c_PASTE(cqsort_, i_tag)(i_val arr[], intptr_t lo, intptr_t hi } } -static inline void c_PASTE(csort_, i_tag)(i_val arr[], size_t n) - { c_PASTE(cqsort_, i_tag)(arr, 0, (intptr_t)n - 1); } +static inline void c_PASTE(csort_, i_tag)(i_val arr[], intptr_t n) + { c_PASTE(cqsort_, i_tag)(arr, 0, n - 1); } #include <stc/priv/template.h> diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index f0d157e3..30184407 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -32,13 +32,10 @@ #include "priv/altnames.h" #define c_NPOS INTPTR_MAX -#if SIZE_MAX == UINT32_MAX - #define c_ZU PRIu32 -#elif SIZE_MAX == UINT64_MAX - #define c_ZU PRIu64 -#endif +#define c_ZI PRIiPTR +#define c_ZU PRIuPTR #if defined STC_NDEBUG || defined NDEBUG - #define c_ASSERT(expr) (void)(expr) + #define c_ASSERT(expr) (void)(0) #else #define c_ASSERT(expr) assert(expr) #endif diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index 44c5e8d5..56c0e867 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -110,7 +110,7 @@ STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->end) it->ref = NULL; } -STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t n) +STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t n) { if ((it.ref += n) >= it.end) it.ref = NULL; return it; } #if !defined _i_queue diff --git a/include/stc/cmap.h b/include/stc/cmap.h index f9cd6986..f90d9a4a 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -53,7 +53,7 @@ int main(void) { #include "forward.h" #include <stdlib.h> #include <string.h> -typedef struct { size_t idx; uint8_t hx; } chash_bucket_t; +typedef struct { intptr_t idx; uint8_t hx; } chash_bucket_t; #endif // CMAP_H_INCLUDED #ifndef _i_prefix @@ -96,13 +96,13 @@ typedef _i_SET_ONLY( i_keyraw ) i_valraw second; } ) _cx_raw; -STC_API _cx_self _cx_memb(_with_capacity)(size_t cap); +STC_API _cx_self _cx_memb(_with_capacity)(intptr_t cap); #if !defined i_no_clone STC_API _cx_self _cx_memb(_clone)(_cx_self map); #endif STC_API void _cx_memb(_drop)(_cx_self* self); STC_API void _cx_memb(_clear)(_cx_self* self); -STC_API bool _cx_memb(_reserve)(_cx_self* self, size_t capacity); +STC_API bool _cx_memb(_reserve)(_cx_self* self, intptr_t capacity); STC_API chash_bucket_t _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey* rkeyptr); STC_API _cx_result _cx_memb(_insert_entry_)(_cx_self* self, _cx_rawkey rkey); STC_API void _cx_memb(_erase_entry)(_cx_self* self, _cx_value* val); @@ -111,10 +111,10 @@ STC_INLINE _cx_self _cx_memb(_init)(void) { return c_LITERAL(_cx_self){0}; } STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self) { _cx_memb(_reserve)(self, self->size); } STC_INLINE float _cx_memb(_max_load_factor)(const _cx_self* self) { return (float)(i_max_load_factor); } STC_INLINE bool _cx_memb(_empty)(const _cx_self* map) { return !map->size; } -STC_INLINE size_t _cx_memb(_size)(const _cx_self* map) { return map->size; } -STC_INLINE size_t _cx_memb(_bucket_count)(_cx_self* map) { return map->bucket_count; } -STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* map) - { return (size_t)((float)map->bucket_count * (i_max_load_factor)); } +STC_INLINE intptr_t _cx_memb(_size)(const _cx_self* map) { return map->size; } +STC_INLINE intptr_t _cx_memb(_bucket_count)(_cx_self* map) { return map->bucket_count; } +STC_INLINE intptr_t _cx_memb(_capacity)(const _cx_self* map) + { return (intptr_t)((float)map->bucket_count * (i_max_load_factor)); } STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, _cx_rawkey rkey) { return self->size && self->_hashx[_cx_memb(_bucket_)(self, &rkey).idx]; } @@ -195,7 +195,7 @@ _cx_memb(_push)(_cx_self* self, _cx_value _val) { return _res; } -STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, size_t n) { +STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, intptr_t n) { while (n--) #if defined _i_isset && defined i_no_emplace _cx_memb(_insert)(self, *raw++); @@ -208,7 +208,7 @@ STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, size_t n) { #endif } -STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, size_t n) +STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, intptr_t n) { _cx_self cx = {0}; _cx_memb(_put_n)(&cx, raw, n); return cx; } STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { @@ -238,7 +238,7 @@ _cx_memb(_advance)(_cx_iter it, size_t n) { STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) { - size_t idx; + intptr_t idx; if (self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx]) return c_LITERAL(_cx_iter){self->table + idx, self->table + self->bucket_count, @@ -248,7 +248,7 @@ _cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) { STC_INLINE const _cx_value* _cx_memb(_get)(const _cx_self* self, _cx_rawkey rkey) { - size_t idx; + intptr_t idx; if (self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx]) return self->table + idx; return NULL; @@ -258,12 +258,12 @@ STC_INLINE _cx_value* _cx_memb(_get_mut)(_cx_self* self, _cx_rawkey rkey) { return (_cx_value*)_cx_memb(_get)(self, rkey); } -STC_INLINE size_t +STC_INLINE intptr_t _cx_memb(_erase)(_cx_self* self, _cx_rawkey rkey) { if (self->size == 0) return 0; chash_bucket_t b = _cx_memb(_bucket_)(self, &rkey); - return self->_hashx[b.idx] ? _cx_memb(_erase_entry)(self, self->table + b.idx), 1U : 0U; + return self->_hashx[b.idx] ? _cx_memb(_erase_entry)(self, self->table + b.idx), 1 : 0; } STC_INLINE _cx_iter @@ -278,11 +278,11 @@ _cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { #if defined(i_implement) #ifndef CMAP_H_INCLUDED -STC_INLINE size_t fastrange_1(uint64_t x, uint64_t n) - { return (size_t)((uint32_t)x*n >> 32); } // n < 2^32 +STC_INLINE intptr_t fastrange_1(uint64_t x, uint64_t n) + { return (intptr_t)((uint32_t)x*n >> 32); } // n < 2^32 -STC_INLINE size_t fastrange_2(uint64_t x, uint64_t n) - { return x & (n - 1); } // n power of 2. +STC_INLINE intptr_t fastrange_2(uint64_t x, uint64_t n) + { return (intptr_t)(x & (n - 1)); } // n power of 2. STC_INLINE uint64_t next_power_of_2(uint64_t n) { n--; @@ -294,7 +294,7 @@ STC_INLINE uint64_t next_power_of_2(uint64_t n) { #endif // CMAP_H_INCLUDED STC_DEF _cx_self -_cx_memb(_with_capacity)(const size_t cap) { +_cx_memb(_with_capacity)(const intptr_t cap) { _cx_self h = {0}; _cx_memb(_reserve)(&h, cap); return h; @@ -319,7 +319,7 @@ STC_DEF void _cx_memb(_drop)(_cx_self* self) { STC_DEF void _cx_memb(_clear)(_cx_self* self) { _cx_memb(_wipe_)(self); self->size = 0; - memset(self->_hashx, 0, self->bucket_count); + c_memset(self->_hashx, 0, self->bucket_count); } #ifndef _i_isset @@ -355,7 +355,7 @@ STC_DEF chash_bucket_t _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey* rkeyptr) { const uint64_t _hash = i_hash_functor(self, rkeyptr); i_size _cap = self->bucket_count; - chash_bucket_t b = {c_PASTE(fastrange_,_i_expandby)(_hash, _cap), (uint8_t)(_hash | 0x80)}; + chash_bucket_t b = {c_PASTE(fastrange_,_i_expandby)(_hash, (uint64_t)_cap), (uint8_t)(_hash | 0x80)}; const uint8_t* _hx = self->_hashx; while (_hx[b.idx]) { if (_hx[b.idx] == b.hx) { @@ -390,7 +390,7 @@ STC_DEF _cx_self _cx_memb(_clone)(_cx_self m) { if (m.table) { _cx_value *t = c_ALLOC_N(_cx_value, m.bucket_count), *dst = t, *m_end = m.table + m.bucket_count; - uint8_t *h = (uint8_t *)memcpy(c_malloc(m.bucket_count + 1), m._hashx, m.bucket_count + 1); + uint8_t *h = (uint8_t *)c_memcpy(c_malloc(m.bucket_count + 1), m._hashx, m.bucket_count + 1); if (!(t && h)) { c_free(t), c_free(h), t = 0, h = 0, m.bucket_count = 0; } else @@ -404,7 +404,7 @@ _cx_memb(_clone)(_cx_self m) { #endif STC_DEF bool -_cx_memb(_reserve)(_cx_self* self, const size_t _newcap) { +_cx_memb(_reserve)(_cx_self* self, const intptr_t _newcap) { const i_size _oldbuckets = self->bucket_count; if (_newcap != self->size && _newcap <= _oldbuckets) return true; @@ -424,7 +424,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t _newcap) { m._hashx[_nbuckets] = 0xff; const _cx_value* e = self->table; const uint8_t* h = self->_hashx; - for (size_t i = 0; i < _oldbuckets; ++i, ++e) if (*h++) { + for (i_size i = 0; i < _oldbuckets; ++i, ++e) if (*h++) { _cx_rawkey r = i_keyto(_i_keyref(e)); chash_bucket_t b = _cx_memb(_bucket_)(&m, &r); m.table[b.idx] = *e; @@ -450,7 +450,7 @@ _cx_memb(_erase_entry)(_cx_self* self, _cx_value* _val) { if (! _hashx[j]) break; const _cx_rawkey _raw = i_keyto(_i_keyref(_slot + j)); - k = (i_size)c_PASTE(fastrange_,_i_expandby)(i_hash_functor(self, (&_raw)), _cap); + k = (i_size)c_PASTE(fastrange_,_i_expandby)(i_hash_functor(self, (&_raw)), (uint64_t)_cap); if ((j < i) ^ (k <= i) ^ (k > j)) /* is k outside (i, j]? */ _slot[i] = _slot[j], _hashx[i] = _hashx[j], i = j; } diff --git a/include/stc/cpque.h b/include/stc/cpque.h index 21130864..55df70ef 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -55,7 +55,7 @@ STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, intptr_t n) STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, const intptr_t cap) { if (cap != self->_len && cap <= self->_cap) return true; - _cx_value *d = (_cx_value *)c_realloc(self->data, cap*sizeof *d); + _cx_value *d = (_cx_value *)c_realloc(self->data, cap*c_sizeof *d); return d ? (self->data = d, self->_cap = cap, true) : false; } diff --git a/include/stc/crandom.h b/include/stc/crandom.h index 5641d788..32e541ff 100644 --- a/include/stc/crandom.h +++ b/include/stc/crandom.h @@ -46,7 +46,7 @@ int main() { 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; unsigned has_next; } stc64_normalf_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. diff --git a/include/stc/cregex.h b/include/stc/cregex.h index c41fbb67..564fe157 100644 --- a/include/stc/cregex.h +++ b/include/stc/cregex.h @@ -105,7 +105,7 @@ STC_INLINE cregex cregex_from_2(const char* pattern, int cflags) { } /* number of capture groups in a regex pattern including full the match capture, 0 if regex is invalid */ -unsigned cregex_captures(const cregex* re); +int cregex_captures(const cregex* re); /* return CREG_OK, CREG_NOMATCH or CREG_MATCHERROR. */ #define cregex_find(...) c_MACRO_OVERLOAD(cregex_find, __VA_ARGS__) @@ -132,17 +132,17 @@ STC_INLINE bool cregex_is_match(const cregex* re, const char* input) /* replace csview input with replace using regular expression pattern */ #define cregex_replace_sv(...) c_MACRO_OVERLOAD(cregex_replace_sv, __VA_ARGS__) #define cregex_replace_sv_3(pattern, input, replace) \ - cregex_replace_sv_4(pattern, input, replace, ~0U) + cregex_replace_sv_4(pattern, input, replace, INT32_MAX) #define cregex_replace_sv_4(pattern, input, replace, count) \ cregex_replace_sv_6(pattern, input, replace, count, NULL, CREG_DEFAULT) -cstr cregex_replace_sv_6(const cregex* re, csview input, const char* replace, unsigned count, +cstr cregex_replace_sv_6(const cregex* re, csview input, const char* replace, int count, bool (*mfun)(int i, csview match, cstr* mstr), int rflags); /* replace input with replace using regular expression */ #define cregex_replace(...) c_MACRO_OVERLOAD(cregex_replace, __VA_ARGS__) -#define cregex_replace_3(re, input, replace) cregex_replace_4(re, input, replace, ~0U) +#define cregex_replace_3(re, input, replace) cregex_replace_4(re, input, replace, INT32_MAX) -STC_INLINE cstr cregex_replace_4(const cregex* re, const char* input, const char* replace, unsigned count) { +STC_INLINE cstr cregex_replace_4(const cregex* re, const char* input, const char* replace, int count) { csview sv = {input, c_strlen(input)}; return cregex_replace_sv_4(re, sv, replace, count); } @@ -150,10 +150,10 @@ STC_INLINE cstr cregex_replace_4(const cregex* re, const char* input, const char /* replace + compile RE pattern, and extra arguments */ #define cregex_replace_pattern(...) c_MACRO_OVERLOAD(cregex_replace_pattern, __VA_ARGS__) #define cregex_replace_pattern_3(pattern, input, replace) \ - cregex_replace_pattern_4(pattern, input, replace, ~0U) + cregex_replace_pattern_4(pattern, input, replace, INT32_MAX) #define cregex_replace_pattern_4(pattern, input, replace, count) \ cregex_replace_pattern_6(pattern, input, replace, count, NULL, CREG_DEFAULT) -cstr cregex_replace_pattern_6(const char* pattern, const char* input, const char* replace, unsigned count, +cstr cregex_replace_pattern_6(const char* pattern, const char* input, const char* replace, int count, bool (*mfun)(int i, csview match, cstr* mstr), int crflags); /* destroy regex */ diff --git a/include/stc/csmap.h b/include/stc/csmap.h index b92d25d8..de948618 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -107,7 +107,7 @@ STC_API _cx_self _cx_memb(_init)(void); STC_API _cx_result _cx_memb(_insert)(_cx_self* self, i_key key _i_MAP_ONLY(, i_val mapped)); STC_API _cx_result _cx_memb(_push)(_cx_self* self, _cx_value _val); STC_API void _cx_memb(_drop)(_cx_self* self); -STC_API bool _cx_memb(_reserve)(_cx_self* self, size_t cap); +STC_API bool _cx_memb(_reserve)(_cx_self* self, intptr_t cap); STC_API _cx_value* _cx_memb(_find_it)(const _cx_self* self, _cx_rawkey rkey, _cx_iter* out); STC_API _cx_iter _cx_memb(_lower_bound)(const _cx_self* self, _cx_rawkey rkey); STC_API _cx_value* _cx_memb(_front)(const _cx_self* self); @@ -118,8 +118,8 @@ STC_API _cx_iter _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx STC_API void _cx_memb(_next)(_cx_iter* it); STC_INLINE bool _cx_memb(_empty)(const _cx_self* cx) { return cx->size == 0; } -STC_INLINE size_t _cx_memb(_size)(const _cx_self* cx) { return cx->size; } -STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* cx) { return cx->cap; } +STC_INLINE intptr_t _cx_memb(_size)(const _cx_self* cx) { return cx->size; } +STC_INLINE intptr_t _cx_memb(_capacity)(const _cx_self* cx) { return cx->cap; } STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) { _cx_iter it; _cx_memb(_find_it)(self, rkey, &it); return it; } STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, _cx_rawkey rkey) @@ -130,7 +130,7 @@ STC_INLINE _cx_value* _cx_memb(_get_mut)(_cx_self* self, _cx_rawkey rkey) { _cx_iter it; return _cx_memb(_find_it)(self, rkey, &it); } STC_INLINE _cx_self -_cx_memb(_with_capacity)(const size_t cap) { +_cx_memb(_with_capacity)(const intptr_t cap) { _cx_self tree = _cx_memb(_init)(); _cx_memb(_reserve)(&tree, cap); return tree; @@ -225,10 +225,10 @@ _cx_memb(_init)(void) { } STC_DEF bool -_cx_memb(_reserve)(_cx_self* self, const size_t cap) { +_cx_memb(_reserve)(_cx_self* self, const intptr_t cap) { if (cap <= self->cap) return false; - _cx_node* nodes = (_cx_node*)c_realloc(self->nodes, (cap + 1)*sizeof(_cx_node)); + _cx_node* nodes = (_cx_node*)c_realloc(self->nodes, (cap + 1)*c_sizeof(_cx_node)); if (!nodes) return false; nodes[0] = c_LITERAL(_cx_node){{0, 0}, 0}; @@ -294,7 +294,7 @@ _cx_memb(_push)(_cx_self* self, _cx_value _val) { return _res; } -STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, size_t n) { +STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, intptr_t n) { while (n--) #if defined _i_isset && defined i_no_emplace _cx_memb(_insert)(self, *raw++); @@ -307,7 +307,7 @@ STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, size_t n) { #endif } -STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, size_t n) +STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, intptr_t n) { _cx_self cx = {0}; _cx_memb(_put_n)(&cx, raw, n); return cx; } #ifndef _i_isset diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 97d5256c..dd4686e9 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -185,7 +185,7 @@ STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->end) it->ref = NULL; } -STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t n) +STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t n) { if ((it.ref += n) >= it.end) it.ref = NULL ; return it; } #include "priv/template.h" diff --git a/include/stc/cstr.h b/include/stc/cstr.h index f965487c..2966db81 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -374,7 +374,7 @@ STC_INLINE char* cstr_append_s(cstr* self, cstr s) { } #define cstr_replace(...) c_MACRO_OVERLOAD(cstr_replace, __VA_ARGS__) -#define cstr_replace_3(self, search, repl) cstr_replace_4(self, search, repl, ~0U) +#define cstr_replace_3(self, search, repl) cstr_replace_4(self, search, repl, INT32_MAX) STC_INLINE void cstr_replace_4(cstr* self, const char* search, const char* repl, int32_t count) { cstr_take(self, cstr_replace_sv(cstr_sv(self), c_SV(search, c_strlen(search)), c_SV(repl, c_strlen(repl)), count)); diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 11d145e6..06664b4d 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -208,7 +208,7 @@ STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->end) it->ref = NULL; } -STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t n) +STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t n) { if ((it.ref += n) >= it.end) it.ref = NULL; return it; } STC_INLINE intptr_t _cx_memb(_index)(const _cx_self* self, _cx_iter it) diff --git a/include/stc/forward.h b/include/stc/forward.h index dfb43a9f..594c76fa 100644 --- a/include/stc/forward.h +++ b/include/stc/forward.h @@ -26,17 +26,15 @@ #include <stdint.h> #define forward_carc(CX, VAL) _c_carc_types(CX, VAL) -#define forward_carr2(CX, VAL) _c_carr2_types(CX, VAL) -#define forward_carr3(CX, VAL) _c_carr3_types(CX, VAL) #define forward_cbox(CX, VAL) _c_cbox_types(CX, VAL) #define forward_cdeq(CX, VAL) _c_cdeq_types(CX, VAL) #define forward_clist(CX, VAL) _c_clist_types(CX, VAL) -#define forward_cmap(CX, KEY, VAL) _c_chash_types(CX, KEY, VAL, uint32_t, c_true, c_false) -#define forward_cmap_huge(CX, KEY, VAL) _c_chash_types(CX, KEY, VAL, size_t, c_true, c_false) -#define forward_cset(CX, KEY) _c_chash_types(CX, cset, KEY, KEY, uint32_t, c_false, c_true) -#define forward_cset_huge(CX, KEY) _c_chash_types(CX, cset, KEY, KEY, size_t, c_false, c_true) -#define forward_csmap(CX, KEY, VAL) _c_aatree_types(CX, KEY, VAL, uint32_t, c_true, c_false) -#define forward_csset(CX, KEY) _c_aatree_types(CX, KEY, KEY, uint32_t, c_false, c_true) +#define forward_cmap(CX, KEY, VAL) _c_chash_types(CX, KEY, VAL, int32_t, c_true, c_false) +#define forward_cmap_huge(CX, KEY, VAL) _c_chash_types(CX, KEY, VAL, intptr_t, c_true, c_false) +#define forward_cset(CX, KEY) _c_chash_types(CX, cset, KEY, KEY, int32_t, c_false, c_true) +#define forward_cset_huge(CX, KEY) _c_chash_types(CX, cset, KEY, KEY, intptr_t, c_false, c_true) +#define forward_csmap(CX, KEY, VAL) _c_aatree_types(CX, KEY, VAL, int32_t, c_true, c_false) +#define forward_csset(CX, KEY) _c_aatree_types(CX, KEY, KEY, int32_t, c_false, c_true) #define forward_cstack(CX, VAL) _c_cstack_types(CX, VAL) #define forward_cpque(CX, VAL) _c_cpque_types(CX, VAL) #define forward_cqueue(CX, VAL) _c_cdeq_types(CX, VAL) diff --git a/include/stc/priv/template.h b/include/stc/priv/template.h index 9634fe2c..4aa54bcc 100644 --- a/include/stc/priv/template.h +++ b/include/stc/priv/template.h @@ -47,7 +47,7 @@ #ifdef i_size #define _i_expandby 2 #else - #define i_size uint32_t + #define i_size int32_t #define _i_expandby 1 #endif diff --git a/include/stc/utf8.h b/include/stc/utf8.h index ce50af87..da738fc6 100644 --- a/include/stc/utf8.h +++ b/include/stc/utf8.h @@ -25,7 +25,7 @@ extern bool utf8_iscased(uint32_t c); extern bool utf8_isword(uint32_t c); extern bool utf8_valid_n(const char* s, intptr_t nbytes); extern int utf8_icmp_sv(csview s1, csview s2); -extern unsigned utf8_encode(char *out, uint32_t c); +extern int utf8_encode(char *out, uint32_t c); extern uint32_t utf8_peek_off(const char *s, int offset); STC_INLINE bool utf8_isupper(uint32_t c) @@ -45,7 +45,7 @@ STC_INLINE bool utf8_isblank(uint32_t c) { } STC_INLINE bool utf8_isspace(uint32_t c) { - if (c < 128) return isspace(c) != 0; + if (c < 128) return isspace((int)c) != 0; return ((c == 8232) | (c == 8233)) || utf8_isgroup(U8G_Zs, c); } diff --git a/misc/archived/cstr.h b/misc/archived/cstr.h index 9111fe6d..17baf52c 100644 --- a/misc/archived/cstr.h +++ b/misc/archived/cstr.h @@ -56,7 +56,7 @@ STC_API void cstr_resize(cstr* self, size_t len, char fill); STC_API cstr* cstr_assign_n(cstr* self, const char* str, size_t n); STC_API int cstr_printf(cstr* self, const char* fmt, ...); STC_API cstr* cstr_append_n(cstr* self, const char* str, size_t n); -STC_API cstr cstr_replace_sv(csview str, csview find, csview repl, unsigned count); +STC_API cstr cstr_replace_sv(csview str, csview find, csview repl, int count); STC_DEF void cstr_replace_at_sv(cstr* self, const size_t pos, size_t len, csview repl); STC_API void cstr_erase(cstr* self, size_t pos, size_t n); STC_API size_t cstr_find(const cstr* self, const char* needle); @@ -182,7 +182,7 @@ STC_INLINE uint64_t cstr_hash(const cstr *self) { return cfasthash(self->str, _cstr_p(self)->size); } -STC_INLINE void cstr_replace_ex(cstr* self, const char* find, const char* repl, unsigned count) { +STC_INLINE void cstr_replace_ex(cstr* self, const char* find, const char* repl, int count) { cstr_take(self, cstr_replace_sv(cstr_sv(self), c_SV(find, strlen(find)), c_SV(repl, strlen(repl)), count)); } diff --git a/misc/examples/astar.c b/misc/examples/astar.c index 828de8ce..ddc9de3a 100644 --- a/misc/examples/astar.c +++ b/misc/examples/astar.c @@ -37,7 +37,7 @@ point_equal(const point* a, const point* b) point point_from(const cstr* maze, const char* c, int width) { - int index = cstr_find(maze, c); + int index = (int)cstr_find(maze, c); return point_init(index % width, index / width, width); } @@ -156,7 +156,7 @@ main(void) "# # # # # # #\n" "#########################################################################\n"), cstr_drop(&maze)) { - int width = cstr_find(&maze, "\n") + 1; + int width = (int)cstr_find(&maze, "\n") + 1; c_WITH (cdeq_point path = astar(&maze, width), cdeq_point_drop(&path)) { c_FOREACH (it, cdeq_point, path) diff --git a/misc/examples/birthday.c b/misc/examples/birthday.c index be7f0457..fb887cd7 100644 --- a/misc/examples/birthday.c +++ b/misc/examples/birthday.c @@ -50,19 +50,19 @@ void test_distribution(void) uint64_t sum = 0; c_FOREACH (i, cmap_x, map) sum += i.ref->second; - sum /= map.size; + sum /= (uint64_t)map.size; c_FOREACH (i, cmap_x, map) { printf("%4" PRIu32 ": %" PRIu64 " - %" PRIu64 ": %11.8f\n", i.ref->first, i.ref->second, sum, - (1 - (double)i.ref->second / sum)); + (1.0 - (double)i.ref->second / (double)sum)); } } } int main() { - seed = time(NULL); + seed = (uint64_t)time(NULL); test_distribution(); test_repeats(); } diff --git a/misc/examples/bits.c b/misc/examples/bits.c index c50eac6e..03b74881 100644 --- a/misc/examples/bits.c +++ b/misc/examples/bits.c @@ -4,18 +4,18 @@ int main() { c_WITH (cbits set = cbits_with_size(23, true), cbits_drop(&set)) { - printf("count %" c_ZU ", %" c_ZU "\n", cbits_count(&set), cbits_size(&set)); + printf("count %" c_ZI ", %" c_ZI "\n", cbits_count(&set), cbits_size(&set)); cbits s1 = cbits_from("1110100110111"); char buf[256]; cbits_to_str(&s1, buf, 0, 255); - printf("buf: %s: %" c_ZU "\n", buf, cbits_count(&s1)); + printf("buf: %s: %" c_ZI "\n", buf, cbits_count(&s1)); cbits_drop(&s1); cbits_reset(&set, 9); cbits_resize(&set, 43, false); printf(" str: %s\n", cbits_to_str(&set, buf, 0, 255)); - printf("%4" c_ZU ": ", cbits_size(&set)); + printf("%4" c_ZI ": ", cbits_size(&set)); c_FORRANGE (i, cbits_size(&set)) printf("%d", cbits_test(&set, i)); puts(""); @@ -25,12 +25,12 @@ int main() cbits_resize(&set, 93, false); cbits_resize(&set, 102, true); cbits_set_value(&set, 99, false); - printf("%4" c_ZU ": ", cbits_size(&set)); + printf("%4" c_ZI ": ", cbits_size(&set)); c_FORRANGE (i, cbits_size(&set)) printf("%d", cbits_test(&set, i)); puts("\nIterate:"); - printf("%4" c_ZU ": ", cbits_size(&set)); + printf("%4" c_ZI ": ", cbits_size(&set)); c_FORRANGE (i, cbits_size(&set)) printf("%d", cbits_test(&set, i)); puts(""); @@ -52,7 +52,7 @@ int main() puts(""); cbits_set_all(&set, false); - printf("%4" c_ZU ": ", cbits_size(&set)); + printf("%4" c_ZI ": ", cbits_size(&set)); c_FORRANGE (i, cbits_size(&set)) printf("%d", cbits_test(&set, i)); puts(""); diff --git a/misc/examples/bits2.c b/misc/examples/bits2.c index 502e7268..9b1d1af7 100644 --- a/misc/examples/bits2.c +++ b/misc/examples/bits2.c @@ -9,10 +9,10 @@ int main() { Bits s1 = Bits_from("1110100110111"); - printf("size %" c_ZU "\n", Bits_size(&s1)); + printf("size %" c_ZI "\n", Bits_size(&s1)); char buf[256]; Bits_to_str(&s1, buf, 0, 256); - printf("buf: %s: count=%" c_ZU "\n", buf, Bits_count(&s1)); + printf("buf: %s: count=%" c_ZI "\n", buf, Bits_count(&s1)); Bits_reset(&s1, 8); printf(" s1: %s\n", Bits_to_str(&s1, buf, 0, 256)); diff --git a/misc/examples/books.c b/misc/examples/books.c index 96c7ff6e..4695941a 100644 --- a/misc/examples/books.c +++ b/misc/examples/books.c @@ -32,7 +32,7 @@ int main() // When collections store owned values (String), they can still be // queried using references (&str). if (cmap_str_contains(&book_reviews, "Les Misérables")) { - printf("We've got %" c_ZU " reviews, but Les Misérables ain't one.", + printf("We've got %" c_ZI " reviews, but Les Misérables ain't one.", cmap_str_size(&book_reviews)); } diff --git a/misc/examples/complex.c b/misc/examples/complex.c index 6fed1d4d..5c212554 100644 --- a/misc/examples/complex.c +++ b/misc/examples/complex.c @@ -37,7 +37,7 @@ int main() // Put in some data in the structures stack.data[3] = 3.1415927f; - printf("stack size: %" c_ZU "\n", FloatStack_size(&stack)); + printf("stack size: %" c_ZI "\n", FloatStack_size(&stack)); StackList list = StackList_init(); StackList_push_back(&list, stack); diff --git a/misc/examples/csmap_erase.c b/misc/examples/csmap_erase.c index bef00a17..a41a1ad1 100644 --- a/misc/examples/csmap_erase.c +++ b/misc/examples/csmap_erase.c @@ -12,7 +12,7 @@ void printmap(mymap m) { c_FOREACH (elem, mymap, m) printf(" [%d, %s]", elem.ref->first, cstr_str(&elem.ref->second)); - printf("\nsize() == %" c_ZU "\n\n", mymap_size(&m)); + printf("\nsize() == %" c_ZI "\n\n", mymap_size(&m)); } int main() @@ -75,9 +75,9 @@ int main() puts("Starting data of map m3 is:"); printmap(m3); // The 3rd member function removes elements with a given Key - size_t count = mymap_erase(&m3, 2); + int count = mymap_erase(&m3, 2); // The 3rd member function also returns the number of elements removed - printf("The number of elements removed from m3 is: %" c_ZU "\n", count); + printf("The number of elements removed from m3 is: %d\n", count); puts("After the element with a key of 2 is deleted, the map m3 is:"); printmap(m3); } diff --git a/misc/examples/csmap_find.c b/misc/examples/csmap_find.c index a61a47be..201c94e9 100644 --- a/misc/examples/csmap_find.c +++ b/misc/examples/csmap_find.c @@ -18,7 +18,7 @@ void print_elem(csmap_istr_raw p) { #define using_print_collection(CX) \ void print_collection_##CX(const CX* t) { \ - printf("%" c_ZU " elements: ", CX##_size(t)); \ + printf("%" c_ZI " elements: ", CX##_size(t)); \ \ c_FOREACH (p, CX, *t) { \ print_elem(CX##_value_toraw(p.ref)); \ diff --git a/misc/examples/cstr_match.c b/misc/examples/cstr_match.c index 116e5dd4..bfb0df6b 100644 --- a/misc/examples/cstr_match.c +++ b/misc/examples/cstr_match.c @@ -5,8 +5,8 @@ int main() { c_WITH (cstr ss = cstr_lit("The quick brown fox jumps over the lazy dog.JPG"), cstr_drop(&ss)) { - size_t pos = cstr_find_at(&ss, 0, "brown"); - printf("%" c_ZU " [%s]\n", pos, pos == c_NPOS ? "<NULL>" : cstr_str(&ss) + pos); + intptr_t pos = cstr_find_at(&ss, 0, "brown"); + printf("%" c_ZI " [%s]\n", pos, pos == c_NPOS ? "<NULL>" : cstr_str(&ss) + pos); printf("equals: %d\n", cstr_equals(&ss, "The quick brown fox jumps over the lazy dog.JPG")); printf("contains: %d\n", cstr_contains(&ss, "umps ove")); printf("starts_with: %d\n", cstr_starts_with(&ss, "The quick brown")); @@ -16,7 +16,7 @@ int main() cstr s1 = cstr_lit("hell😀 w😀rl🐨"); csview ch1 = cstr_u8_chr(&s1, 7); csview ch2 = cstr_u8_chr(&s1, 10); - printf("%s\nsize: %" c_ZU ", %" c_ZU "\n", cstr_str(&s1), cstr_u8_size(&s1), cstr_size(&s1)); + printf("%s\nsize: %" c_ZI ", %" c_ZI "\n", cstr_str(&s1), cstr_u8_size(&s1), cstr_size(&s1)); printf("ch1: %.*s\n", c_ARGSV(ch1)); printf("ch2: %.*s\n", c_ARGSV(ch2)); } diff --git a/misc/examples/demos.c b/misc/examples/demos.c index 898c24cf..7070d860 100644 --- a/misc/examples/demos.c +++ b/misc/examples/demos.c @@ -175,11 +175,11 @@ void mapdemo3() cmap_str_iter it = cmap_str_find(&table, "Make"); c_FOREACH (i, cmap_str, table) printf("entry: %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second)); - printf("size %" c_ZU ": remove: Make: %s\n", cmap_str_size(&table), cstr_str(&it.ref->second)); + printf("size %" c_ZI ": remove: Make: %s\n", cmap_str_size(&table), cstr_str(&it.ref->second)); //cmap_str_erase(&table, "Make"); cmap_str_erase_at(&table, it); - printf("size %" c_ZU "\n", cmap_str_size(&table)); + printf("size %" c_ZI "\n", cmap_str_size(&table)); c_FOREACH (i, cmap_str, table) printf("entry: %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second)); cmap_str_drop(&table); // frees key and value cstrs, and hash table. diff --git a/misc/examples/forfilter.c b/misc/examples/forfilter.c index fdc013a3..1c64c9e0 100644 --- a/misc/examples/forfilter.c +++ b/misc/examples/forfilter.c @@ -69,7 +69,7 @@ void demo2(void) , c_flt_skipwhile(x, *x.ref != 11) && *x.ref % 2 != 0 , c_flt_take(x, 5)) - IVec_push(&vector, *x.ref * *x.ref); + IVec_push(&vector, (int)(*x.ref * *x.ref)); c_FOREACH (x, IVec, vector) printf(" %d", *x.ref); puts(""); diff --git a/misc/examples/gauss1.c b/misc/examples/gauss1.c index db103945..6b06b4e8 100644 --- a/misc/examples/gauss1.c +++ b/misc/examples/gauss1.c @@ -24,7 +24,7 @@ int main() printf("Demo of gaussian / normal distribution of %d random samples\n", N); // Setup random engine with normal distribution. - uint64_t seed = time(NULL); + uint64_t seed = (uint64_t)time(NULL); stc64_t rng = stc64_new(seed); stc64_normalf_t dist = stc64_normalf_new(Mean, StdDev); diff --git a/misc/examples/gauss2.c b/misc/examples/gauss2.c index c2ed2e00..c627fc91 100644 --- a/misc/examples/gauss2.c +++ b/misc/examples/gauss2.c @@ -18,7 +18,7 @@ int main() printf("Demo of gaussian / normal distribution of %d random samples\n", N); // Setup random engine with normal distribution. - uint64_t seed = time(NULL); + uint64_t seed = (uint64_t)time(NULL); stc64_t rng = stc64_new(seed); stc64_normalf_t dist = stc64_normalf_new(Mean, StdDev); @@ -33,7 +33,7 @@ int main() // Print the gaussian bar chart c_AUTO (cstr, bar) c_FORPAIR (index, count, csmap_int, mhist) { - size_t n = (size_t) (*_.count * StdDev * Scale * 2.5 / (float)N); + int n = (int)((float)*_.count * StdDev * Scale * 2.5f / (float)N); if (n > 0) { cstr_resize(&bar, n, '*'); printf("%4d %s\n", *_.index, cstr_str(&bar)); diff --git a/misc/examples/make.sh b/misc/examples/make.sh index bd1392fc..0c4760a6 100755 --- a/misc/examples/make.sh +++ b/misc/examples/make.sh @@ -7,7 +7,7 @@ if [ "$(uname)" = 'Linux' ]; then fi #cc=gcc; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall $sanitize" -cc=gcc; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall -Wsign-compare -Wwrite-strings" # -Wconversion +cc=gcc; cflags="-s -O2 -std=c99 -Wconversion -Wpedantic -Wall -Wsign-compare -Wwrite-strings" # -Wconversion #cc=tcc; cflags="-Wall -std=c99" #cc=clang; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall -Wsign-compare -Wwrite-strings" #cc=clang; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall -DSTC_CSTR_V1 -DSTC_CSMAP_V1" diff --git a/misc/examples/new_queue.c b/misc/examples/new_queue.c index 828387b5..5c25a229 100644 --- a/misc/examples/new_queue.c +++ b/misc/examples/new_queue.c @@ -22,25 +22,25 @@ int point_cmp(const Point* a, const Point* b) { int main() { int n = 50000000; - stc64_t rng = stc64_new(time(NULL)); + stc64_t rng = stc64_new((uint64_t)time(NULL)); stc64_uniform_t dist = stc64_uniform_new(0, n); c_AUTO (IQ, Q) { // Push 50'000'000 random numbers onto the queue. c_FORRANGE (n) - IQ_push(&Q, stc64_uniform(&rng, &dist)); + IQ_push(&Q, (int)stc64_uniform(&rng, &dist)); // Push or pop on the queue 50 million times - printf("befor: size %" c_ZU ", capacity %" c_ZU "\n", IQ_size(&Q), IQ_capacity(&Q)); + printf("befor: size %" c_ZI ", capacity %" c_ZI "\n", IQ_size(&Q), IQ_capacity(&Q)); c_FORRANGE (n) { - int r = stc64_uniform(&rng, &dist); + int r = (int)stc64_uniform(&rng, &dist); if (r & 3) IQ_push(&Q, r); else IQ_pop(&Q); } - printf("after: size %" c_ZU ", capacity %" c_ZU "\n", IQ_size(&Q), IQ_capacity(&Q)); + printf("after: size %" c_ZI ", capacity %" c_ZI "\n", IQ_size(&Q), IQ_capacity(&Q)); } } diff --git a/misc/examples/prime.c b/misc/examples/prime.c index 5c8d65d3..11c1f1c7 100644 --- a/misc/examples/prime.c +++ b/misc/examples/prime.c @@ -6,19 +6,19 @@ #include <stc/algo/crange.h> -cbits sieveOfEratosthenes(size_t n) +cbits sieveOfEratosthenes(intptr_t n) { cbits bits = cbits_with_size(n/2 + 1, true); - size_t q = (size_t) sqrt((double) n) + 1; - for (size_t i = 3; i < q; i += 2) { - size_t j = i; + intptr_t q = (intptr_t)sqrt((double) n) + 1; + for (intptr_t i = 3; i < q; i += 2) { + intptr_t j = i; for (; j < n; j += 2) { if (cbits_test(&bits, j>>1)) { i = j; break; } } - for (size_t j = i*i; j < n; j += i*2) + for (intptr_t j = i*i; j < n; j += i*2) cbits_reset(&bits, j>>1); } return bits; @@ -26,16 +26,16 @@ cbits sieveOfEratosthenes(size_t n) int main(void) { - size_t n = 1000000000; - printf("computing prime numbers up to %" c_ZU "\n", n); + intptr_t n = 1000000000; + printf("computing prime numbers up to %" c_ZI "\n", n); clock_t t1 = clock(); c_WITH (cbits primes = sieveOfEratosthenes(n + 1), cbits_drop(&primes)) { puts("done"); - size_t np = cbits_count(&primes); + intptr_t np = cbits_count(&primes); clock_t t2 = clock(); - printf("number of primes: %" c_ZU ", time: %f\n", np, (t2 - t1) / (float)CLOCKS_PER_SEC); + printf("number of primes: %" c_ZI ", time: %f\n", np, (float)(t2 - t1) / (float)CLOCKS_PER_SEC); puts("Show all the primes in the range [2, 1000):"); printf("2"); c_FORRANGE (i, 3, 1000, 2) diff --git a/misc/examples/priority.c b/misc/examples/priority.c index 22da6f60..f39c0634 100644 --- a/misc/examples/priority.c +++ b/misc/examples/priority.c @@ -9,13 +9,13 @@ #include <stc/cpque.h> int main() { - size_t N = 10000000; - stc64_t rng = stc64_new(time(NULL)); + intptr_t N = 10000000; + stc64_t rng = stc64_new((uint64_t)time(NULL)); stc64_uniform_t dist = stc64_uniform_new(0, N * 10); c_AUTO (cpque_i, heap) { // Push ten million random numbers to priority queue - printf("Push %" c_ZU " numbers\n", N); + printf("Push %" c_ZI " numbers\n", N); c_FORRANGE (N) cpque_i_push(&heap, stc64_uniform(&rng, &dist)); diff --git a/misc/examples/queue.c b/misc/examples/queue.c index 1d325fc6..ee537b58 100644 --- a/misc/examples/queue.c +++ b/misc/examples/queue.c @@ -15,17 +15,17 @@ int main() { { // Push ten million random numbers onto the queue. c_FORRANGE (n) - cqueue_i_push(&queue, stc64_uniform(&rng, &dist)); + cqueue_i_push(&queue, (int)stc64_uniform(&rng, &dist)); // Push or pop on the queue ten million times printf("%d\n", n); c_FORRANGE (n) { // forrange uses initial n only. - int r = stc64_uniform(&rng, &dist); + int r = (int)stc64_uniform(&rng, &dist); if (r & 1) ++n, cqueue_i_push(&queue, r); else --n, cqueue_i_pop(&queue); } - printf("%d, %" c_ZU "\n", n, cqueue_i_size(&queue)); + printf("%d, %" c_ZI "\n", n, cqueue_i_size(&queue)); } } diff --git a/misc/examples/random.c b/misc/examples/random.c index 82214924..fc4576dd 100644 --- a/misc/examples/random.c +++ b/misc/examples/random.c @@ -5,10 +5,10 @@ int main() { const size_t N = 1000000000; - const uint64_t seed = time(NULL), range = 1000000; + const uint64_t seed = (uint64_t)time(NULL), range = 1000000; stc64_t rng = stc64_new(seed); - uint64_t sum; + int64_t sum; clock_t diff, before; printf("Compare speed of full and unbiased ranged random numbers...\n"); @@ -18,8 +18,8 @@ int main() sum += (uint32_t)stc64_rand(&rng); } diff = clock() - before; - printf("full range\t\t: %f secs, %" c_ZU ", avg: %f\n", - (float)diff / CLOCKS_PER_SEC, N, (double)sum / N); + printf("full range\t\t: %f secs, %" c_ZI ", avg: %f\n", + (float)diff / CLOCKS_PER_SEC, N, (float)sum / (float)N); stc64_uniform_t dist1 = stc64_uniform_new(0, range); rng = stc64_new(seed); @@ -29,17 +29,17 @@ int main() sum += stc64_uniform(&rng, &dist1); // unbiased } diff = clock() - before; - printf("unbiased 0-%" PRIu64 "\t: %f secs, %" c_ZU ", avg: %f\n", - range, (float)diff/CLOCKS_PER_SEC, N, (double)sum / N); + printf("unbiased 0-%" PRIu64 "\t: %f secs, %" c_ZI ", avg: %f\n", + range, (float)diff/CLOCKS_PER_SEC, N, (float)sum / (float)N); sum = 0; rng = stc64_new(seed); before = clock(); c_FORRANGE (N) { - sum += stc64_rand(&rng) % (range + 1); // biased + sum += (int64_t)(stc64_rand(&rng) % (range + 1)); // biased } diff = clock() - before; - printf("biased 0-%" PRIu64 " \t: %f secs, %" c_ZU ", avg: %f\n", - range, (float)diff / CLOCKS_PER_SEC, N, (double)sum / N); + printf("biased 0-%" PRIu64 " \t: %f secs, %" c_ZI ", avg: %f\n", + range, (float)diff / CLOCKS_PER_SEC, N, (float)sum / (float)N); } diff --git a/misc/examples/regex_match.c b/misc/examples/regex_match.c index 93b83651..b7d6ed3a 100644 --- a/misc/examples/regex_match.c +++ b/misc/examples/regex_match.c @@ -1,6 +1,7 @@ #define i_extern #include <stc/cregex.h> #include <stc/csview.h> + #define i_val float #include <stc/cstack.h> @@ -22,7 +23,7 @@ int main() // extract and convert all numbers in str to floats c_FORMATCH (i, &re, str) - cstack_float_push(&vec, atof(i.match[0].str)); + cstack_float_push(&vec, (float)atof(i.match[0].str)); c_FOREACH (i, cstack_float, vec) printf(" %g\n", *i.ref); diff --git a/misc/examples/sort.c b/misc/examples/sort.c index de94cede..65077143 100644 --- a/misc/examples/sort.c +++ b/misc/examples/sort.c @@ -14,7 +14,7 @@ #define fmt_Elem "%lld" -int testsort(csort_elm_value *a, size_t size, const char *desc) { +int testsort(csort_elm_value *a, long size, const char *desc) { clock_t t = clock(); #ifdef __cplusplus printf("std::sort: "); @@ -26,13 +26,13 @@ int testsort(csort_elm_value *a, size_t size, const char *desc) { t = clock() - t; printf("%s: %d elements sorted in %.2f ms\n", - desc, (int)size, t*1000.0/CLOCKS_PER_SEC); + desc, (int)size, (float)t*1000.0f/CLOCKS_PER_SEC); return 0; } int main(int argc, char *argv[]) { - size_t i, size = argc > 1 ? strtoull(argv[1], NULL, 0) : 10000000; - csort_elm_value *a = (csort_elm_value*)malloc(sizeof(*a) * size); + long i, size = argc > 1 ? strtol(argv[1], NULL, 0) : 10000000; + csort_elm_value *a = (csort_elm_value*)c_malloc(c_sizeof(*a) * size); if (a == NULL) return -1; for (i = 0; i < size; i++) diff --git a/misc/examples/sso_map.c b/misc/examples/sso_map.c index f88e5f79..0841a316 100644 --- a/misc/examples/sso_map.c +++ b/misc/examples/sso_map.c @@ -10,7 +10,7 @@ int main() cmap_str_emplace(&m, "Test long ", "This is a longer string"); c_FORPAIR (k, v, cmap_str, m) - printf("%s: '%s' Len=%" c_ZU ", Is long: %s\n", + printf("%s: '%s' Len=%" c_ZI ", Is long: %s\n", cstr_str(_.k), cstr_str(_.v), cstr_size(_.v), cstr_is_long(_.v) ? "true" : "false"); } diff --git a/misc/examples/sso_substr.c b/misc/examples/sso_substr.c index be372a8d..7e858ec4 100644 --- a/misc/examples/sso_substr.c +++ b/misc/examples/sso_substr.c @@ -6,7 +6,7 @@ int main () { cstr str = cstr_lit("We think in generalities, but we live in details."); csview sv1 = cstr_substr_ex(&str, 3, 5); // "think" - size_t pos = cstr_find(&str, "live"); // position of "live" + intptr_t pos = cstr_find(&str, "live"); // position of "live" csview sv2 = cstr_substr_ex(&str, pos, 4); // "live" csview sv3 = cstr_slice_ex(&str, -8, -1); // "details" printf("%.*s, %.*s, %.*s\n", c_ARGSV(sv1), c_ARGSV(sv2), c_ARGSV(sv3)); diff --git a/misc/examples/utf8replace_c.c b/misc/examples/utf8replace_c.c index 2d8d1921..3f98a2a6 100644 --- a/misc/examples/utf8replace_c.c +++ b/misc/examples/utf8replace_c.c @@ -16,11 +16,8 @@ int main() { c_FOREACH (c, cstr, hello) printf("%.*s,", c_ARGSV(c.u8.chr)); - //csview sv = c_SV("If you find the time, you will find the winner"); - //str = cstr_replace_sv(sv, c_SV("find"), c_SV("match"), 0); - - str = cstr_lit("If you find the time, you will find the winner"); - cstr_replace(&str, "find", "match"); + str = cstr_lit("scooby, dooby doo"); + cstr_replace(&str, "oo", "00"); printf("\n%s\n", cstr_str(&str)); } } diff --git a/src/cregex.c b/src/cregex.c index 1876e860..c17e1967 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -78,7 +78,7 @@ typedef struct _Reprog { _Reinst *startinst; /* start pc */ _Reflags flags; - unsigned nsubids; + int nsubids; _Reclass cclass[_NCLASS]; /* .data */ _Reinst firstinst[]; /* .text : originally 5 elements? */ } _Reprog; @@ -246,13 +246,13 @@ utfruneicase(const char *s, _Rune c) * save a new match in mp */ static void -_renewmatch(_Resub *mp, unsigned ms, _Resublist *sp, unsigned nsubids) +_renewmatch(_Resub *mp, int ms, _Resublist *sp, int nsubids) { if (mp==NULL || ms==0) return; if (mp[0].str == NULL || sp->m[0].str < mp[0].str || (sp->m[0].str == mp[0].str && sp->m[0].size > mp[0].size)) { - for (unsigned i=0; i<ms && i<=nsubids; i++) + for (int i=0; i<ms && i<=nsubids; i++) mp[i] = sp->m[i]; } } @@ -265,7 +265,7 @@ _renewmatch(_Resub *mp, unsigned ms, _Resublist *sp, unsigned nsubids) static _Relist* _renewthread(_Relist *lp, /* _relist to add to */ _Reinst *ip, /* instruction to add */ - unsigned ms, + int ms, _Resublist *sep) /* pointers to subexpressions */ { _Relist *p; @@ -297,7 +297,7 @@ _renewthread(_Relist *lp, /* _relist to add to */ static _Relist* _renewemptythread(_Relist *lp, /* _relist to add to */ _Reinst *ip, /* instruction to add */ - unsigned ms, + int ms, const char *sp) /* pointers to subexpressions */ { _Relist *p; @@ -895,7 +895,7 @@ _regcomp1(_Reprog *progp, _Parser *par, const char *s, int cflags) pp->startinst = par->andp->first; pp = _optimize(par, pp); - pp->nsubids = (unsigned)par->cursubid; + pp->nsubids = par->cursubid; out: if (par->error) { c_free(pp); @@ -910,20 +910,20 @@ _runematch(_Rune s, _Rune r) { int inv = 0, n; switch (s) { - case ASC_D: inv = 1; case ASC_d: return inv ^ (isdigit(r) != 0); - case ASC_S: inv = 1; case ASC_s: return inv ^ (isspace(r) != 0); - case ASC_W: inv = 1; case ASC_w: return inv ^ ((isalnum(r) != 0) | (r == '_')); - case ASC_AL: inv = 1; case ASC_al: return inv ^ (isalpha(r) != 0); - case ASC_AN: inv = 1; case ASC_an: return inv ^ (isalnum(r) != 0); + case ASC_D: inv = 1; case ASC_d: return inv ^ (isdigit((int)r) != 0); + case ASC_S: inv = 1; case ASC_s: return inv ^ (isspace((int)r) != 0); + case ASC_W: inv = 1; case ASC_w: return inv ^ ((isalnum((int)r) != 0) | (r == '_')); + case ASC_AL: inv = 1; case ASC_al: return inv ^ (isalpha((int)r) != 0); + case ASC_AN: inv = 1; case ASC_an: return inv ^ (isalnum((int)r) != 0); case ASC_AS: return (r >= 128); case ASC_as: return (r < 128); case ASC_BL: inv = 1; case ASC_bl: return inv ^ ((r == ' ') | (r == '\t')); - case ASC_CT: inv = 1; case ASC_ct: return inv ^ (iscntrl(r) != 0); - case ASC_GR: inv = 1; case ASC_gr: return inv ^ (isgraph(r) != 0); - case ASC_PR: inv = 1; case ASC_pr: return inv ^ (isprint(r) != 0); - case ASC_PU: inv = 1; case ASC_pu: return inv ^ (ispunct(r) != 0); - case ASC_LO: inv = 1; case ASC_lo: return inv ^ (islower(r) != 0); - case ASC_UP: inv = 1; case ASC_up: return inv ^ (isupper(r) != 0); - case ASC_XD: inv = 1; case ASC_xd: return inv ^ (isxdigit(r) != 0); + case ASC_CT: inv = 1; case ASC_ct: return inv ^ (iscntrl((int)r) != 0); + case ASC_GR: inv = 1; case ASC_gr: return inv ^ (isgraph((int)r) != 0); + case ASC_PR: inv = 1; case ASC_pr: return inv ^ (isprint((int)r) != 0); + case ASC_PU: inv = 1; case ASC_pu: return inv ^ (ispunct((int)r) != 0); + case ASC_LO: inv = 1; case ASC_lo: return inv ^ (islower((int)r) != 0); + case ASC_UP: inv = 1; case ASC_up: return inv ^ (isupper((int)r) != 0); + case ASC_XD: inv = 1; case ASC_xd: return inv ^ (isxdigit((int)r) != 0); case UTF_AN: inv = 1; case UTF_an: return inv ^ utf8_isalnum(r); case UTF_BL: inv = 1; case UTF_bl: return inv ^ utf8_isblank(r); case UTF_SP: inv = 1; case UTF_sp: return inv ^ utf8_isspace(r); @@ -966,7 +966,7 @@ static int _regexec1(const _Reprog *progp, /* program to run */ const char *bol, /* string to run machine on */ _Resub *mp, /* subexpression elements */ - unsigned ms, /* number of elements at mp */ + int ms, /* number of elements at mp */ _Reljunk *j, int mflags ) @@ -979,7 +979,7 @@ _regexec1(const _Reprog *progp, /* program to run */ const char *s, *p; _Rune r, *rp, *ep; int n, checkstart, match = 0; - unsigned i; + int i; bool icase = progp->flags.icase; checkstart = j->starttype; @@ -1123,7 +1123,7 @@ static int _regexec2(const _Reprog *progp, /* program to run */ const char *bol, /* string to run machine on */ _Resub *mp, /* subexpression elements */ - unsigned ms, /* number of elements at mp */ + int ms, /* number of elements at mp */ _Reljunk *j, int mflags ) @@ -1149,7 +1149,7 @@ _regexec2(const _Reprog *progp, /* program to run */ static int _regexec(const _Reprog *progp, /* program to run */ const char *bol, /* string to run machine on */ - unsigned ms, /* number of elements at mp */ + int ms, /* number of elements at mp */ _Resub mp[], /* subexpression elements */ int mflags) { @@ -1195,7 +1195,7 @@ _regexec(const _Reprog *progp, /* program to run */ static void -_build_subst(const char* replace, unsigned nmatch, const csview match[], +_build_subst(const char* replace, int nmatch, const csview match[], bool (*mfun)(int, csview, cstr*), cstr* subst) { cstr_buf buf = cstr_buffer(subst); intptr_t len = 0, cap = buf.cap; @@ -1216,7 +1216,7 @@ _build_subst(const char* replace, unsigned nmatch, const csview match[], csview m = mfun && mfun(g, match[g], &mstr) ? cstr_sv(&mstr) : match[g]; if (len + m.size > cap) dst = cstr_reserve(subst, cap = cap*3/2 + m.size); - for (unsigned i = 0; i < m.size; ++i) + for (int i = 0; i < (int)m.size; ++i) dst[len++] = m.str[i]; } ++replace; @@ -1244,9 +1244,9 @@ cregex_compile_3(cregex *self, const char* pattern, int cflags) { return self->error = par.error; } -unsigned +int cregex_captures(const cregex* self) { - return self->prog ? 1U + self->prog->nsubids : 0U; + return self->prog ? 1 + self->prog->nsubids : 0; } int @@ -1271,13 +1271,13 @@ cregex_find_pattern_4(const char* pattern, const char* input, } cstr -cregex_replace_sv_6(const cregex* re, csview input, const char* replace, unsigned count, +cregex_replace_sv_6(const cregex* re, csview input, const char* replace, int count, bool (*mfun)(int, csview, cstr*), int rflags) { cstr out = cstr_NULL; cstr subst = cstr_NULL; csview match[CREG_MAX_CAPTURES]; - unsigned nmatch = cregex_captures(re); - if (!count) count = ~0U; + int nmatch = cregex_captures(re); + if (!count) count = INT32_MAX; bool copy = !(rflags & CREG_R_STRIP); while (count-- && cregex_find_sv(re, input, match) == CREG_OK) { @@ -1294,7 +1294,7 @@ cregex_replace_sv_6(const cregex* re, csview input, const char* replace, unsigne } cstr -cregex_replace_pattern_6(const char* pattern, const char* input, const char* replace, unsigned count, +cregex_replace_pattern_6(const char* pattern, const char* input, const char* replace, int count, bool (*mfun)(int, csview, cstr*), int crflags) { cregex re = cregex_init(); if (cregex_compile(&re, pattern, crflags) != CREG_OK) diff --git a/src/utf8code.c b/src/utf8code.c index 351ddab5..a892f5fd 100644 --- a/src/utf8code.c +++ b/src/utf8code.c @@ -20,7 +20,7 @@ const uint8_t utf8_dtab[] = { 12,36,12,12,12,12,12,12,12,12,12,12, }; -unsigned utf8_encode(char *out, uint32_t c) +int utf8_encode(char *out, uint32_t c) { if (c < 0x80U) { out[0] = (char) c; @@ -143,7 +143,7 @@ bool utf8_isalpha(uint32_t c) { static int16_t groups[] = {U8G_Latin, U8G_Nl, U8G_Greek, U8G_Cyrillic, U8G_Han, U8G_Devanagari, U8G_Arabic}; if (c < 128) return isalpha((int)c) != 0; - for (unsigned j=0; j < c_ARRAYLEN(groups); ++j) + for (int j=0; j < c_ARRAYLEN(groups); ++j) if (utf8_isgroup(groups[j], c)) return true; return false; |
