aboutsummaryrefslogtreecommitdiff
path: root/priority_queue.c
diff options
context:
space:
mode:
Diffstat (limited to 'priority_queue.c')
-rw-r--r--priority_queue.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/priority_queue.c b/priority_queue.c
index 472f5c3..d2517a6 100644
--- a/priority_queue.c
+++ b/priority_queue.c
@@ -12,35 +12,40 @@ PositionPQ *ppq_new(Position pos, size_t priority) {
return ppq;
}
-/* FIXME: this is shitty */
-void ppq_insert(PositionPQ **ppq, Position pos, size_t priority) {
+/* FIXME: insted of `return n` introduce some defines with error codes,
+ * or an enum I don't care */
+int ppq_insert(PositionPQ **ppq, Position pos, size_t priority) {
+ //printf("Inserting %zu %zu\n", pos.x, pos.y);
PositionPQ *start = *ppq;
if ((*ppq) == NULL) {
(*ppq) = ppq_new(pos, priority);
- return;
+ return 1;
}
PositionPQ *n = ppq_new(pos, priority);
if (start->priority > priority) {
n->next = start;
start = n;
- return;
+ return 2;
}
PositionPQ *temp = *ppq;
while(temp->next != NULL && temp->next->priority <= priority) {
if (temp->pos.x == pos.x && temp->pos.y == pos.y && temp->priority <= priority) {
- return; /* pos is already at the start of ppq with a fine priority */
+ return 3; /* pos is already in ppq with a fine priority */
}
temp = temp->next;
}
+ if (temp->pos.x == pos.x && temp->pos.y == pos.y && temp->priority <= priority) {
+ return 3; /* pos is already in ppq with a fine priority */
+ }
n->next = temp->next;
temp->next = n;
- return;
+ return 4;
}
Position ppq_pop(PositionPQ **ppq) {