util: added a reverse insert (sorted) routine to TAILQ
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.
This commit is contained in:
parent
c26ccaba3d
commit
248b682c84
1 changed files with 18 additions and 0 deletions
18
src/queue.h
18
src/queue.h
|
@ -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; \
|
||||
|
|
Loading…
Add table
Reference in a new issue