2 * Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include <openssl/bn.h>
18 pitem *pitem_new(unsigned char *prio64be, void *data)
20 pitem *item = OPENSSL_malloc(sizeof(*item));
24 memcpy(item->priority, prio64be, sizeof(item->priority));
32 void pitem_free(pitem *item)
39 pqueue *pq = OPENSSL_zalloc(sizeof(*pq));
44 void pqueue_free(pqueue *pq)
49 pitem *pqueue_insert(pqueue *pq, pitem *item)
53 if (pq->items == NULL) {
58 for (curr = NULL, next = pq->items;
59 next != NULL; curr = next, next = next->next) {
61 * we can compare 64-bit value in big-endian encoding with memcmp:-)
63 int cmp = memcmp(next->priority, item->priority, 8);
64 if (cmp > 0) { /* next > item */
75 else if (cmp == 0) /* duplicates not allowed */
85 pitem *pqueue_peek(pqueue *pq)
90 pitem *pqueue_pop(pqueue *pq)
92 pitem *item = pq->items;
94 if (pq->items != NULL)
95 pq->items = pq->items->next;
100 pitem *pqueue_find(pqueue *pq, unsigned char *prio64be)
105 if (pq->items == NULL)
108 for (next = pq->items; next->next != NULL; next = next->next) {
109 if (memcmp(next->priority, prio64be, 8) == 0) {
115 /* check the one last node */
116 if (memcmp(next->priority, prio64be, 8) == 0)
125 pitem *pqueue_iterator(pqueue *pq)
127 return pqueue_peek(pq);
130 pitem *pqueue_next(pitem **item)
134 if (item == NULL || *item == NULL)
139 *item = (*item)->next;
144 int pqueue_size(pqueue *pq)
146 pitem *item = pq->items;
149 while (item != NULL) {