aboutsummaryrefslogtreecommitdiff
path: root/src/schedule.c
diff options
context:
space:
mode:
authorMarvin Borner2023-05-27 09:44:14 +0200
committerMarvin Borner2023-05-27 09:44:14 +0200
commit337ec809393b709b36ca7b64d77489ae4bc1af1c (patch)
tree4e6eb71eaa8e81c4b08b8d23938e1609ff5d91a6 /src/schedule.c
parentac039e6fcbdec3dc6c8e28013e1b3a20068c84ee (diff)
More scheduling and probabilisticity
Diffstat (limited to 'src/schedule.c')
-rw-r--r--src/schedule.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/schedule.c b/src/schedule.c
index e746a7f..dda08f3 100644
--- a/src/schedule.c
+++ b/src/schedule.c
@@ -1,6 +1,10 @@
// Copyright (c) 2023, Marvin Borner <dev@marvinborner.de>
// SPDX-License-Identifier: MIT
+#include <math.h>
+#include <time.h>
+#include <stdlib.h>
+
#include <schedule.h>
#include <lib/pqueue.h>
#include <parse.h>
@@ -25,8 +29,26 @@ static void set_pos(void *a, size_t position)
(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);
}