aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-03-29 15:39:50 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-03-29 15:39:50 +0300
commit6b5b7c9060f4e317ed5463772369e727fcfeeb05 (patch)
tree10f076f4eec5acfea6c505c41d3dbf2db08e522b
parent40d4d279e41c336d5c4e9a1e07c7751bc76ecbfb (diff)
downloadastar-6b5b7c9060f4e317ed5463772369e727fcfeeb05.tar.xz
Implement ppq_remove() (possibly buggy idk)
-rw-r--r--priority_queue.c26
-rw-r--r--priority_queue.h3
2 files changed, 29 insertions, 0 deletions
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();
diff --git a/priority_queue.h b/priority_queue.h
index c121487..241dcc7 100644
--- a/priority_queue.h
+++ b/priority_queue.h
@@ -25,6 +25,9 @@ int ppq_insert(PositionPQ **ppq, Position pos, size_t priority);
/* Remove and return the position with the lowest priority */
Position ppq_pop(PositionPQ **ppq);
+/* Remove a given pos fron ppq */
+void ppq_remove(PositionPQ **ppq, Position pos);
+
/* Change the priority of a given pos, moving it to a different place in the
* linked list ("POTENTIALLY NOT NEEDED" since we don't use different weights */
void ppq_reprioritize(PositionPQ *ppq, Position pos, size_t priority);