projects
/
oweals
/
openssl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
make update
[oweals/openssl.git]
/
crypto
/
pqueue
/
pqueue.c
diff --git
a/crypto/pqueue/pqueue.c
b/crypto/pqueue/pqueue.c
index e3eb836d45246f50da67373ed4535ad9b038740a..53135d029a3eaa281d080afe6cdcfa36bb82b405 100644
(file)
--- a/
crypto/pqueue/pqueue.c
+++ b/
crypto/pqueue/pqueue.c
@@
-59,7
+59,7
@@
#include "cryptlib.h"
#include <openssl/bn.h>
#include "cryptlib.h"
#include <openssl/bn.h>
-#include
"pqueue.h"
+#include
<openssl/pqueue.h>
typedef struct _pqueue
{
typedef struct _pqueue
{
@@
-68,13
+68,12
@@
typedef struct _pqueue
} pqueue_s;
pitem *
} pqueue_s;
pitem *
-pitem_new(
PQ_64BIT priority
, void *data)
+pitem_new(
unsigned char *prio64be
, void *data)
{
pitem *item = (pitem *) OPENSSL_malloc(sizeof(pitem));
if (item == NULL) return NULL;
{
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;
item->data = data;
item->next = NULL;
@@
-87,7
+86,6
@@
pitem_free(pitem *item)
{
if (item == NULL) return;
{
if (item == NULL) return;
- pq_64bit_free(&(item->priority));
OPENSSL_free(item);
}
OPENSSL_free(item);
}
@@
-124,7
+122,10
@@
pqueue_insert(pqueue_s *pq, pitem *item)
next != NULL;
curr = next, next = next->next)
{
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;
{
item->next = next;
@@
-135,8
+136,8
@@
pqueue_insert(pqueue_s *pq, pitem *item)
return item;
}
return item;
}
- /* duplicates not allowed */
- if (pq_64bit_eq(&(item->priority), &(next->priority)))
+
+ else if (cmp == 0) /* duplicates not allowed */
return NULL;
}
return NULL;
}
@@
-164,18
+165,17
@@
pqueue_pop(pqueue_s *pq)
}
pitem *
}
pitem *
-pqueue_find(pqueue_s *pq,
PQ_64BIT priority
)
+pqueue_find(pqueue_s *pq,
unsigned char *prio64be
)
{
{
- pitem *next
, *prev = NULL
;
+ pitem *next;
pitem *found = NULL;
if ( pq->items == NULL)
return NULL;
pitem *found = NULL;
if ( pq->items == NULL)
return NULL;
- for ( next = pq->items; next->next != NULL;
- prev = next, next = next->next)
+ 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;
{
found = next;
break;
@@
-183,7
+183,7
@@
pqueue_find(pqueue_s *pq, PQ_64BIT priority)
}
/* check the one last node */
}
/* check the one last node */
- if (
pq_64bit_eq(&(next->priority), &priority)
)
+ if (
memcmp(next->priority, prio64be,8) ==0
)
found = next;
if ( ! found)
found = next;
if ( ! found)
@@
-199,7
+199,6
@@
pqueue_find(pqueue_s *pq, PQ_64BIT priority)
return found;
}
return found;
}
-#if PQ_64BIT_IS_INTEGER
void
pqueue_print(pqueue_s *pq)
{
void
pqueue_print(pqueue_s *pq)
{
@@
-207,11
+206,14
@@
pqueue_print(pqueue_s *pq)
while(item != NULL)
{
while(item != NULL)
{
- printf("item\t%lld\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;
}
}
item = item->next;
}
}
-#endif
pitem *
pqueue_iterator(pqueue_s *pq)
pitem *
pqueue_iterator(pqueue_s *pq)
@@
-234,3
+236,17
@@
pqueue_next(pitem **item)
return ret;
}
return ret;
}
+
+int
+pqueue_size(pqueue_s *pq)
+{
+ pitem *item = pq->items;
+ int count = 0;
+
+ while(item != NULL)
+ {
+ count++;
+ item = item->next;
+ }
+ return count;
+}