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