2 * @file PriorityQueue.c
5 #include "cgds/PriorityQueue.h"
7 // NOTE: no _init() method here,
8 // since PriorityQueue has no specific initialization
10 PriorityQueue
* _priorityqueue_new(size_t dataSize
, OrderType pType
, UInt arity
)
12 PriorityQueue
* priorityQueue
=
13 (PriorityQueue
*) safe_malloc(sizeof (PriorityQueue
));
14 Heap
* heap
= _heap_new(dataSize
, pType
, arity
);
15 priorityQueue
->heap
= heap
;
19 PriorityQueue
* priorityqueue_copy(PriorityQueue
* priorityQueue
)
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
;
29 bool priorityqueue_empty(PriorityQueue
* priorityQueue
)
31 return heap_empty(priorityQueue
->heap
);
34 UInt
priorityqueue_size(PriorityQueue
* priorityQueue
)
36 return heap_size(priorityQueue
->heap
);
39 ItemValue
* priorityqueue_peek_raw(PriorityQueue
* priorityQueue
)
41 return heap_top_raw(priorityQueue
->heap
);
44 void priorityqueue_pop(PriorityQueue
* priorityQueue
)
46 heap_pop(priorityQueue
->heap
);
49 void priorityqueue_clear(PriorityQueue
* priorityQueue
)
51 heap_clear(priorityQueue
->heap
);
54 void priorityqueue_destroy(PriorityQueue
* priorityQueue
)
56 heap_destroy(priorityQueue
->heap
);
57 safe_free(priorityQueue
);