summaryrefslogtreecommitdiffhomepage
path: root/docs/cbits_api.md
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-04 23:35:56 +0100
committerGitHub <[email protected]>2023-02-04 23:35:56 +0100
commitadc47cefc2976768c3f0b773bd26bfd1062e8a53 (patch)
tree4923f88afb0d091d5d39ae03d65a4998a0517652 /docs/cbits_api.md
parent0c4c4f8bba17562735b67b2923cd23c773aa53a7 (diff)
parentd2ff84c53aa9bd3857fdf22dcf7cd9398a4780be (diff)
downloadSTC-modified-adc47cefc2976768c3f0b773bd26bfd1062e8a53.tar.gz
STC-modified-adc47cefc2976768c3f0b773bd26bfd1062e8a53.zip
Merge pull request #46 from tylov/newinit
Version 4.1 RC2: signed sizes and indices, cspan with numpy slicing.
Diffstat (limited to 'docs/cbits_api.md')
-rw-r--r--docs/cbits_api.md90
1 files changed, 45 insertions, 45 deletions
diff --git a/docs/cbits_api.md b/docs/cbits_api.md
index b21611df..60586a5b 100644
--- a/docs/cbits_api.md
+++ b/docs/cbits_api.md
@@ -19,40 +19,40 @@ All cbits definitions and prototypes are available by including a single header
## Methods
```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_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_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
-
-bool cbits_test(const cbits* self, size_t i);
-bool cbits_at(const cbits* self, size_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);
-
-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_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_intersect(cbits* self, const cbits* other);
-void cbits_union(cbits* self, const cbits* other);
-void cbits_xor(cbits* self, const cbits* other); // set of disjoint bits
+cbits cbits_init(void);
+cbits cbits_from(const char* str);
+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, 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
+
+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, 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, intptr_t start, intptr_t stop);
+
+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, intptr_t i);
+
+void cbits_intersect(cbits* self, const cbits* other);
+void cbits_union(cbits* self, const cbits* other);
+void cbits_xor(cbits* self, const cbits* other); // set of disjoint bits
```
## Types
@@ -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);