2 * Sorted list - linked list with sortkey
4 * $Id: s.sortedlist.h 1.6 03/04/10 13:09:54+03:00 anttit@jon.mipl.mediapoli.com $
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.
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
20 int mipv6_bitwise_compare(const void *data1, const void *data2, int datalen);
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
29 * Allocates memory for entry and data
31 int mipv6_slist_add(struct list_head *head, void *data, int datalen,
32 unsigned long sortkey);
35 * mipv6_slist_get_first - get the first data item in the list
36 * @head: list_head of the sorted list
38 * Returns the actual data item, not copy, so don't kfree it
40 void *mipv6_slist_get_first(struct list_head *head);
43 * mipv6_slist_del_first - delete (and get) the first item in list
44 * @head: list_head of the sorted list
46 * Remember to kfree the item
48 void *mipv6_slist_del_first(struct list_head *head);
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
56 * compare function needs to have prototype
57 * int (*compare)(const void *data1, const void *data2, int datalen) where
60 int mipv6_slist_del_item(struct list_head *head, void *data,
61 int (*compare)(const void *data1, const void *data2,
65 * mipv6_slist_get_first_key - get sortkey of the first item
66 * @head: list_head of the sorted list
68 unsigned long mipv6_slist_get_first_key(struct list_head *head);
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
76 * compare function needs to have prototype
77 * int (*compare)(const void *data1, const void *data2, int datalen) where
80 unsigned long mipv6_slist_get_key(struct list_head *head, void *data,
81 int (*compare)(const void *data1,
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
90 * Returns the actual data item, not copy, so don't kfree it
92 void *mipv6_slist_get_data(struct list_head *head, unsigned long sortkey);
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
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.
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,
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
118 int mipv6_slist_push_first(struct list_head *head, unsigned long new_key);
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
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
131 int mipv6_slist_for_each(struct list_head *head, void *args,
132 int (*func)(void *data, void *args,
133 unsigned long sortkey));