summaryrefslogtreecommitdiffstats
path: root/src/list.h
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2008-05-01 18:00:08 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2008-05-01 18:00:08 +0200
commit9d87952b714a304502e39edc5a7ce12e5ef01abd (patch)
tree3206b27caf07dd6ad596ebfde9ca394bc16c76cc /src/list.h
parent799317c37c2aa08b65a3a5ff7be977b16987ead7 (diff)
Add td_list_add_sorted() function for insertion in a sorted list
Diffstat (limited to 'src/list.h')
-rw-r--r--src/list.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/list.h b/src/list.h
index f79640c..2bbd200 100644
--- a/src/list.h
+++ b/src/list.h
@@ -2,7 +2,7 @@
File: list.h
- Copyright (C) 2006 Christophe GRENIER <grenier@cgsecurity.org>
+ Copyright (C) 2006-2008 Christophe GRENIER <grenier@cgsecurity.org>
This software is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -333,4 +333,18 @@ static inline void td_list_splice_init(struct td_list_head *list,
pos = n, n = td_list_entry(n->member.next, typeof(*n), member))
+static inline void td_list_add_sorted(struct td_list_head *new, struct td_list_head *head,
+ int (*compar)(const struct td_list_head *a, const struct td_list_head *b))
+{
+ struct td_list_head *pos;
+ td_list_for_each(pos, head)
+ {
+ if(compar(new,pos)<0)
+ {
+ __td_list_add(new, pos->prev, pos);
+ return ;
+ }
+ }
+ td_list_add_tail(new, head);
+}
#endif