2 * Copyright 2005-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
10 #include "ssl_local.h"
11 #include <openssl/bn.h>
18 pitem *pitem_new(unsigned char *prio64be, void *data)
20 pitem *item = OPENSSL_malloc(sizeof(*item));
25 memcpy(item->priority, prio64be, sizeof(item->priority));
31 void pitem_free(pitem *item)
36 pqueue *pqueue_new(void)
38 pqueue *pq = OPENSSL_zalloc(sizeof(*pq));
43 void pqueue_free(pqueue *pq)
48 pitem *pqueue_insert(pqueue *pq, pitem *item)
52 if (pq->items == NULL) {
57 for (curr = NULL, next = pq->items;
58 next != NULL; curr = next, next = next->next) {
60 * we can compare 64-bit value in big-endian encoding with memcmp:-)
62 int cmp = memcmp(next->priority, item->priority, 8);
63 if (cmp > 0) { /* next > item */
74 else if (cmp == 0) /* duplicates not allowed */
84 pitem *pqueue_peek(pqueue *pq)
89 pitem *pqueue_pop(pqueue *pq)
91 pitem *item = pq->items;
93 if (pq->items != NULL)
94 pq->items = pq->items->next;
99 pitem *pqueue_find(pqueue *pq, unsigned char *prio64be)
104 if (pq->items == NULL)
107 for (next = pq->items; next->next != NULL; next = next->next) {
108 if (memcmp(next->priority, prio64be, 8) == 0) {
114 /* check the one last node */
115 if (memcmp(next->priority, prio64be, 8) == 0)
124 pitem *pqueue_iterator(pqueue *pq)
126 return pqueue_peek(pq);
129 pitem *pqueue_next(piterator *item)
133 if (item == NULL || *item == NULL)
138 *item = (*item)->next;
143 size_t pqueue_size(pqueue *pq)
145 pitem *item = pq->items;
148 while (item != NULL) {