Lines Matching defs:pqp

34 shadow_pq_enqueue(shadow_pq_t *pqp, void *p)
39 if (pqp->shpq_last + 1 == pqp->shpq_size) {
41 uint_t size = pqp->shpq_size * 2;
47 bcopy(pqp->shpq_items, items, sizeof (void *) * pqp->shpq_size);
48 free(pqp->shpq_items);
49 pqp->shpq_items = items;
50 pqp->shpq_size = size;
53 assert(pqp->shpq_last + 1 < pqp->shpq_size);
55 i = ++pqp->shpq_last;
56 pqp->shpq_items[i] = p;
57 ip = pqp->shpq_priority(p);
64 jp = pqp->shpq_priority(pqp->shpq_items[j]);
70 p = pqp->shpq_items[i];
71 pqp->shpq_items[i] = pqp->shpq_items[j];
72 pqp->shpq_items[j] = p;
79 shadow_pq_remove_common(shadow_pq_t *pqp, uint_t i)
85 assert(i <= pqp->shpq_last && i != 0);
86 assert(pqp->shpq_items[i] != NULL);
88 pqp->shpq_items[i] = pqp->shpq_items[pqp->shpq_last];
89 pqp->shpq_items[pqp->shpq_last] = NULL;
90 pqp->shpq_last--;
92 if (pqp->shpq_last < i)
95 ip = pqp->shpq_priority(pqp->shpq_items[i]);
97 for (; i * 2 <= pqp->shpq_last; i = c) {
98 if (pqp->shpq_items[i * 2 + 1] == NULL) {
99 if (pqp->shpq_items[i * 2] == NULL)
102 cp = pqp->shpq_priority(pqp->shpq_items[c]);
104 assert(pqp->shpq_items[i * 2] != NULL);
105 cp0 = pqp->shpq_priority(pqp->shpq_items[i * 2]);
106 cp1 = pqp->shpq_priority(pqp->shpq_items[i * 2 + 1]);
122 p = pqp->shpq_items[i];
123 pqp->shpq_items[i] = pqp->shpq_items[c];
124 pqp->shpq_items[c] = p;
131 if (pqp->shpq_last * 4 < pqp->shpq_size) {
133 uint_t size = pqp->shpq_size / 2;
134 while (size * 2 < pqp->shpq_size) {
140 bcopy(pqp->shpq_items, items, sizeof (void *) * size);
141 free(pqp->shpq_items);
142 pqp->shpq_items = items;
143 pqp->shpq_size = size;
149 shadow_pq_dequeue(shadow_pq_t *pqp)
153 if (pqp->shpq_last == 0)
156 p = pqp->shpq_items[1];
157 shadow_pq_remove_common(pqp, 1);
162 shadow_pq_peek(shadow_pq_t *pqp)
164 if (pqp->shpq_last == 0)
167 return (pqp->shpq_items[1]);
176 shadow_pq_remove(shadow_pq_t *pqp, void *p)
180 for (i = 1; i <= pqp->shpq_last; i++) {
181 if (pqp->shpq_items[i] == p) {
182 shadow_pq_remove_common(pqp, i);
191 shadow_pq_iter(shadow_pq_t *pqp, int (*callback)(shadow_pq_t *, void *,
197 for (i = 1; i <= pqp->shpq_last; i++) {
198 if ((ret = callback(pqp, pqp->shpq_items[i], data)) != 0)
206 shadow_pq_init(shadow_pq_t *pqp, shadow_pq_priority_f *cb)
208 pqp->shpq_size = (1 << 2); /* must be a power of two */
209 pqp->shpq_last = 0;
210 pqp->shpq_priority = cb;
211 pqp->shpq_items = shadow_zalloc(sizeof (void *) * pqp->shpq_size);
213 return (pqp->shpq_items == NULL ? -1 : 0);
217 shadow_pq_fini(shadow_pq_t *pqp)
219 free(pqp->shpq_items);
220 bzero(pqp, sizeof (shadow_pq_t));