aboutsummaryrefslogtreecommitdiff
path: root/priority_queue.h
blob: 13eea1a7532dec0db8bb3b71859de7a9a5e2c023 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#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 
 * UPDATE: we do need *prev. */
struct PositionPQNode_s {
    Position pos;
    size_t priority; /* Lower is "better" */
    struct PositionPQNode_s *prev;
    struct PositionPQNode_s *next;
};

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 */
#define PPQ_INSERT_SUCCESS 0
#define PPQ_INSERT_NEW 1 /* ppq was NULL, created a new one */
#define PPQ_INSERT_ALREADY 2 /* pos is already in ppq */
int ppq_insert(PositionPQ **ppq, Position pos, size_t priority);

/* Remove and return the position with the lowest priority */
Position ppq_pop(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);

void ppq_print(PositionPQ *ppq);

void ppq_free(PositionPQ *ppq);

#endif /* PRIORITY_QUEUE_H_ */