Skip to content

Commit 0d35e13

Browse files
committed
Added documentation to hap priority queue data structure.
1 parent 3e05e18 commit 0d35e13

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

DataStructure/Queues/HPriorityQueue.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77

88

9+
10+
/** This function will allocate a new heap priority queue then it will return its pointer.
11+
*
12+
* @param freeFn the free function pointer, that will be called to free the queue items
13+
* @param cmp the comparator function pointer, that will be called to compare the queue items
14+
* @return it will return the new allocated queue pointer
15+
*/
16+
917
HPriorityQueue *hPriorityQueueInitialization(void (*freeFn)(void *), int (*cmp)(const void *, const void *)) {
1018

1119
HPriorityQueue *queue = (HPriorityQueue *) malloc(sizeof(HPriorityQueue));
@@ -18,6 +26,14 @@ HPriorityQueue *hPriorityQueueInitialization(void (*freeFn)(void *), int (*cmp)(
1826

1927

2028

29+
30+
31+
/** This function will insert the passed item in the queue.
32+
*
33+
* @param queue the queue pointer
34+
* @param item the new item pointer
35+
*/
36+
2137
void hpQueueEnqueue(HPriorityQueue *queue, void *item) {
2238

2339
if (queue == NULL) {
@@ -31,6 +47,14 @@ void hpQueueEnqueue(HPriorityQueue *queue, void *item) {
3147
}
3248

3349

50+
51+
52+
/** This function will insert all the passed array items in the queue.
53+
*
54+
* @param queue the queue pointer
55+
* @param items the new items array pointer
56+
* @param length the length of the new items array
57+
*/
3458
void hpQueueEnqueueAll(HPriorityQueue *queue, void *items, int length) {
3559

3660
if (queue == NULL) {
@@ -45,6 +69,14 @@ void hpQueueEnqueueAll(HPriorityQueue *queue, void *items, int length) {
4569

4670

4771

72+
73+
/** This function will remove the first item from the queue,
74+
* then it will return it.
75+
*
76+
* @param queue the queue pointer
77+
* @return it will return the first item in the queue
78+
*/
79+
4880
void *hpQueueDequeue(HPriorityQueue *queue) {
4981

5082
if (queue == NULL) {
@@ -59,6 +91,13 @@ void *hpQueueDequeue(HPriorityQueue *queue) {
5991

6092

6193

94+
95+
/** This function will return the first item in the queue without removing it from the queue.
96+
*
97+
* @param queue the queue pointer
98+
* @return it will return the first item in the queue
99+
*/
100+
62101
void *hpQueuePeek(HPriorityQueue *queue) {
63102

64103
if (queue == NULL) {
@@ -73,16 +112,43 @@ void *hpQueuePeek(HPriorityQueue *queue) {
73112

74113

75114

115+
116+
/** This function will return the number of items in the queue.
117+
*
118+
* @param queue the queue pointer
119+
* @return it will return the number of items in the queue
120+
*/
121+
76122
int hpQueueGetLength(HPriorityQueue *queue) {
77123
return binaryHeapGetSize(queue->heap);
78124
}
79125

80126

127+
128+
129+
/** This function will check if the queue is empty or not,
130+
* and if it was the function will return one (1),
131+
* other wise it will return zero (0).
132+
*
133+
* @param queue the queue pointer
134+
* @return it will return 1 if the queue was empty, other wise it will return 0
135+
*/
136+
81137
int hpQueueIsEmpty(HPriorityQueue *queue) {
82138
return binaryHeapIsEmpty(queue->heap);
83139
}
84140

85141

142+
143+
144+
/** This function will return a double void array that contains the queue items.
145+
*
146+
* Note: the array will be sorted.
147+
*
148+
* @param queue the queue pointer
149+
* @return it will return a double void array pointer, that contains the queue items
150+
*/
151+
86152
void **hpQueueToArray(HPriorityQueue *queue) {
87153
void **arr = binaryHeapToArray(queue->heap);
88154

@@ -97,12 +163,29 @@ void **hpQueueToArray(HPriorityQueue *queue) {
97163

98164
}
99165

166+
167+
168+
169+
/** This function will clear the queue and free all it's items,
170+
* without freeing the queue itself.
171+
*
172+
* @param queue the queue pointer
173+
*/
174+
100175
void clearHPQueue(HPriorityQueue *queue) {
101176

102177
clearBinaryHeap(queue->heap);
103178

104179
}
105180

181+
182+
183+
184+
/** This function will destroy and free the queue and it's items.
185+
*
186+
* @param queue the queue pointer
187+
*/
188+
106189
void destroyHPQueue(HPriorityQueue *queue) {
107190

108191
destroyBinaryHeap(queue->heap);

0 commit comments

Comments
 (0)