2 * @file PriorityQueue.c
5 #include "cgds/PriorityQueue.h"
7 // NOTE: no _init() method here, since PriorityQueue has no specific initialization
9 PriorityQueue
* _priorityqueue_new(size_t dataSize
, OrderType pType
, UInt arity
)
11 PriorityQueue
* priorityQueue
= (PriorityQueue
*) safe_malloc(sizeof (PriorityQueue
));
12 Heap
* heap
= _heap_new(dataSize
, pType
, arity
);
13 priorityQueue
->heap
= heap
;
17 PriorityQueue
* priorityqueue_copy(PriorityQueue
* priorityQueue
)
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
;
27 Bool
priorityqueue_empty(PriorityQueue
* priorityQueue
)
29 return heap_empty(priorityQueue
->heap
);
32 UInt
priorityqueue_size(PriorityQueue
* priorityQueue
)
34 return heap_size(priorityQueue
->heap
);
37 ItemValue
* priorityqueue_peek_raw(PriorityQueue
* priorityQueue
)
39 return heap_top_raw(priorityQueue
->heap
);
42 void priorityqueue_pop(PriorityQueue
* priorityQueue
)
44 heap_pop(priorityQueue
->heap
);
47 void priorityqueue_clear(PriorityQueue
* priorityQueue
)
49 heap_clear(priorityQueue
->heap
);
52 void priorityqueue_destroy(PriorityQueue
* priorityQueue
)
54 heap_destroy(priorityQueue
->heap
);
55 safe_free(priorityQueue
);