From 6b5b7c9060f4e317ed5463772369e727fcfeeb05 Mon Sep 17 00:00:00 2001 From: Kirill Petrashin Date: Sun, 29 Mar 2026 15:39:50 +0300 Subject: Implement ppq_remove() (possibly buggy idk) --- priority_queue.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'priority_queue.c') diff --git a/priority_queue.c b/priority_queue.c index de6c179..6460a9e 100644 --- a/priority_queue.c +++ b/priority_queue.c @@ -67,6 +67,32 @@ Position ppq_pop(PositionPQ **ppq) { return pos; } +void ppq_remove(PositionPQ **ppq, Position pos) { + PositionPQ *temp = *ppq; + + if (temp == NULL) { + error("Tried to remove a pos from a NULL PositionPQ\n"); + } + + PositionPQ *prev = NULL; + + while (temp->next != NULL && (pos.x != temp->pos.x || pos.y != temp->pos.y)) { + prev = temp; + temp = temp->next; + } + + if (pos.x == temp->pos.x && pos.y == temp->pos.y) { + if (prev != NULL) { + prev->next = temp->next; + free(temp); + } else { + prev = *ppq; + *ppq = (*ppq)->next; + free(prev); + } + } +} + void ppq_reprioritize(PositionPQ *ppq, Position pos, size_t priority) { (void)ppq, (void)pos, (void)priority; todo(); -- cgit v1.2.3