]>
git.ipfire.org Git - thirdparty/openssl.git/blob - ssl/pqueue.c
53f295feaaa628bfa833a8f028b86ea3d974580b
2 * Copyright 2005-2018 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
));
23 ERR_raise(ERR_LIB_SSL
, ERR_R_MALLOC_FAILURE
);
27 memcpy(item
->priority
, prio64be
, sizeof(item
->priority
));
33 void pitem_free(pitem
*item
)
38 pqueue
*pqueue_new(void)
40 pqueue
*pq
= OPENSSL_zalloc(sizeof(*pq
));
43 ERR_raise(ERR_LIB_SSL
, ERR_R_MALLOC_FAILURE
);
48 void pqueue_free(pqueue
*pq
)
53 pitem
*pqueue_insert(pqueue
*pq
, pitem
*item
)
57 if (pq
->items
== NULL
) {
62 for (curr
= NULL
, next
= pq
->items
;
63 next
!= NULL
; curr
= next
, next
= next
->next
) {
65 * we can compare 64-bit value in big-endian encoding with memcmp:-)
67 int cmp
= memcmp(next
->priority
, item
->priority
, 8);
68 if (cmp
> 0) { /* next > item */
79 else if (cmp
== 0) /* duplicates not allowed */
89 pitem
*pqueue_peek(pqueue
*pq
)
94 pitem
*pqueue_pop(pqueue
*pq
)
96 pitem
*item
= pq
->items
;
98 if (pq
->items
!= NULL
)
99 pq
->items
= pq
->items
->next
;
104 pitem
*pqueue_find(pqueue
*pq
, unsigned char *prio64be
)
109 if (pq
->items
== NULL
)
112 for (next
= pq
->items
; next
->next
!= NULL
; next
= next
->next
) {
113 if (memcmp(next
->priority
, prio64be
, 8) == 0) {
119 /* check the one last node */
120 if (memcmp(next
->priority
, prio64be
, 8) == 0)
129 pitem
*pqueue_iterator(pqueue
*pq
)
131 return pqueue_peek(pq
);
134 pitem
*pqueue_next(piterator
*item
)
138 if (item
== NULL
|| *item
== NULL
)
143 *item
= (*item
)->next
;
148 size_t pqueue_size(pqueue
*pq
)
150 pitem
*item
= pq
->items
;
153 while (item
!= NULL
) {