Lines Matching refs:pq

64 element (struct grub_priority_queue *pq, grub_size_t k)
66 return ((grub_uint8_t *) pq->els) + k * pq->elsize;
70 swap (struct grub_priority_queue *pq, grub_size_t m, grub_size_t n)
74 p1 = (grub_uint8_t *) element (pq, m);
75 p2 = (grub_uint8_t *) element (pq, n);
76 for (l = pq->elsize; l; l--, p1++, p2++)
104 grub_priority_queue_top (grub_priority_queue_t pq)
106 if (!pq->used)
108 return element (pq, 0);
112 grub_priority_queue_destroy (grub_priority_queue_t pq)
114 grub_free (pq->els);
115 grub_free (pq);
141 /* Heap property: pq->cmp (element (pq, p), element (pq, parent (p))) <= 0. */
143 grub_priority_queue_push (grub_priority_queue_t pq, const void *el)
146 if (pq->used == pq->allocated)
149 els = grub_realloc (pq->els, pq->elsize * 2 * pq->allocated);
152 pq->allocated *= 2;
153 pq->els = els;
155 pq->used++;
156 grub_memcpy (element (pq, pq->used - 1), el, pq->elsize);
157 for (p = pq->used - 1; p; p = parent (p))
159 if (pq->cmp (element (pq, p), element (pq, parent (p))) <= 0)
161 swap (pq, p, parent (p));
168 grub_priority_queue_pop (grub_priority_queue_t pq)
172 swap (pq, 0, pq->used - 1);
173 pq->used--;
174 for (p = 0; left_child (p) < pq->used; )
177 if (pq->cmp (element (pq, left_child (p)), element (pq, p)) <= 0
178 && (right_child (p) >= pq->used
179 || pq->cmp (element (pq, right_child (p)), element (pq, p)) <= 0))
181 if (right_child (p) >= pq->used
182 || pq->cmp (element (pq, left_child (p)),
183 element (pq, right_child (p))) > 0)
187 swap (pq, p, c);
209 priority_queue <int> pq;
221 if (s && *(int *) grub_priority_queue_top (pq2) != pq.top ())
229 pq.pop ();
236 pq.push (v);
245 if (*(int *) grub_priority_queue_top (pq2) != pq.top ())
251 pq.pop ();