14#define MAX_UP_TO 100000
17#define CAPACITY 300000
18#define NAME bump_alloc
22#define ALLOC bump_alloc
27 if (n == 0 || n == 1) {
34 while (left <= right) {
35 mid = left + (right - left) / 2;
36 size_t square = mid * mid;
54 sieve_vec_iter_const iter = sieve_vec_get_iter_const(sieve);
56 sieve_vec_iter_const_next(&iter);
57 sieve_vec_iter_const_next(&iter);
60 bool const* is_not_prime;
61 while ((is_not_prime = sieve_vec_iter_const_next(&iter))) {
70 size_t size = sieve_vec_size(sieve);
73 for (
size_t factor = 2; factor <= sqrt; factor++) {
74 for (
size_t index = factor * 2; index <
size; index += factor) {
75 DC_LOG(*log,
DC_DEBUG,
"marking %zu as not prime (factor: %zu)", index, factor);
76 *sieve_vec_write(sieve, index) =
true;
91 bump_alloc_buffer buf;
92 bump_alloc alloc = bump_alloc_new(&buf, stdalloc_get_ref());
93 sieve_vec values = sieve_vec_new_with_defaults(up_to,
false, &alloc);
98 sieve_vec_delete(&values);
104 new_global)((
NS(
DC_LOGGER, global_config)){.stream = stdout, .ansi_colours =
true},
static DC_PUBLIC size_t size(SELF const *self)
static dc_cpu_features dc_cpu_features_get()
static DC_PUBLIC void dc_cpu_features_debug(dc_cpu_features const *self, dc_debug_fmt fmt, FILE *stream)
#define DC_DEBUG(DEBUG_FN, DEBUG_PTR)
#define DC_ASSERT(expr,...)
static size_t sqrt_size_t(size_t n)
static void example_prime_sieve(DC_LOGGER *parent)
static void compute(sieve_vec *sieve, DC_LOGGER *log)
static void display(sieve_vec const *sieve, DC_LOGGER *log)
#define DC_SCOPED(type,...)
RAII in C. Call the destructor when the variable goes out of scope.
#define DC_LOGGER_NEW(...)