diff options
| author | Kirill Petrashin <kirill8201@yandex.ru> | 2026-03-14 20:29:41 +0300 |
|---|---|---|
| committer | Kirill Petrashin <kirill8201@yandex.ru> | 2026-03-14 20:29:41 +0300 |
| commit | 8d165ccf784dd7a3afe35b68339f2b536591362c (patch) | |
| tree | ae83b4e294a01d46590765574f03868fdb42194b /priority_queue.h | |
| parent | 0a2e9c66d9218b9ae850e3f4c3346e299f6d6b6e (diff) | |
Draft the priority queue
Diffstat (limited to 'priority_queue.h')
| -rw-r--r-- | priority_queue.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/priority_queue.h b/priority_queue.h new file mode 100644 index 0000000..45252a8 --- /dev/null +++ b/priority_queue.h @@ -0,0 +1,31 @@ +#ifndef PRIORITY_QUEUE_H_ +#define PRIORITY_QUEUE_H_ + +#include "structs.h" + +/* This is basically a sorted linked list + * Not sure if we need *prev, to be fair */ +struct PositionPQNode_s { + Position pos; + size_t priority; /* Lower is "better" */ + struct PositionPQNode_s *prev; + struct PositionPQNode_s *next; +} PositionPQNode_s; + +typedef struct PositionPQNode_s PositionPQ; + +/* Create a new PositionPQ with pos and priority */ +PositionPQ ppq_new(Position pos, size_t priority); + +/* Insert a pos with priority into a given PositionPQ */ +void ppq_insert(PositionPQ ppq, Position pos, size_t priority); + +/* Remove and return the position with the lowest priority */ +Position ppq_remove(PositionPQ ppq); + +/* 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); + + +#endif /* PRIORITY_QUEUE_H_ */ |
