src/cx/list.h

Tue, 21 Mar 2023 17:21:20 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 21 Mar 2023 17:21:20 +0100
changeset 668
d7129285ac32
parent 667
2f88a7c13a28
child 669
dce9b8450656
permissions
-rw-r--r--

add CX_STORE_POINTERS special item size for maps

390
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 439
diff changeset
28 /**
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 439
diff changeset
29 * \file list.h
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 439
diff changeset
30 * \brief Interface for list implementations.
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 439
diff changeset
31 * \author Mike Becker
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 439
diff changeset
32 * \author Olaf Wintermann
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 439
diff changeset
33 * \version 3.0
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 439
diff changeset
34 * \copyright 2-Clause BSD License
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 439
diff changeset
35 */
390
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 #ifndef UCX_LIST_H
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 #define UCX_LIST_H
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39
484
9e6900b1cf9d add common.h include to all other header files
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
40 #include "common.h"
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
41 #include "allocator.h"
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
42 #include "iterator.h"
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
43
415
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
44 #ifdef __cplusplus
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
45 extern "C" {
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
46 #endif
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
47
667
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
48 #ifndef CX_STORE_POINTERS
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
49 #define CX_STORE_POINTERS 0
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
50 #endif
2f88a7c13a28 add CX_STORE_POINTERS special "item size" for lists
Mike Becker <universe@uap-core.de>
parents: 666
diff changeset
51
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
52 /**
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
53 * A comparator function comparing two list elements.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
54 */
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
55 typedef int(*CxListComparator)(
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
56 void const *left,
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
57 void const *right
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
58 );
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
59
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
60 /**
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
61 * List class type.
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
62 */
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
63 typedef struct cx_list_class_s cx_list_class;
435
0fe204d50f54 change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents: 415
diff changeset
64
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
65 /**
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
66 * Structure for holding the base data of a list.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
67 */
435
0fe204d50f54 change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents: 415
diff changeset
68 struct cx_list_s {
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
69 /**
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
70 * The list class definition.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
71 */
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
72 cx_list_class const *cl;
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
73 /**
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
74 * The actual implementation in case the list class is delegating.
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
75 */
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
76 cx_list_class const *climpl;
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
77 /**
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
78 * The allocator to use.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
79 */
508
8aea65ae1eaf #168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
80 CxAllocator const *allocator;
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
81 /**
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
82 * The comparator function for the elements.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
83 */
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
84 CxListComparator cmpfunc;
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
85 /**
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
86 * The size of each element (payload only).
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
87 */
401
e6a8f7fb0c45 copy list items when they are added to the list
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
88 size_t itemsize;
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
89 /**
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
90 * The size of the list (number of currently stored elements).
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
91 */
401
e6a8f7fb0c45 copy list items when they are added to the list
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
92 size_t size;
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
93 /**
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
94 * The capacity of the list (maximum number of elements).
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
95 */
401
e6a8f7fb0c45 copy list items when they are added to the list
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
96 size_t capacity;
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
97 union {
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
98 /**
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
99 * An optional simple destructor for the list contents that admits the free() interface.
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
100 *
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
101 * @remark Set content_destructor_type to #CX_DESTRUCTOR_SIMPLE.
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
102 *
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
103 * @attention Read the documentation of the particular list implementation
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
104 * whether this destructor shall only destroy the contents or also free the memory.
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
105 */
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
106 cx_destructor_func simple_destructor;
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
107 /**
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
108 * An optional advanced destructor for the list contents providing additional data.
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
109 *
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
110 * @remark Set content_destructor_type to #CX_DESTRUCTOR_ADVANCED.
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
111 *
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
112 * @attention Read the documentation of the particular list implementation
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
113 * whether this destructor shall only destroy the contents or also free the memory.
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
114 */
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
115 cx_advanced_destructor advanced_destructor;
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
116 };
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
117 /**
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
118 * The type of destructor to use.
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
119 */
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
120 enum cx_destructor_type content_destructor_type;
435
0fe204d50f54 change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents: 415
diff changeset
121 };
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
122
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
123 /**
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
124 * The class definition for arbitrary lists.
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
125 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
126 struct cx_list_class_s {
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
127 /**
524
e98b09018d32 remove list destructor
Mike Becker <universe@uap-core.de>
parents: 519
diff changeset
128 * Destructor function.
e98b09018d32 remove list destructor
Mike Becker <universe@uap-core.de>
parents: 519
diff changeset
129 */
e98b09018d32 remove list destructor
Mike Becker <universe@uap-core.de>
parents: 519
diff changeset
130 void (*destructor)(struct cx_list_s *list);
e98b09018d32 remove list destructor
Mike Becker <universe@uap-core.de>
parents: 519
diff changeset
131
e98b09018d32 remove list destructor
Mike Becker <universe@uap-core.de>
parents: 519
diff changeset
132 /**
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
133 * Member function for inserting a single elements.
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
134 * Implementors SHOULD see to performant implementations for corner cases.
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
135 */
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
136 int (*insert_element)(
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
137 struct cx_list_s *list,
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
138 size_t index,
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
139 void const *data
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
140 );
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
141
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
142 /**
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
143 * Member function for inserting multiple elements.
640
55cc3b373c5e simplify list class - fixes #236
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
144 * Implementors SHOULD see to performant implementations for corner cases.
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
145 */
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
146 size_t (*insert_array)(
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
147 struct cx_list_s *list,
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
148 size_t index,
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
149 void const *data,
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
150 size_t n
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
151 );
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
152
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
153 /**
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
154 * Member function for inserting an element relative to an iterator position.
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
155 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
156 int (*insert_iter)(
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
157 struct cx_mut_iterator_s *iter,
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
158 void const *elem,
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
159 int prepend
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
160 );
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
161
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
162 /**
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
163 * Member function for removing an element.
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
164 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
165 int (*remove)(
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
166 struct cx_list_s *list,
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
167 size_t index
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
168 );
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
169
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
170 /**
664
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
171 * Member function for removing all elements.
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
172 */
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
173 void (*clear)(struct cx_list_s *list);
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
174
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
175 /**
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
176 * Member function for swapping two elements.
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
177 */
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
178 int (*swap)(
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
179 struct cx_list_s *list,
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
180 size_t i,
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
181 size_t j
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
182 );
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
183
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
184 /**
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
185 * Member function for element lookup.
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
186 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
187 void *(*at)(
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
188 struct cx_list_s const *list,
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
189 size_t index
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
190 );
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
191
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
192 /**
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
193 * Member function for finding an element.
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
194 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
195 size_t (*find)(
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
196 struct cx_list_s const *list,
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
197 void const *elem
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
198 );
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
199
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
200 /**
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
201 * Member function for sorting the list in place.
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
202 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
203 void (*sort)(struct cx_list_s *list);
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
204
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
205 /**
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
206 * Member function for comparing this list to another list of the same type.
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
207 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
208 int (*compare)(
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
209 struct cx_list_s const *list,
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
210 struct cx_list_s const *other
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
211 );
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
212
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
213 /**
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
214 * Member function for reversing the order of the items.
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
215 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
216 void (*reverse)(struct cx_list_s *list);
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
217
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
218 /**
640
55cc3b373c5e simplify list class - fixes #236
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
219 * Member function for returning an iterator pointing to the specified index.
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
220 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
221 struct cx_iterator_s (*iterator)(
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
222 struct cx_list_s const *list,
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
223 size_t index,
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
224 bool backward
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
225 );
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
226 };
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
227
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
228 /**
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
229 * Common type for all list implementations.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
230 */
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
231 typedef struct cx_list_s CxList;
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
232
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
233 /**
666
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
234 * Invokes the configured destructor function for a specific element.
664
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
235 *
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
236 * Usually only used by list implementations. There should be no need
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
237 * to invoke this function manually.
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
238 *
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
239 * @param list the list
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
240 * @param elem the element
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
241 */
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
242 __attribute__((__nonnull__))
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
243 void cx_list_invoke_destructor(
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
244 struct cx_list_s const *list,
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
245 void *elem
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
246 );
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
247
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
248 /**
666
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
249 * Invokes the simple destructor function for a specific element.
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
250 *
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
251 * Usually only used by list implementations. There should be no need
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
252 * to invoke this function manually.
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
253 *
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
254 * @param list the list
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
255 * @param elem the element
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
256 */
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
257 __attribute__((__nonnull__))
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
258 void cx_list_invoke_simple_destructor(
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
259 struct cx_list_s const *list,
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
260 void *elem
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
261 );
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
262
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
263 /**
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
264 * Invokes the advanced destructor function for a specific element.
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
265 *
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
266 * Usually only used by list implementations. There should be no need
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
267 * to invoke this function manually.
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
268 *
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
269 * @param list the list
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
270 * @param elem the element
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
271 */
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
272 __attribute__((__nonnull__))
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
273 void cx_list_invoke_advanced_destructor(
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
274 struct cx_list_s const *list,
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
275 void *elem
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
276 );
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
277
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
278 /**
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
279 * Advises the list to store copies of the objects (default mode of operation).
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
280 *
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
281 * Retrieving objects from this list will yield pointers to the copies stored
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
282 * within this list.
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
283 *
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
284 * @param list the list
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
285 * @see cxListStorePointers()
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
286 */
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
287 __attribute__((__nonnull__))
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
288 void cxListStoreObjects(CxList *list);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
289
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
290 /**
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
291 * Advises the list to only store pointers to the objects.
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
292 *
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
293 * Retrieving objects from this list will yield the original pointers stored.
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
294 *
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
295 * @note This function forcibly sets the element size to the size of a pointer.
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
296 * Invoking this function on a non-empty list that already stores copies of
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
297 * objects is undefined.
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
298 *
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
299 * @param list the list
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
300 * @see cxListStoreObjects()
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
301 */
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
302 __attribute__((__nonnull__))
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
303 void cxListStorePointers(CxList *list);
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
304
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
305 /**
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
306 * Returns true, if this list is storing pointers instead of the actual data.
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
307 *
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
308 * @param list
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
309 * @return
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
310 * @see cxListStorePointers()
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
311 */
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
312 __attribute__((__nonnull__))
666
b5dd654deb3b add unit test for cxListClear + fix destructor functions not always invoked with the correct pointer
Mike Becker <universe@uap-core.de>
parents: 664
diff changeset
313 bool cxListIsStoringPointers(CxList const *list);
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
314
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
315 /**
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
316 * Adds an item to the end of the list.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
317 *
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
318 * @param list the list
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
319 * @param elem a pointer to the element to add
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
320 * @return zero on success, non-zero on memory allocation failure
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
321 * @see cxListAddArray()
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
322 */
508
8aea65ae1eaf #168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
323 __attribute__((__nonnull__))
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
324 static inline int cxListAdd(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
325 CxList *list,
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
326 void const *elem
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
327 ) {
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
328 return list->cl->insert_element(list, list->size, elem);
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
329 }
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
330
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
331 /**
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
332 * Adds multiple items to the end of the list.
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
333 *
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
334 * This method is more efficient than invoking cxListAdd() multiple times.
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
335 *
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
336 * If there is not enough memory to add all elements, the returned value is
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
337 * less than \p n.
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
338 *
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
339 * If this list is storing pointers instead of objects \p array is expected to
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
340 * be an array of pointers.
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
341 *
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
342 * @param list the list
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
343 * @param array a pointer to the elements to add
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
344 * @param n the number of elements to add
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
345 * @return the number of added elements
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
346 */
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
347 __attribute__((__nonnull__))
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
348 static inline size_t cxListAddArray(
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
349 CxList *list,
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
350 void const *array,
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
351 size_t n
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
352 ) {
640
55cc3b373c5e simplify list class - fixes #236
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
353 return list->cl->insert_array(list, list->size, array, n);
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
354 }
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
355
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
356 /**
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
357 * Inserts an item at the specified index.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
358 *
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
359 * If \p index equals the list \c size, this is effectively cxListAdd().
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
360 *
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
361 * @param list the list
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
362 * @param index the index the element shall have
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
363 * @param elem a pointer to the element to add
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
364 * @return zero on success, non-zero on memory allocation failure
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
365 * or when the index is out of bounds
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
366 * @see cxListInsertAfter()
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
367 * @see cxListInsertBefore()
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
368 */
508
8aea65ae1eaf #168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
369 __attribute__((__nonnull__))
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
370 static inline int cxListInsert(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
371 CxList *list,
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
372 size_t index,
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
373 void const *elem
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
374 ) {
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
375 return list->cl->insert_element(list, index, elem);
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
376 }
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
377
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
378 /**
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
379 * Inserts multiple items to the list at the specified index.
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
380 * If \p index equals the list size, this is effectively cxListAddArray().
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
381 *
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
382 * This method is usually more efficient than invoking cxListInsert()
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
383 * multiple times.
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
384 *
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
385 * If there is not enough memory to add all elements, the returned value is
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
386 * less than \p n.
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
387 *
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
388 * If this list is storing pointers instead of objects \p array is expected to
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
389 * be an array of pointers.
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
390 *
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
391 * @param list the list
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
392 * @param index the index where to add the elements
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
393 * @param array a pointer to the elements to add
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
394 * @param n the number of elements to add
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
395 * @return the number of added elements
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
396 */
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
397 __attribute__((__nonnull__))
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
398 static inline size_t cxListInsertArray(
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
399 CxList *list,
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
400 size_t index,
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
401 void const *array,
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
402 size_t n
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
403 ) {
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
404 return list->cl->insert_array(list, index, array, n);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
405 }
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
406
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
407 /**
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
408 * Inserts an element after the current location of the specified iterator.
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
409 *
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
410 * The used iterator remains operational, but all other active iterators should
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
411 * be considered invalidated.
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
412 *
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
413 * If \p iter is not a list iterator, the behavior is undefined.
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
414 * If \p iter is a past-the-end iterator, the new element gets appended to the list.
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
415 *
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
416 * @param iter an iterator
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
417 * @param elem the element to insert
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
418 * @return zero on success, non-zero on memory allocation failure
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
419 * @see cxListInsert()
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
420 * @see cxListInsertBefore()
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
421 */
508
8aea65ae1eaf #168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
422 __attribute__((__nonnull__))
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
423 static inline int cxListInsertAfter(
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
424 CxMutIterator *iter,
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
425 void const *elem
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
426 ) {
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
427 return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0);
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
428 }
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
429
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
430 /**
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
431 * Inserts an element before the current location of the specified iterator.
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
432 *
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
433 * The used iterator remains operational, but all other active iterators should
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
434 * be considered invalidated.
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
435 *
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
436 * If \p iter is not a list iterator, the behavior is undefined.
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
437 * If \p iter is a past-the-end iterator, the new element gets appended to the list.
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
438 *
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
439 * @param iter an iterator
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
440 * @param elem the element to insert
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
441 * @return zero on success, non-zero on memory allocation failure
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
442 * @see cxListInsert()
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
443 * @see cxListInsertAfter()
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
444 */
508
8aea65ae1eaf #168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
445 __attribute__((__nonnull__))
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
446 static inline int cxListInsertBefore(
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
447 CxMutIterator *iter,
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
448 void const *elem
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
449 ) {
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
450 return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1);
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
451 }
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
452
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
453 /**
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
454 * Removes the element at the specified index.
664
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
455 *
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
456 * If an element destructor function is specified, it is called before
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
457 * removing the element.
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
458 *
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
459 * @param list the list
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
460 * @param index the index of the element
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
461 * @return zero on success, non-zero if the index is out of bounds
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
462 */
508
8aea65ae1eaf #168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
463 __attribute__((__nonnull__))
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
464 static inline int cxListRemove(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
465 CxList *list,
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
466 size_t index
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
467 ) {
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
468 return list->cl->remove(list, index);
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
469 }
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
470
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
471 /**
664
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
472 * Removes all elements from this list.
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
473 *
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
474 * If an element destructor function is specified, it is called for each
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
475 * element before removing them.
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
476 *
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
477 * @param list the list
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
478 */
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
479 __attribute__((__nonnull__))
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
480 static inline void cxListClear(CxList *list) {
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
481 list->cl->clear(list);
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
482 }
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
483
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
484 /**
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
485 * Swaps two items in the list.
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
486 *
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
487 * Implementations should only allocate temporary memory for the swap, if
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
488 * it is necessary.
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
489 *
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
490 * @param list the list
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
491 * @param i the index of the first element
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
492 * @param j the index of the second element
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
493 * @return zero on success, non-zero if one of the indices is out of bounds
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
494 */
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
495 __attribute__((__nonnull__))
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
496 static inline int cxListSwap(
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
497 CxList *list,
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
498 size_t i,
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
499 size_t j
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
500 ) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
501 return list->cl->swap(list, i, j);
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
502 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
503
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
504 /**
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
505 * Returns a pointer to the element at the specified index.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
506 *
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
507 * @param list the list
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
508 * @param index the index of the element
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
509 * @return a pointer to the element or \c NULL if the index is out of bounds
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
510 */
508
8aea65ae1eaf #168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
511 __attribute__((__nonnull__))
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
512 static inline void *cxListAt(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
513 CxList *list,
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
514 size_t index
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
515 ) {
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
516 return list->cl->at(list, index);
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
517 }
439
9a5adedd6de6 add high-level function cxListAt()
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
518
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
519 /**
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
520 * Returns an iterator pointing to the item at the specified index.
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
521 *
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
522 * The returned iterator is position-aware.
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
523 *
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
524 * If the index is out of range, a past-the-end iterator will be returned.
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
525 *
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
526 * @param list the list
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
527 * @param index the index where the iterator shall point at
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
528 * @return a new iterator
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
529 */
508
8aea65ae1eaf #168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
530 __attribute__((__nonnull__, __warn_unused_result__))
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
531 static inline CxIterator cxListIteratorAt(
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
532 CxList const *list,
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
533 size_t index
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
534 ) {
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
535 return list->cl->iterator(list, index, false);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
536 }
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
537
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
538 /**
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
539 * Returns a backwards iterator pointing to the item at the specified index.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
540 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
541 * The returned iterator is position-aware.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
542 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
543 * If the index is out of range, a past-the-end iterator will be returned.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
544 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
545 * @param list the list
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
546 * @param index the index where the iterator shall point at
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
547 * @return a new iterator
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
548 */
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
549 __attribute__((__nonnull__, __warn_unused_result__))
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
550 static inline CxIterator cxListBackwardsIteratorAt(
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
551 CxList const *list,
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
552 size_t index
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
553 ) {
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
554 return list->cl->iterator(list, index, true);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
555 }
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
556
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
557 /**
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
558 * Returns a mutating iterator pointing to the item at the specified index.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
559 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
560 * The returned iterator is position-aware.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
561 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
562 * If the index is out of range, a past-the-end iterator will be returned.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
563 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
564 * @param list the list
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
565 * @param index the index where the iterator shall point at
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
566 * @return a new iterator
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
567 */
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
568 __attribute__((__nonnull__, __warn_unused_result__))
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
569 CxMutIterator cxListMutIteratorAt(
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
570 CxList *list,
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
571 size_t index
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
572 );
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
573
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
574 /**
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
575 * Returns a mutating backwards iterator pointing to the item at the
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
576 * specified index.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
577 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
578 * The returned iterator is position-aware.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
579 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
580 * If the index is out of range, a past-the-end iterator will be returned.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
581 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
582 * @param list the list
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
583 * @param index the index where the iterator shall point at
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
584 * @return a new iterator
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
585 */
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
586 __attribute__((__nonnull__, __warn_unused_result__))
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
587 CxMutIterator cxListMutBackwardsIteratorAt(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
588 CxList *list,
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
589 size_t index
640
55cc3b373c5e simplify list class - fixes #236
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
590 );
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
591
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
592 /**
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
593 * Returns an iterator pointing to the first item of the list.
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
594 *
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
595 * The returned iterator is position-aware.
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
596 *
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
597 * If the list is empty, a past-the-end iterator will be returned.
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
598 *
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
599 * @param list the list
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
600 * @return a new iterator
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
601 */
508
8aea65ae1eaf #168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
602 __attribute__((__nonnull__, __warn_unused_result__))
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
603 static inline CxIterator cxListIterator(CxList const *list) {
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
604 return list->cl->iterator(list, 0, false);
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
605 }
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
606
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
607 /**
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
608 * Returns a mutating iterator pointing to the first item of the list.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
609 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
610 * The returned iterator is position-aware.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
611 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
612 * If the list is empty, a past-the-end iterator will be returned.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
613 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
614 * @param list the list
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
615 * @return a new iterator
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
616 */
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
617 __attribute__((__nonnull__, __warn_unused_result__))
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
618 static inline CxMutIterator cxListMutIterator(CxList *list) {
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
619 return cxListMutIteratorAt(list, 0);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
620 }
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
621
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
622
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
623 /**
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
624 * Returns a backwards iterator pointing to the last item of the list.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
625 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
626 * The returned iterator is position-aware.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
627 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
628 * If the list is empty, a past-the-end iterator will be returned.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
629 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
630 * @param list the list
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
631 * @return a new iterator
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
632 */
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
633 __attribute__((__nonnull__, __warn_unused_result__))
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
634 static inline CxIterator cxListBackwardsIterator(CxList const *list) {
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
635 return list->cl->iterator(list, list->size - 1, true);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
636 }
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
637
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
638 /**
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
639 * Returns a mutating backwards iterator pointing to the last item of the list.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
640 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
641 * The returned iterator is position-aware.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
642 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
643 * If the list is empty, a past-the-end iterator will be returned.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
644 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
645 * @param list the list
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
646 * @return a new iterator
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
647 */
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
648 __attribute__((__nonnull__, __warn_unused_result__))
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
649 static inline CxMutIterator cxListMutBackwardsIterator(CxList *list) {
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
650 return cxListMutBackwardsIteratorAt(list, list->size - 1);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
651 }
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
652
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
653 /**
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
654 * Returns the index of the first element that equals \p elem.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
655 *
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
656 * Determining equality is performed by the list's comparator function.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
657 *
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
658 * @param list the list
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
659 * @param elem the element to find
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
660 * @return the index of the element or \c (size+1) if the element is not found
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
661 */
508
8aea65ae1eaf #168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
662 __attribute__((__nonnull__))
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
663 static inline size_t cxListFind(
621
646e38efc7bc missing const in cxListFind
Mike Becker <universe@uap-core.de>
parents: 618
diff changeset
664 CxList const *list,
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
665 void const *elem
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
666 ) {
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
667 return list->cl->find(list, elem);
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
668 }
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
669
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
670 /**
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
671 * Sorts the list in place.
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
672 *
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
673 * \remark The underlying sort algorithm is implementation defined.
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
674 *
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
675 * @param list the list
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
676 */
508
8aea65ae1eaf #168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
677 __attribute__((__nonnull__))
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
678 static inline void cxListSort(CxList *list) {
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
679 list->cl->sort(list);
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
680 }
404
86ebc3745e62 adds cxListLast
Mike Becker <universe@uap-core.de>
parents: 401
diff changeset
681
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
682 /**
490
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
683 * Reverses the order of the items.
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
684 *
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
685 * @param list the list
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
686 */
508
8aea65ae1eaf #168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
687 __attribute__((__nonnull__))
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
688 static inline void cxListReverse(CxList *list) {
490
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
689 list->cl->reverse(list);
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
690 }
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
691
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
692 /**
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
693 * Compares a list to another list of the same type.
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
694 *
618
1f5a8f6f3015 #219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
695 * First, the list sizes are compared.
1f5a8f6f3015 #219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
696 * If they match, the lists are compared element-wise.
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
697 *
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
698 * @param list the list
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
699 * @param other the list to compare to
618
1f5a8f6f3015 #219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
700 * @return zero, if both lists are equal element wise,
1f5a8f6f3015 #219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
701 * negative if the first list is smaller, positive if the first list is larger
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
702 */
508
8aea65ae1eaf #168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
703 __attribute__((__nonnull__))
618
1f5a8f6f3015 #219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
704 int cxListCompare(
1f5a8f6f3015 #219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
705 CxList const *list,
1f5a8f6f3015 #219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
706 CxList const *other
1f5a8f6f3015 #219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
707 );
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
708
503
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
709 /**
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
710 * Deallocates the memory of the specified list structure.
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
711 *
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
712 * Also calls content a destructor function, depending on the configuration
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
713 * in CxList.content_destructor_type.
503
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
714 *
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
715 * This function itself is a destructor function for the CxList.
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
716 *
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
717 * @param list the list which shall be destroyed
503
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
718 */
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
719 __attribute__((__nonnull__))
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
720 void cxListDestroy(CxList *list);
503
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
721
415
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
722 #ifdef __cplusplus
628
1e2be40f0cb5 use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents: 621
diff changeset
723 } // extern "C"
415
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
724 #endif
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
725
628
1e2be40f0cb5 use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents: 621
diff changeset
726 #endif // UCX_LIST_H

mercurial