-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoundedPriorityQueue.h
110 lines (99 loc) 路 4 KB
/
BoundedPriorityQueue.h
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef BOUNDEDPRIORITYQUEUE_H_DEFINED
#define BOUNDEDPRIORITYQUEUE_H_DEFINED
#include <stddef.h>
#include <stdbool.h>
/* Opaque structure of a bounded priority queue */
typedef struct bounded_priority_queue_t BoundedPriorityQueue;
/* ------------------------------------------------------------------------- *
* Create a bounded priority queue.
*
* PARAMETERS
* capacity Maximum number of element that can be stored in the queue.
*
* NOTE
* The returned structure should be cleaned with `bpqFree` after
* usage.
*
* RETURN
* bpq The bounded priority queue.
* ------------------------------------------------------------------------- */
BoundedPriorityQueue *bpqCreate(size_t capacity);
/* ------------------------------------------------------------------------- *
* Free the memory allocated for the bounded priority queue.
*
* PARAMETERS
* bpq The bounded priority queue to free
* ------------------------------------------------------------------------- */
void bpqFree(BoundedPriorityQueue *bpq);
/* ------------------------------------------------------------------------- *
* Insert a key/value pair in the priority queue. If the queue is full,
* the element is not added.
*
*
* PARAMETERS
* bpq The bounded priority queue
* key A key...
* value ... and its associated value
*
* RETURN
* opened True if the element was successfully added, false if the
* queue is full
* ------------------------------------------------------------------------- */
bool bpqInsert(BoundedPriorityQueue *bpq, double key, size_t value);
/* ------------------------------------------------------------------------- *
* Replace the element with maximum key with a new key/value pair. The queue
* must contain at least one element (otherwise calling the function results in
* an undefined behavior).
*
* PARAMETERS
* bpq The bounded priority queue
* key The new key...
* value ... and its associated value
* ------------------------------------------------------------------------- */
void bpqReplaceMaximum(BoundedPriorityQueue *bpq, double key, size_t value);
/* ------------------------------------------------------------------------- *
* Return the maximum key currently stored in the priority queue. The queue
* must contain at least one element (otherwise calling the function results in
* an undefined behavior).
*
* PARAMETERS
* bpq The bounded priority queue
*
* RETURN
* max The value of the maximum key.
* ------------------------------------------------------------------------- */
double bpqMaximumKey(const BoundedPriorityQueue *bpq);
/* ------------------------------------------------------------------------- *
* Get all the values stored in the queue as an array of unsigned integers.
* The size of the array is the size of the queue (see function `bpqSize`).
* The array must be freed after usage.
*
* PARAMETERS
* bpq The bounded priority queue
*
* RETURN
* array The array of values.
* ------------------------------------------------------------------------- */
size_t *bpqGetItems(const BoundedPriorityQueue *bpq);
/* ------------------------------------------------------------------------- *
* Return the size of the queue (i.e. the number of elements currently stored
* in the structure).
*
* PARAMETERS
* bpq The bounded priority queue
*
* RETURN
* size The size of the queue
* ------------------------------------------------------------------------- */
size_t bpqSize(const BoundedPriorityQueue *bpq);
/* ------------------------------------------------------------------------- *
* Return the capacity of the queue.
*
* PARAMETERS
* bpq The bounded priority queue
*
* RETURN
* capacity The capacity of the queue
* ------------------------------------------------------------------------- */
size_t bpqCapacity(const BoundedPriorityQueue *bpq);
#endif // BOUNDEDPRIORITYQUEUE_H_DEFINED