summaryrefslogtreecommitdiff
path: root/Cryptlib/OpenSSL/crypto/pqueue
diff options
context:
space:
mode:
Diffstat (limited to 'Cryptlib/OpenSSL/crypto/pqueue')
-rw-r--r--Cryptlib/OpenSSL/crypto/pqueue/pqueue.c37
-rw-r--r--Cryptlib/OpenSSL/crypto/pqueue/pqueue.h46
2 files changed, 49 insertions, 34 deletions
diff --git a/Cryptlib/OpenSSL/crypto/pqueue/pqueue.c b/Cryptlib/OpenSSL/crypto/pqueue/pqueue.c
index 69cfefd5..75f97349 100644
--- a/Cryptlib/OpenSSL/crypto/pqueue/pqueue.c
+++ b/Cryptlib/OpenSSL/crypto/pqueue/pqueue.c
@@ -66,14 +66,13 @@ typedef struct _pqueue {
int count;
} pqueue_s;
-pitem *pitem_new(PQ_64BIT priority, void *data)
+pitem *pitem_new(unsigned char *prio64be, void *data)
{
pitem *item = (pitem *)OPENSSL_malloc(sizeof(pitem));
if (item == NULL)
return NULL;
- pq_64bit_init(&(item->priority));
- pq_64bit_assign(&item->priority, &priority);
+ memcpy(item->priority, prio64be, sizeof(item->priority));
item->data = data;
item->next = NULL;
@@ -86,7 +85,6 @@ void pitem_free(pitem *item)
if (item == NULL)
return;
- pq_64bit_free(&(item->priority));
OPENSSL_free(item);
}
@@ -119,7 +117,11 @@ pitem *pqueue_insert(pqueue_s *pq, pitem *item)
for (curr = NULL, next = pq->items;
next != NULL; curr = next, next = next->next) {
- if (pq_64bit_gt(&(next->priority), &(item->priority))) {
+ /*
+ * we can compare 64-bit value in big-endian encoding with memcmp:-)
+ */
+ int cmp = memcmp(next->priority, item->priority, 8);
+ if (cmp > 0) { /* next > item */
item->next = next;
if (curr == NULL)
@@ -129,8 +131,8 @@ pitem *pqueue_insert(pqueue_s *pq, pitem *item)
return item;
}
- /* duplicates not allowed */
- if (pq_64bit_eq(&(item->priority), &(next->priority)))
+
+ else if (cmp == 0) /* duplicates not allowed */
return NULL;
}
@@ -155,7 +157,7 @@ pitem *pqueue_pop(pqueue_s *pq)
return item;
}
-pitem *pqueue_find(pqueue_s *pq, PQ_64BIT priority)
+pitem *pqueue_find(pqueue_s *pq, unsigned char *prio64be)
{
pitem *next;
pitem *found = NULL;
@@ -164,33 +166,42 @@ pitem *pqueue_find(pqueue_s *pq, PQ_64BIT priority)
return NULL;
for (next = pq->items; next->next != NULL; next = next->next) {
- if (pq_64bit_eq(&(next->priority), &priority)) {
+ if (memcmp(next->priority, prio64be, 8) == 0) {
found = next;
break;
}
}
/* check the one last node */
- if (pq_64bit_eq(&(next->priority), &priority))
+ if (memcmp(next->priority, prio64be, 8) == 0)
found = next;
if (!found)
return NULL;
+#if 0 /* find works in peek mode */
+ if (prev == NULL)
+ pq->items = next->next;
+ else
+ prev->next = next->next;
+#endif
+
return found;
}
-#if PQ_64BIT_IS_INTEGER
void pqueue_print(pqueue_s *pq)
{
pitem *item = pq->items;
while (item != NULL) {
- printf("item\t" PQ_64BIT_PRINT "\n", item->priority);
+ printf("item\t%02x%02x%02x%02x%02x%02x%02x%02x\n",
+ item->priority[0], item->priority[1],
+ item->priority[2], item->priority[3],
+ item->priority[4], item->priority[5],
+ item->priority[6], item->priority[7]);
item = item->next;
}
}
-#endif
pitem *pqueue_iterator(pqueue_s *pq)
{
diff --git a/Cryptlib/OpenSSL/crypto/pqueue/pqueue.h b/Cryptlib/OpenSSL/crypto/pqueue/pqueue.h
index 02386d13..d40d9c7d 100644
--- a/Cryptlib/OpenSSL/crypto/pqueue/pqueue.h
+++ b/Cryptlib/OpenSSL/crypto/pqueue/pqueue.h
@@ -1,7 +1,7 @@
/* crypto/pqueue/pqueue.h */
-/*
+/*
* DTLS implementation written by Nagendra Modadugu
- * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
+ * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
*/
/* ====================================================================
* Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
@@ -11,7 +11,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -58,38 +58,42 @@
*/
#ifndef HEADER_PQUEUE_H
-#define HEADER_PQUEUE_H
+# define HEADER_PQUEUE_H
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <openssl/pq_compat.h>
+# include <stdio.h>
+# include <stdlib.h>
+# include <string.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
typedef struct _pqueue *pqueue;
-typedef struct _pitem
- {
- PQ_64BIT priority;
- void *data;
- struct _pitem *next;
- } pitem;
+typedef struct _pitem {
+ unsigned char priority[8]; /* 64-bit value in big-endian encoding */
+ void *data;
+ struct _pitem *next;
+} pitem;
typedef struct _pitem *piterator;
-pitem *pitem_new(PQ_64BIT priority, void *data);
-void pitem_free(pitem *item);
+pitem *pitem_new(unsigned char *prio64be, void *data);
+void pitem_free(pitem *item);
pqueue pqueue_new(void);
-void pqueue_free(pqueue pq);
+void pqueue_free(pqueue pq);
pitem *pqueue_insert(pqueue pq, pitem *item);
pitem *pqueue_peek(pqueue pq);
pitem *pqueue_pop(pqueue pq);
-pitem *pqueue_find(pqueue pq, PQ_64BIT priority);
+pitem *pqueue_find(pqueue pq, unsigned char *prio64be);
pitem *pqueue_iterator(pqueue pq);
pitem *pqueue_next(piterator *iter);
-void pqueue_print(pqueue pq);
+void pqueue_print(pqueue pq);
+int pqueue_size(pqueue pq);
-#endif /* ! HEADER_PQUEUE_H */
+#ifdef __cplusplus
+}
+#endif
+#endif /* ! HEADER_PQUEUE_H */