1
#ifndef PRIORITY_QUEUE_H
2
#define PRIORITY_QUEUE_H
3
#include "LinkedList.h"
4
struct PriorityQueue_struct {
5
/* a simple priority queue structure: entries are all integers, gains are all integers in [0, gainmax], total n elements */
6
int count;/* how many entries are in?*/
8
/* max index value of an entry */
11
/* only ngain buckets are allowed */
14
/* current highest gain */
17
/* the ngain buckets. Each bucket i holds all entries with gain = i.*/
18
DoubleLinkedList *buckets;
20
/* a mapping which maps an entry's index to an element in a DoubleLinkedList */
21
DoubleLinkedList *where;
23
/* the gain of entry i is gain[i] */
27
typedef struct PriorityQueue_struct *PriorityQueue;
30
PriorityQueue PriorityQueue_new(int n, int ngain);
32
void PriorityQueue_delete(PriorityQueue q);
34
/* if entry i is already in the list, then an update of gain is carried out*/
35
PriorityQueue PriorityQueue_push(PriorityQueue q, int i, int gain);
37
int PriorityQueue_pop(PriorityQueue q, int *i, int *gain);/* return 0 if nmothing left, 1 otherwise */
39
int PriorityQueue_remove(PriorityQueue q, int i);/* return 0 if error */
40
int PriorityQueue_get_gain(PriorityQueue q, int i);