*
*/
+#include "cryptlib.h"
+#include <openssl/bn.h>
#include "pqueue.h"
-#include "crypto.h"
typedef struct _pqueue
{
} pqueue_s;
pitem *
-pitem_new(unsigned long long priority, void *data)
+pitem_new(unsigned char *prio64be, void *data)
{
pitem *item = (pitem *) OPENSSL_malloc(sizeof(pitem));
if (item == NULL) return NULL;
- item->priority = priority;
+ memcpy(item->priority,prio64be,sizeof(item->priority));
+
item->data = data;
item->next = NULL;
pitem_free(pitem *item)
{
if (item == NULL) return;
-
+
OPENSSL_free(item);
}
next != NULL;
curr = next, next = next->next)
{
- if (item->priority < next->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;
return item;
}
- /* duplicates not allowed */
- if (item->priority == next->priority)
+
+ else if (cmp == 0) /* duplicates not allowed */
return NULL;
}
}
pitem *
-pqueue_find(pqueue_s *pq, unsigned long long priority)
+pqueue_find(pqueue_s *pq, unsigned char *prio64be)
{
- pitem *next, *prev = NULL;
+ pitem *next;
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 ( next->priority == priority)
+ if ( memcmp(next->priority, prio64be,8) == 0)
{
found = next;
break;
}
/* check the one last node */
- if ( next->priority == priority)
+ if ( memcmp(next->priority, prio64be,8) ==0)
found = next;
if ( ! found)
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;
}
}
return ret;
}
+
+int
+pqueue_size(pqueue_s *pq)
+{
+ pitem *item = pq->items;
+ int count = 0;
+
+ while(item != NULL)
+ {
+ count++;
+ item = item->next;
+ }
+ return count;
+}