| 403 | } |
| 404 | |
| 405 | void h2_iq_sort(h2_iqueue *q, h2_iq_cmp *cmp, void *ctx) |
| 406 | { |
| 407 | /* Assume that changes in ordering are minimal. This needs, |
| 408 | * best case, q->nelts - 1 comparisons to check that nothing |
| 409 | * changed. |
| 410 | */ |
| 411 | if (q->nelts > 0) { |
| 412 | int i, ni, prev, last; |
| 413 | |
| 414 | /* Start at the end of the queue and create a tail of sorted |
| 415 | * entries. Make that tail one element longer in each iteration. |
| 416 | */ |
| 417 | last = i = (q->head + q->nelts - 1) % q->nalloc; |
| 418 | while (i != q->head) { |
| 419 | prev = (q->nalloc + i - 1) % q->nalloc; |
| 420 | |
| 421 | ni = iq_bubble_up(q, i, prev, cmp, ctx); |
| 422 | if (ni == prev) { |
| 423 | /* i bubbled one up, bubble the new i down, which |
| 424 | * keeps all ints below i sorted. */ |
| 425 | iq_bubble_down(q, i, last, cmp, ctx); |
| 426 | } |
| 427 | i = prev; |
| 428 | }; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | |
| 433 | int h2_iq_shift(h2_iqueue *q) |
no test coverage detected