ucx/list.h

changeset 123
7fb0f74517c5
parent 122
540d99722f1f
child 124
8b44653541ef
equal deleted inserted replaced
122:540d99722f1f 123:7fb0f74517c5
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28 /**
29 * Double linked list implementation.
30 *
31 * @file list.h
32 * @author Mike Becker
33 * @author Olaf Wintermann
27 */ 34 */
28 35
29 #ifndef UCX_LIST_H 36 #ifndef UCX_LIST_H
30 #define UCX_LIST_H 37 #define UCX_LIST_H
31 38
50 * @param elem The variable name of the element 57 * @param elem The variable name of the element
51 */ 58 */
52 #define UCX_FOREACH(elem,list) \ 59 #define UCX_FOREACH(elem,list) \
53 for (UcxList* elem = list ; elem != NULL ; elem = elem->next) 60 for (UcxList* elem = list ; elem != NULL ; elem = elem->next)
54 61
62 /**
63 * UCX list type
64 * @see UcxList
65 */
55 typedef struct UcxList UcxList; 66 typedef struct UcxList UcxList;
56 struct UcxList { 67 struct UcxList {
68 /**
69 * List element payload.
70 */
57 void *data; 71 void *data;
72 /**
73 * Pointer to the next list element or <code>NULL</code>, if this is the
74 * last element.
75 */
58 UcxList *next; 76 UcxList *next;
77 /**
78 * Pointer to the previous list element or <code>NULL</code>, if this is
79 * the first element.
80 */
59 UcxList *prev; 81 UcxList *prev;
60 }; 82 };
61 83
62 UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void* data); 84 UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void* data);
63 int ucx_list_equals(const UcxList *l1, const UcxList *l2,
64 cmp_func fnc, void* data);
65 85
66 void ucx_list_free(UcxList *l); 86 /**
67 UcxList *ucx_list_append(UcxList *l, void *data); 87 * Compares two UCX lists element-wise by using a compare function.
68 UcxList *ucx_list_prepend(UcxList *l, void *data); 88 *
69 UcxList *ucx_list_concat(UcxList *l1, UcxList *l2); 89 * Each element of the two specified lists are compared by using the specified
70 UcxList *ucx_list_last(const UcxList *l); 90 * compare function and the additional data. The type and content of this
71 UcxList *ucx_list_get(const UcxList *l, int index); 91 * additional data depends on the cmp_func() used.
72 size_t ucx_list_size(const UcxList *l); 92 *
73 int ucx_list_contains(UcxList *l, void *elem, cmp_func fnc, void *cmpdata); 93 * If the list pointers denote elements within a list, the lists are compared
94 * starting with the denoted elements. Thus any previous elements are not taken
95 * into account. This might be useful to check, if certain list tails match
96 * each other.
97 *
98 * @param list1 the first list
99 * @param list2 the second list
100 * @param cmpfnc the compare function
101 * @param data additional data for the compare function
102 * @return 1, if and only if the two lists equal element-wise, 0 otherwise
103 */
104 int ucx_list_equals(const UcxList *list1, const UcxList *list2,
105 cmp_func cmpfnc, void* data);
74 106
75 UcxList *ucx_list_sort(UcxList *l, cmp_func fnc, void *data); 107 /**
108 * Destroys the entire list.
109 *
110 * The members of the list are not automatically freed, so ensure they are
111 * otherwise referenced or a memory leak will occur.
112 *
113 * <b>Caution:</b> the argument <b>MUST</b> denote an entire list (i.e. a call
114 * to ucx_list_first() on the argument must return the argument itself)
115 *
116 * @param list The list to free.
117 */
118 void ucx_list_free(UcxList *list);
119 UcxList *ucx_list_append(UcxList *list, void *data);
120 UcxList *ucx_list_prepend(UcxList *list, void *data);
121 UcxList *ucx_list_concat(UcxList *list1, UcxList *list2);
122 UcxList *ucx_list_last(const UcxList *list);
123 UcxList *ucx_list_get(const UcxList *list, int index);
124 ssize_t ucx_list_indexof(const UcxList *list, const UcxList *elem);
125 size_t ucx_list_size(const UcxList *list);
126 ssize_t ucx_list_find(UcxList *list, void *elem, cmp_func fnc, void *cmpdata);
127 int ucx_list_contains(UcxList *list, void *elem, cmp_func fnc, void *cmpdata);
76 128
77 UcxList *ucx_list_first(const UcxList *l); 129 UcxList *ucx_list_sort(UcxList *list, cmp_func cmpfnc, void *data);
78 UcxList *ucx_list_remove(UcxList *l, UcxList *e); 130
131 UcxList *ucx_list_first(const UcxList *list);
132 UcxList *ucx_list_remove(UcxList *list, UcxList *element);
79 133
80 #ifdef __cplusplus 134 #ifdef __cplusplus
81 } 135 }
82 #endif 136 #endif
83 137

mercurial