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