ef3bb3b629b071a7e4a04462c0af98a35598538e
[linux-flexiantxendom0-3.2.10.git] / net / ipv6 / mobile_ip6 / sortedlist.h
1 /*
2  *      Sorted list - linked list with sortkey
3  *
4  *      $Id: s.sortedlist.h 1.6 03/04/10 13:09:54+03:00 anttit@jon.mipl.mediapoli.com $
5  *
6  *      This program is free software; you can redistribute it and/or
7  *      modify it under the terms of the GNU General Public License
8  *      as published by the Free Software Foundation; either version
9  *      2 of the License, or (at your option) any later version.
10  */
11
12 /**
13  * compare - compares two arbitrary data items
14  * @data1: first data item
15  * @data2: second data item
16  * @datalen: length of data items in bits
17  *
18  * datalen is in bits!
19  */
20 int mipv6_bitwise_compare(const void *data1, const void *data2, int datalen);
21
22 /**
23  * mipv6_slist_add - add an entry to sorted list
24  * @head: list_head of the sorted list
25  * @data: item to store
26  * @datalen: length of data (in bytes)
27  * @key: sortkey of item
28  *
29  * Allocates memory for entry and data
30  */
31 int mipv6_slist_add(struct list_head *head, void *data, int datalen,
32                     unsigned long sortkey);
33
34 /**
35  * mipv6_slist_get_first - get the first data item in the list
36  * @head: list_head of the sorted list
37  *
38  * Returns the actual data item, not copy, so don't kfree it
39  */
40 void *mipv6_slist_get_first(struct list_head *head);
41
42 /**
43  * mipv6_slist_del_first - delete (and get) the first item in list
44  * @head: list_head of the sorted list
45  *
46  * Remember to kfree the item
47  */
48 void *mipv6_slist_del_first(struct list_head *head);
49
50 /**
51  * mipv6_slist_del_item - delete entry
52  * @head: list_head of the sorted list
53  * @data: item to delete
54  * @compare: function used for comparing the data items
55  *
56  * compare function needs to have prototype
57  * int (*compare)(const void *data1, const void *data2, int datalen) where
58  * datalen is in bits
59  */
60 int mipv6_slist_del_item(struct list_head *head, void *data,
61                          int (*compare)(const void *data1, const void *data2,
62                                         int datalen));
63
64 /**
65  * mipv6_slist_get_first_key - get sortkey of the first item
66  * @head: list_head of the sorted list
67  */
68 unsigned long mipv6_slist_get_first_key(struct list_head *head);
69
70 /**
71  * mipv6_slist_get_key - get sortkey of the data item
72  * @head: list_head of the sorted list
73  * @data: the item to search for
74  * @compare: function used for comparing the data items
75  *
76  * compare function needs to have prototype
77  * int (*compare)(const void *data1, const void *data2, int datalen) where
78  * datalen is in bits
79  */
80 unsigned long mipv6_slist_get_key(struct list_head *head, void *data,
81                                   int (*compare)(const void *data1,
82                                                  const void *data2,
83                                                  int datalen));
84
85 /**
86  * mipv6_slist_get_data - get the data item identified by sortkey
87  * @head: list_head of the sorted list
88  * @key: sortkey of the item
89  *
90  * Returns the actual data item, not copy, so don't kfree it
91  */
92 void *mipv6_slist_get_data(struct list_head *head, unsigned long sortkey);
93
94 /**
95  * mipv6_slist_modify - modify data item
96  * @head: list_head of the sorted list
97  * @data: item, whose sortkey is to be modified
98  * @datalen: datalen in bytes
99  * @new_key: new sortkey
100  * @compare: function used for comparing the data items
101  *
102  * Compies the new data on top of the old one, if compare function returns
103  * non-negative. If there's no matching entry, new one will be created.
104  * Compare function needs to have prototype
105  * int (*compare)(const void *data1, const void *data2, int datalen) where
106  * datalen is in bits.
107  */
108 int mipv6_slist_modify(struct list_head *head, void *data, int datalen,
109                        unsigned long new_key,
110                        int (*compare)(const void *data1, const void *data2,
111                                       int datalen));
112
113 /**
114  * mipv6_slist_push_first - move the first entry to place indicated by new_key
115  * @head: list_head of the sorted list
116  * @new_key: new sortkey
117  */
118 int mipv6_slist_push_first(struct list_head *head, unsigned long new_key);
119
120 /**
121  * mipv6_slist_for_each - apply func to every item in list
122  * @head: list_head of the sorted list
123  * @args: args to pass to func
124  * @func: function to use
125  *
126  * function must be of type
127  * int (*func)(void *data, void *args, unsigned long sortkey)
128  * List iteration will stop once func has been applied to every item
129  * or when func returns true
130  */
131 int mipv6_slist_for_each(struct list_head *head, void *args,
132                          int (*func)(void *data, void *args,
133                                      unsigned long sortkey));