// Copyright (c) 2023, Marvin Borner // SPDX-License-Identifier: MIT #include #include #include #include #include #include #include static struct pqueue *queue; static pqueue_pri_t get_pri(void *a) { struct term *term = a; return (parse_get_max_depth() - term->depth + 1) * term->refs; } static int cmp_pri(pqueue_pri_t next, pqueue_pri_t curr) { return next < curr; } static void set_pos(void *a, size_t position) { (void)a; (void)position; } // skewed random number generator // prefers smaller numbers static size_t choose_position(void) { size_t size = pqueue_size(queue); return size - (size_t)sqrt(((size_t)rand() % (size_t)pow(size, 2))); } void schedule(void) { while (pqueue_size(queue) > 0) { size_t position = choose_position(); struct term *term = pqueue_pop_at(queue, position); // TODO: reduce term } } void schedule_init(void) { srand(time(0)); queue = map_to_pqueue(cmp_pri, get_pri, set_pos); } void schedule_destroy(void) { pqueue_free(queue); }