Commit | Line | Data |
---|---|---|
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 | |
10 | PriorityQueue* _priorityqueue_new(size_t dataSize, OrderType pType, UInt arity) | |
11 | { | |
e45132ac | 12 | PriorityQueue* priorityQueue = |
1ff641f9 | 13 | (PriorityQueue*) safe_malloc(sizeof (PriorityQueue)); |
e45132ac BA |
14 | Heap* heap = _heap_new(dataSize, pType, arity); |
15 | priorityQueue->heap = heap; | |
16 | return priorityQueue; | |
a7868768 BA |
17 | } |
18 | ||
19 | PriorityQueue* priorityqueue_copy(PriorityQueue* priorityQueue) | |
20 | { | |
e45132ac BA |
21 | PriorityQueue* priorityQueueCopy = _priorityqueue_new( |
22 | priorityQueue->heap->array->dataSize, | |
23 | priorityQueue->heap->hType, priorityQueue->heap->arity); | |
24 | heap_destroy(priorityQueueCopy->heap); //TODO: bad style... | |
25 | priorityQueueCopy->heap = heap_copy(priorityQueue->heap); | |
26 | return priorityQueueCopy; | |
a7868768 BA |
27 | } |
28 | ||
1ff641f9 | 29 | bool priorityqueue_empty(PriorityQueue* priorityQueue) |
a7868768 | 30 | { |
e45132ac | 31 | return heap_empty(priorityQueue->heap); |
a7868768 BA |
32 | } |
33 | ||
34 | UInt priorityqueue_size(PriorityQueue* priorityQueue) | |
35 | { | |
e45132ac | 36 | return heap_size(priorityQueue->heap); |
a7868768 BA |
37 | } |
38 | ||
39 | ItemValue* priorityqueue_peek_raw(PriorityQueue* priorityQueue) | |
40 | { | |
e45132ac | 41 | return heap_top_raw(priorityQueue->heap); |
a7868768 BA |
42 | } |
43 | ||
44 | void priorityqueue_pop(PriorityQueue* priorityQueue) | |
45 | { | |
e45132ac | 46 | heap_pop(priorityQueue->heap); |
a7868768 BA |
47 | } |
48 | ||
49 | void priorityqueue_clear(PriorityQueue* priorityQueue) | |
50 | { | |
e45132ac | 51 | heap_clear(priorityQueue->heap); |
a7868768 BA |
52 | } |
53 | ||
54 | void priorityqueue_destroy(PriorityQueue* priorityQueue) | |
55 | { | |
e45132ac BA |
56 | heap_destroy(priorityQueue->heap); |
57 | safe_free(priorityQueue); | |
a7868768 | 58 | } |