Skip to content

Commit

Permalink
util: added a reverse insert (sorted) routine to TAILQ
Browse files Browse the repository at this point in the history
This changes the way in which equal objects are handled. Previously they'd
be added to the HEAD and with this they add to the TAIL, which is what I
need in network scanning code.
  • Loading branch information
adamsutton committed Jun 9, 2014
1 parent c26ccab commit 248b682
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@
} \
} while(0)

#define TAILQ_INSERT_SORTED_R(head, headname, elm, field, cmpfunc) do { \
if(TAILQ_FIRST(head) == NULL) { \
TAILQ_INSERT_HEAD(head, elm, field); \
} else { \
typeof(elm) _tmp; \
TAILQ_FOREACH_REVERSE(_tmp,head,headname,field) { \
if(cmpfunc(elm,_tmp) >= 0) { \
TAILQ_INSERT_AFTER(head,_tmp,elm,field); \
break; \
} \
if(!TAILQ_PREV(_tmp,headname,field)) { \
TAILQ_INSERT_BEFORE(_tmp,elm,field); \
break; \
} \
} \
} \
} while(0)

#define TAILQ_MOVE(newhead, oldhead, field) do { \
if(TAILQ_FIRST(oldhead)) { \
TAILQ_FIRST(oldhead)->field.tqe_prev = &(newhead)->tqh_first; \
Expand Down

0 comments on commit 248b682

Please sign in to comment.