Go to the documentation of this file.
12 #ifndef _GK_MKPQUEUE2_H
13 #define _GK_MKPQUEUE2_H
16 #define GK_MKPQUEUE2(FPRFX, PQT, KT, VT, KMALLOC, VMALLOC, KMAX, KEY_LT)\
20 PQT *FPRFX ## Create2(ssize_t maxnodes)\
24 if ((queue = (PQT *)gk_malloc(sizeof(PQT), "gk_pqCreate2: queue")) != NULL) {\
25 memset(queue, 0, sizeof(PQT));\
27 queue->maxnodes = maxnodes;\
28 queue->keys = KMALLOC(maxnodes, "gk_pqCreate2: keys");\
29 queue->vals = VMALLOC(maxnodes, "gk_pqCreate2: vals");\
31 if (queue->keys == NULL || queue->vals == NULL)\
32 gk_free((void **)&queue->keys, &queue->vals, &queue, LTERM);\
42 void FPRFX ## Reset2(PQT *queue)\
51 void FPRFX ## Destroy2(PQT **r_queue)\
53 PQT *queue = *r_queue; \
54 if (queue == NULL) return;\
55 gk_free((void **)&queue->keys, &queue->vals, &queue, LTERM);\
63 size_t FPRFX ## Length2(PQT *queue)\
65 return queue->nnodes;\
72 int FPRFX ## Insert2(PQT *queue, VT val, KT key)\
75 KT *keys=queue->keys;\
76 VT *vals=queue->vals;\
78 ASSERT2(FPRFX ## CheckHeap2(queue));\
80 if (queue->nnodes == queue->maxnodes) \
83 ASSERT2(FPRFX ## CheckHeap2(queue));\
88 if (KEY_LT(key, keys[j])) {\
100 ASSERT2(FPRFX ## CheckHeap2(queue));\
110 int FPRFX ## GetTop2(PQT *queue, VT *r_val)\
113 KT key, *keys=queue->keys;\
114 VT val, *vals=queue->vals;\
116 ASSERT2(FPRFX ## CheckHeap2(queue));\
118 if (queue->nnodes == 0)\
125 if ((i = queue->nnodes) > 0) {\
129 while ((j=2*i+1) < queue->nnodes) {\
130 if (KEY_LT(keys[j], key)) {\
131 if (j+1 < queue->nnodes && KEY_LT(keys[j+1], keys[j]))\
137 else if (j+1 < queue->nnodes && KEY_LT(keys[j+1], key)) {\
151 ASSERT2(FPRFX ## CheckHeap2(queue));\
161 int FPRFX ## SeeTopVal2(PQT *queue, VT *r_val)\
163 if (queue->nnodes == 0) \
166 *r_val = queue->vals[0];\
176 KT FPRFX ## SeeTopKey2(PQT *queue)\
178 return (queue->nnodes == 0 ? KMAX : queue->keys[0]);\
185 int FPRFX ## CheckHeap2(PQT *queue)\
188 KT *keys=queue->keys;\
190 if (queue->nnodes == 0)\
193 for (i=1; i<queue->nnodes; i++) {\
194 ASSERT(!KEY_LT(keys[i], keys[(i-1)/2]));\
196 for (i=1; i<queue->nnodes; i++)\
197 ASSERT(!KEY_LT(keys[i], keys[0]));\
203 #define GK_MKPQUEUE2_PROTO(FPRFX, PQT, KT, VT)\
204 PQT * FPRFX ## Create2(ssize_t maxnodes);\
205 void FPRFX ## Reset2(PQT *queue);\
206 void FPRFX ## Destroy2(PQT **r_queue);\
207 size_t FPRFX ## Length2(PQT *queue);\
208 int FPRFX ## Insert2(PQT *queue, VT node, KT key);\
209 int FPRFX ## GetTop2(PQT *queue, VT *r_val);\
210 int FPRFX ## SeeTopVal2(PQT *queue, VT *r_val);\
211 KT FPRFX ## SeeTopKey2(PQT *queue);\
212 int FPRFX ## CheckHeap2(PQT *queue);\
gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:22