diff options
| author | djm <> | 2010-10-01 22:54:18 +0000 |
|---|---|---|
| committer | djm <> | 2010-10-01 22:54:18 +0000 |
| commit | f6ca1ae73bb9eabfb510df2cffc2599db98d35a9 (patch) | |
| tree | def8296400903465cb96345535c0a56935eb05a4 /src/lib/libcrypto/pqueue/pqueue.c | |
| parent | 0229f29a33371533962d8b0b8264882afac53d70 (diff) | |
| download | openbsd-f6ca1ae73bb9eabfb510df2cffc2599db98d35a9.tar.gz openbsd-f6ca1ae73bb9eabfb510df2cffc2599db98d35a9.tar.bz2 openbsd-f6ca1ae73bb9eabfb510df2cffc2599db98d35a9.zip | |
import OpenSSL-1.0.0a
Diffstat (limited to 'src/lib/libcrypto/pqueue/pqueue.c')
| -rw-r--r-- | src/lib/libcrypto/pqueue/pqueue.c | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/lib/libcrypto/pqueue/pqueue.c b/src/lib/libcrypto/pqueue/pqueue.c index 5cc18527f8..99a6fb874d 100644 --- a/src/lib/libcrypto/pqueue/pqueue.c +++ b/src/lib/libcrypto/pqueue/pqueue.c | |||
| @@ -68,13 +68,12 @@ typedef struct _pqueue | |||
| 68 | } pqueue_s; | 68 | } pqueue_s; |
| 69 | 69 | ||
| 70 | pitem * | 70 | pitem * |
| 71 | pitem_new(PQ_64BIT priority, void *data) | 71 | pitem_new(unsigned char *prio64be, void *data) |
| 72 | { | 72 | { |
| 73 | pitem *item = (pitem *) OPENSSL_malloc(sizeof(pitem)); | 73 | pitem *item = (pitem *) OPENSSL_malloc(sizeof(pitem)); |
| 74 | if (item == NULL) return NULL; | 74 | if (item == NULL) return NULL; |
| 75 | 75 | ||
| 76 | pq_64bit_init(&(item->priority)); | 76 | memcpy(item->priority,prio64be,sizeof(item->priority)); |
| 77 | pq_64bit_assign(&item->priority, &priority); | ||
| 78 | 77 | ||
| 79 | item->data = data; | 78 | item->data = data; |
| 80 | item->next = NULL; | 79 | item->next = NULL; |
| @@ -87,7 +86,6 @@ pitem_free(pitem *item) | |||
| 87 | { | 86 | { |
| 88 | if (item == NULL) return; | 87 | if (item == NULL) return; |
| 89 | 88 | ||
| 90 | pq_64bit_free(&(item->priority)); | ||
| 91 | OPENSSL_free(item); | 89 | OPENSSL_free(item); |
| 92 | } | 90 | } |
| 93 | 91 | ||
| @@ -124,7 +122,10 @@ pqueue_insert(pqueue_s *pq, pitem *item) | |||
| 124 | next != NULL; | 122 | next != NULL; |
| 125 | curr = next, next = next->next) | 123 | curr = next, next = next->next) |
| 126 | { | 124 | { |
| 127 | if (pq_64bit_gt(&(next->priority), &(item->priority))) | 125 | /* we can compare 64-bit value in big-endian encoding |
| 126 | * with memcmp:-) */ | ||
| 127 | int cmp = memcmp(next->priority, item->priority,8); | ||
| 128 | if (cmp > 0) /* next > item */ | ||
| 128 | { | 129 | { |
| 129 | item->next = next; | 130 | item->next = next; |
| 130 | 131 | ||
| @@ -135,8 +136,8 @@ pqueue_insert(pqueue_s *pq, pitem *item) | |||
| 135 | 136 | ||
| 136 | return item; | 137 | return item; |
| 137 | } | 138 | } |
| 138 | /* duplicates not allowed */ | 139 | |
| 139 | if (pq_64bit_eq(&(item->priority), &(next->priority))) | 140 | else if (cmp == 0) /* duplicates not allowed */ |
| 140 | return NULL; | 141 | return NULL; |
| 141 | } | 142 | } |
| 142 | 143 | ||
| @@ -164,7 +165,7 @@ pqueue_pop(pqueue_s *pq) | |||
| 164 | } | 165 | } |
| 165 | 166 | ||
| 166 | pitem * | 167 | pitem * |
| 167 | pqueue_find(pqueue_s *pq, PQ_64BIT priority) | 168 | pqueue_find(pqueue_s *pq, unsigned char *prio64be) |
| 168 | { | 169 | { |
| 169 | pitem *next, *prev = NULL; | 170 | pitem *next, *prev = NULL; |
| 170 | pitem *found = NULL; | 171 | pitem *found = NULL; |
| @@ -175,7 +176,7 @@ pqueue_find(pqueue_s *pq, PQ_64BIT priority) | |||
| 175 | for ( next = pq->items; next->next != NULL; | 176 | for ( next = pq->items; next->next != NULL; |
| 176 | prev = next, next = next->next) | 177 | prev = next, next = next->next) |
| 177 | { | 178 | { |
| 178 | if ( pq_64bit_eq(&(next->priority), &priority)) | 179 | if ( memcmp(next->priority, prio64be,8) == 0) |
| 179 | { | 180 | { |
| 180 | found = next; | 181 | found = next; |
| 181 | break; | 182 | break; |
| @@ -183,7 +184,7 @@ pqueue_find(pqueue_s *pq, PQ_64BIT priority) | |||
| 183 | } | 184 | } |
| 184 | 185 | ||
| 185 | /* check the one last node */ | 186 | /* check the one last node */ |
| 186 | if ( pq_64bit_eq(&(next->priority), &priority)) | 187 | if ( memcmp(next->priority, prio64be,8) ==0) |
| 187 | found = next; | 188 | found = next; |
| 188 | 189 | ||
| 189 | if ( ! found) | 190 | if ( ! found) |
| @@ -199,7 +200,6 @@ pqueue_find(pqueue_s *pq, PQ_64BIT priority) | |||
| 199 | return found; | 200 | return found; |
| 200 | } | 201 | } |
| 201 | 202 | ||
| 202 | #if PQ_64BIT_IS_INTEGER | ||
| 203 | void | 203 | void |
| 204 | pqueue_print(pqueue_s *pq) | 204 | pqueue_print(pqueue_s *pq) |
| 205 | { | 205 | { |
| @@ -207,11 +207,14 @@ pqueue_print(pqueue_s *pq) | |||
| 207 | 207 | ||
| 208 | while(item != NULL) | 208 | while(item != NULL) |
| 209 | { | 209 | { |
| 210 | printf("item\t" PQ_64BIT_PRINT "\n", item->priority); | 210 | printf("item\t%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 211 | item->priority[0],item->priority[1], | ||
| 212 | item->priority[2],item->priority[3], | ||
| 213 | item->priority[4],item->priority[5], | ||
| 214 | item->priority[6],item->priority[7]); | ||
| 211 | item = item->next; | 215 | item = item->next; |
| 212 | } | 216 | } |
| 213 | } | 217 | } |
| 214 | #endif | ||
| 215 | 218 | ||
| 216 | pitem * | 219 | pitem * |
| 217 | pqueue_iterator(pqueue_s *pq) | 220 | pqueue_iterator(pqueue_s *pq) |
| @@ -234,3 +237,17 @@ pqueue_next(pitem **item) | |||
| 234 | 237 | ||
| 235 | return ret; | 238 | return ret; |
| 236 | } | 239 | } |
| 240 | |||
| 241 | int | ||
| 242 | pqueue_size(pqueue_s *pq) | ||
| 243 | { | ||
| 244 | pitem *item = pq->items; | ||
| 245 | int count = 0; | ||
| 246 | |||
| 247 | while(item != NULL) | ||
| 248 | { | ||
| 249 | count++; | ||
| 250 | item = item->next; | ||
| 251 | } | ||
| 252 | return count; | ||
| 253 | } | ||
