Add basic Set implementation - TODO: add iterators for Set and HashTable
[cgds.git] / src / PriorityQueue.c
... / ...
CommitLineData
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
10PriorityQueue* _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
19PriorityQueue* 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
29bool priorityqueue_empty(PriorityQueue* priorityQueue)
30{
31 return heap_empty(priorityQueue->heap);
32}
33
34UInt priorityqueue_size(PriorityQueue* priorityQueue)
35{
36 return heap_size(priorityQueue->heap);
37}
38
39ItemValue* priorityqueue_peek_raw(PriorityQueue* priorityQueue)
40{
41 return heap_top_raw(priorityQueue->heap);
42}
43
44void priorityqueue_pop(PriorityQueue* priorityQueue)
45{
46 heap_pop(priorityQueue->heap);
47}
48
49void priorityqueue_clear(PriorityQueue* priorityQueue)
50{
51 heap_clear(priorityQueue->heap);
52}
53
54void priorityqueue_destroy(PriorityQueue* priorityQueue)
55{
56 heap_destroy(priorityQueue->heap);
57 safe_free(priorityQueue);
58}