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 /misc | |
| parent | b677a0c3950b8294ba6458e682a885351273ac08 (diff) | |
| download | STC-modified-6ce6ef3307e52db5813d3c8d6a2cba52df06daf8.tar.gz STC-modified-6ce6ef3307e52db5813d3c8d6a2cba52df06daf8.zip | |
Massive update from unsigned sizes and indices to signed.
Diffstat (limited to 'misc')
| -rw-r--r-- | misc/archived/cstr.h | 4 | ||||
| -rw-r--r-- | misc/examples/astar.c | 4 | ||||
| -rw-r--r-- | misc/examples/birthday.c | 6 | ||||
| -rw-r--r-- | misc/examples/bits.c | 12 | ||||
| -rw-r--r-- | misc/examples/bits2.c | 4 | ||||
| -rw-r--r-- | misc/examples/books.c | 2 | ||||
| -rw-r--r-- | misc/examples/complex.c | 2 | ||||
| -rw-r--r-- | misc/examples/csmap_erase.c | 6 | ||||
| -rw-r--r-- | misc/examples/csmap_find.c | 2 | ||||
| -rw-r--r-- | misc/examples/cstr_match.c | 6 | ||||
| -rw-r--r-- | misc/examples/demos.c | 4 | ||||
| -rw-r--r-- | misc/examples/forfilter.c | 2 | ||||
| -rw-r--r-- | misc/examples/gauss1.c | 2 | ||||
| -rw-r--r-- | misc/examples/gauss2.c | 4 | ||||
| -rwxr-xr-x | misc/examples/make.sh | 2 | ||||
| -rw-r--r-- | misc/examples/new_queue.c | 10 | ||||
| -rw-r--r-- | misc/examples/prime.c | 18 | ||||
| -rw-r--r-- | misc/examples/priority.c | 6 | ||||
| -rw-r--r-- | misc/examples/queue.c | 6 | ||||
| -rw-r--r-- | misc/examples/random.c | 18 | ||||
| -rw-r--r-- | misc/examples/regex_match.c | 3 | ||||
| -rw-r--r-- | misc/examples/sort.c | 8 | ||||
| -rw-r--r-- | misc/examples/sso_map.c | 2 | ||||
| -rw-r--r-- | misc/examples/sso_substr.c | 2 | ||||
| -rw-r--r-- | misc/examples/utf8replace_c.c | 7 |
25 files changed, 70 insertions, 72 deletions
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)); } } |
