Implement HashTable + fix some extra blank spaces, remove Bool type (using bool ...
[cgds.git] / src / PriorityQueue.c
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 Heap* heap = _heap_new(dataSize, pType, arity);
15 priorityQueue->heap = heap;
16 return priorityQueue;
17 }
18
19 PriorityQueue* priorityqueue_copy(PriorityQueue* priorityQueue)
20 {
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;
27 }
28
29 bool priorityqueue_empty(PriorityQueue* priorityQueue)
30 {
31 return heap_empty(priorityQueue->heap);
32 }
33
34 UInt priorityqueue_size(PriorityQueue* priorityQueue)
35 {
36 return heap_size(priorityQueue->heap);
37 }
38
39 ItemValue* priorityqueue_peek_raw(PriorityQueue* priorityQueue)
40 {
41 return heap_top_raw(priorityQueue->heap);
42 }
43
44 void priorityqueue_pop(PriorityQueue* priorityQueue)
45 {
46 heap_pop(priorityQueue->heap);
47 }
48
49 void priorityqueue_clear(PriorityQueue* priorityQueue)
50 {
51 heap_clear(priorityQueue->heap);
52 }
53
54 void priorityqueue_destroy(PriorityQueue* priorityQueue)
55 {
56 heap_destroy(priorityQueue->heap);
57 safe_free(priorityQueue);
58 }