Some fixes + improvements (Vector) + code reformatting
[cgds.git] / src / PriorityQueue.c
CommitLineData
a7868768
BA
1/**
2 * @file PriorityQueue.c
3 */
4
5#include "cgds/PriorityQueue.h"
6
eed1b5d2 7// NOTE: no init() method here,
1ff641f9 8// since PriorityQueue has no specific initialization
a7868768
BA
9
10PriorityQueue* _priorityqueue_new(size_t dataSize, OrderType pType, UInt arity)
11{
e45132ac 12 PriorityQueue* priorityQueue =
1ff641f9 13 (PriorityQueue*) safe_malloc(sizeof (PriorityQueue));
1d60b10a 14 priorityQueue->heap = _heap_new(dataSize, pType, arity);
e45132ac 15 return priorityQueue;
a7868768
BA
16}
17
18PriorityQueue* priorityqueue_copy(PriorityQueue* priorityQueue)
19{
1d60b10a
BA
20 PriorityQueue* priorityQueueCopy =
21 (PriorityQueue*) safe_malloc(sizeof (PriorityQueue));
e45132ac
BA
22 priorityQueueCopy->heap = heap_copy(priorityQueue->heap);
23 return priorityQueueCopy;
a7868768
BA
24}
25
1ff641f9 26bool priorityqueue_empty(PriorityQueue* priorityQueue)
a7868768 27{
e45132ac 28 return heap_empty(priorityQueue->heap);
a7868768
BA
29}
30
31UInt priorityqueue_size(PriorityQueue* priorityQueue)
32{
e45132ac 33 return heap_size(priorityQueue->heap);
a7868768
BA
34}
35
1d60b10a 36ItemValue _priorityqueue_peek(PriorityQueue* priorityQueue)
a7868768 37{
1d60b10a 38 return _heap_top(priorityQueue->heap);
a7868768
BA
39}
40
41void priorityqueue_pop(PriorityQueue* priorityQueue)
42{
e45132ac 43 heap_pop(priorityQueue->heap);
a7868768
BA
44}
45
46void priorityqueue_clear(PriorityQueue* priorityQueue)
47{
e45132ac 48 heap_clear(priorityQueue->heap);
a7868768
BA
49}
50
51void priorityqueue_destroy(PriorityQueue* priorityQueue)
52{
e45132ac
BA
53 heap_destroy(priorityQueue->heap);
54 safe_free(priorityQueue);
a7868768 55}