src/cx/list.h

Mon, 06 Jan 2025 23:29:41 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 06 Jan 2025 23:29:41 +0100
changeset 1111
78eeeb950883
parent 1109
89ec23988b88
permissions
-rw-r--r--

remove API for changing the store_pointer property after list creation

fixes #553

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 /**
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
29 * @file list.h
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
30 * @brief Interface for list implementations.
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
31 * @author Mike Becker
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
32 * @author Olaf Wintermann
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
33 * @copyright 2-Clause BSD License
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 439
diff changeset
34 */
390
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 #ifndef UCX_LIST_H
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 #define UCX_LIST_H
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38
681
502105523db7 fix common.h include problems - fixes #255
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
39 #include "common.h"
677
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 669
diff changeset
40 #include "collection.h"
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
41
415
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
42 #ifdef __cplusplus
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
43 extern "C" {
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
44 #endif
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
45
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
46 /**
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
47 * List class type.
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
48 */
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
49 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
50
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
51 /**
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
52 * 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
53 */
435
0fe204d50f54 change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents: 415
diff changeset
54 struct cx_list_s {
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
55 /**
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
56 * Common members for collections.
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
57 */
854
fe0d69d72bcd fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents: 853
diff changeset
58 CX_COLLECTION_BASE;
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
59 /**
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
60 * The list class definition.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
61 */
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
62 const cx_list_class *cl;
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
63 /**
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
64 * 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
65 */
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
66 const cx_list_class *climpl;
435
0fe204d50f54 change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents: 415
diff changeset
67 };
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
68
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
69 /**
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
70 * The class definition for arbitrary lists.
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
71 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
72 struct cx_list_class_s {
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
73 /**
524
e98b09018d32 remove list destructor
Mike Becker <universe@uap-core.de>
parents: 519
diff changeset
74 * Destructor function.
708
1caed6c9ba68 fix inconsistent destructor requirements for list and map classes
Mike Becker <universe@uap-core.de>
parents: 704
diff changeset
75 *
1caed6c9ba68 fix inconsistent destructor requirements for list and map classes
Mike Becker <universe@uap-core.de>
parents: 704
diff changeset
76 * Implementations SHALL invoke the content destructor functions if provided
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
77 * and SHALL deallocate the entire list memory.
524
e98b09018d32 remove list destructor
Mike Becker <universe@uap-core.de>
parents: 519
diff changeset
78 */
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
79 void (*deallocate)(struct cx_list_s *list);
524
e98b09018d32 remove list destructor
Mike Becker <universe@uap-core.de>
parents: 519
diff changeset
80
e98b09018d32 remove list destructor
Mike Becker <universe@uap-core.de>
parents: 519
diff changeset
81 /**
739
529c35a768f3 fix typo in list.h
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 708
diff changeset
82 * Member function for inserting a single element.
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
83 * 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
84 */
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
85 int (*insert_element)(
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
86 struct cx_list_s *list,
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
87 size_t index,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
88 const void *data
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
89 );
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
90
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
91 /**
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
92 * Member function for inserting multiple elements.
640
55cc3b373c5e simplify list class - fixes #236
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
93 * Implementors SHOULD see to performant implementations for corner cases.
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
94 *
875
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
95 * @see cx_list_default_insert_array()
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
96 */
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
97 size_t (*insert_array)(
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
98 struct cx_list_s *list,
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
99 size_t index,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
100 const void *data,
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
101 size_t n
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
102 );
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
103
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
104 /**
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
105 * Member function for inserting sorted elements into a sorted list.
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
106 *
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
107 * @see cx_list_default_insert_sorted()
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
108 */
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
109 size_t (*insert_sorted)(
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
110 struct cx_list_s *list,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
111 const void *sorted_data,
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
112 size_t n
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
113 );
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
114
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
115 /**
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
116 * 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
117 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
118 int (*insert_iter)(
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
119 struct cx_iterator_s *iter,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
120 const void *elem,
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
121 int prepend
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
122 );
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
123
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
124 /**
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
125 * Member function for removing elements.
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
126 *
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
127 * Implementations SHALL check if @p targetbuf is set and copy the elements
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
128 * to the buffer without invoking any destructor.
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
129 * When @p targetbuf is not set, the destructors SHALL be invoked.
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
130 *
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
131 * The function SHALL return the actual number of elements removed, which
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
132 * might be lower than @p num when going out of bounds.
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
133 */
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
134 size_t (*remove)(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
135 struct cx_list_s *list,
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
136 size_t index,
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
137 size_t num,
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
138 void *targetbuf
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
139 );
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
140
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
141 /**
664
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
142 * 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
143 */
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
144 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
145
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
146 /**
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
147 * Member function for swapping two elements.
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
148 *
875
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
149 * @see cx_list_default_swap()
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
150 */
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
151 int (*swap)(
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
152 struct cx_list_s *list,
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
153 size_t i,
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
154 size_t j
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
155 );
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
156
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
157 /**
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
158 * Member function for element lookup.
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
159 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
160 void *(*at)(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
161 const struct cx_list_s *list,
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
162 size_t index
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
163 );
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 /**
764
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
166 * Member function for finding and optionally removing an element.
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
167 */
764
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
168 ssize_t (*find_remove)(
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
169 struct cx_list_s *list,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
170 const void *elem,
764
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
171 bool remove
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
172 );
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
173
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
174 /**
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
175 * Member function for sorting the list.
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
176 *
875
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
177 * @see cx_list_default_sort()
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
178 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
179 void (*sort)(struct cx_list_s *list);
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
180
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
181 /**
875
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
182 * Optional member function for comparing this list
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
183 * to another list of the same type.
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
184 * If set to @c NULL, comparison won't be optimized.
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
185 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
186 cx_attr_nonnull
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
187 int (*compare)(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
188 const struct cx_list_s *list,
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
189 const struct cx_list_s *other
500
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 reversing the order of the items.
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 void (*reverse)(struct cx_list_s *list);
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
196
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
197 /**
640
55cc3b373c5e simplify list class - fixes #236
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
198 * 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
199 */
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
200 struct cx_iterator_s (*iterator)(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
201 const struct cx_list_s *list,
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
202 size_t index,
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
203 bool backward
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
204 );
500
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
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
207 /**
875
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
208 * Default implementation of an array insert.
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
209 *
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
210 * This function uses the element insert function for each element of the array.
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
211 *
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
212 * Use this in your own list class if you do not want to implement an optimized
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
213 * version for your list.
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
214 *
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
215 * @param list the list
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
216 * @param index the index where to insert the data
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
217 * @param data a pointer to the array of data to insert
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
218 * @param n the number of elements to insert
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
219 * @return the number of elements actually inserted
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
220 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
221 cx_attr_nonnull
875
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
222 size_t cx_list_default_insert_array(
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
223 struct cx_list_s *list,
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
224 size_t index,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
225 const void *data,
875
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
226 size_t n
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
227 );
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
228
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
229 /**
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
230 * Default implementation of a sorted insert.
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
231 *
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
232 * This function uses the array insert function to insert consecutive groups
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
233 * of sorted data.
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
234 *
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
235 * The source data @em must already be sorted wrt. the list's compare function.
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
236 *
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
237 * Use this in your own list class if you do not want to implement an optimized
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
238 * version for your list.
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
239 *
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
240 * @param list the list
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
241 * @param sorted_data a pointer to the array of pre-sorted data to insert
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
242 * @param n the number of elements to insert
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
243 * @return the number of elements actually inserted
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
244 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
245 cx_attr_nonnull
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
246 size_t cx_list_default_insert_sorted(
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
247 struct cx_list_s *list,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
248 const void *sorted_data,
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
249 size_t n
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
250 );
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
251
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
252 /**
875
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
253 * Default unoptimized sort implementation.
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
254 *
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
255 * This function will copy all data to an array, sort the array with standard
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
256 * qsort, and then copy the data back to the list memory.
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
257 *
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
258 * Use this in your own list class if you do not want to implement an optimized
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
259 * version for your list.
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
260 *
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
261 * @param list the list that shall be sorted
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
262 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
263 cx_attr_nonnull
875
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
264 void cx_list_default_sort(struct cx_list_s *list);
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
265
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
266 /**
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
267 * Default unoptimized swap implementation.
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
268 *
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
269 * Use this in your own list class if you do not want to implement an optimized
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
270 * version for your list.
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
271 *
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
272 * @param list the list in which to swap
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
273 * @param i index of one element
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
274 * @param j index of the other element
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
275 * @retval zero success
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
276 * @retval non-zero when indices are out of bounds or memory
882
f8ca6e6c0d48 add missing documentation for cx_list_default_swap() return value
Mike Becker <universe@uap-core.de>
parents: 876
diff changeset
277 * allocation for the temporary buffer fails
875
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
278 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
279 cx_attr_nonnull
875
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
280 int cx_list_default_swap(struct cx_list_s *list, size_t i, size_t j);
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
281
ee84ac776cbc add default impl for some list member functions
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
282 /**
1111
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
283 * Initializes a list struct.
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
284 *
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
285 * Only use this function if you are creating your own list implementation.
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
286 * The purpose of this function is to be called in the initialization code
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
287 * of your list, to set certain members correctly.
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
288 *
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
289 * This is particularly important when you want your list to support
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
290 * #CX_STORE_POINTERS as @p elem_size. This function will wrap the list
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
291 * class accordingly and make sure that you can implement your list as if
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
292 * it was only storing objects and the wrapper will automatically enable
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
293 * the feature of storing pointers.
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
294 *
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
295 * @par Example
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
296 *
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
297 * @code
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
298 * CxList *myCustomListCreate(
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
299 * const CxAllocator *allocator,
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
300 * cx_compare_func comparator,
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
301 * size_t elem_size
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
302 * ) {
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
303 * if (allocator == NULL) {
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
304 * allocator = cxDefaultAllocator;
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
305 * }
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
306 *
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
307 * MyCustomList *list = cxCalloc(allocator, 1, sizeof(MyCustomList));
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
308 * if (list == NULL) return NULL;
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
309 *
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
310 * // initialize
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
311 * cx_list_init((CxList*)list, &my_custom_list_class,
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
312 * allocator, comparator, elem_size);
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
313 *
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
314 * // ... some more custom stuff ...
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
315 *
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
316 * return (CxList *) list;
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
317 * }
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
318 * @endcode
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
319 *
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
320 * @param list the list to initialize
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
321 * @param cl the list class
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
322 * @param allocator the allocator for the elements
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
323 * @param comparator a compare function for the elements
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
324 * @param elem_size the size of one element
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
325 */
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
326 cx_attr_nonnull_arg(1, 2, 3)
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
327 void cx_list_init(
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
328 struct cx_list_s *list,
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
329 struct cx_list_class_s *cl,
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
330 const struct cx_allocator_s *allocator,
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
331 cx_compare_func comparator,
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
332 size_t elem_size
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
333 );
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
334
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1109
diff changeset
335 /**
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
336 * Common type for all list implementations.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
337 */
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
338 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
339
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
340 /**
677
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 669
diff changeset
341 * Returns the number of elements currently stored in the list.
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 669
diff changeset
342 *
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 669
diff changeset
343 * @param list the list
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 669
diff changeset
344 * @return the number of currently stored elements
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 669
diff changeset
345 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
346 cx_attr_nonnull
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
347 static inline size_t cxListSize(const CxList *list) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
348 return list->collection.size;
677
b09aae58bba4 refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents: 669
diff changeset
349 }
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
350
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
351 /**
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
352 * 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
353 *
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
354 * @param list the list
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
355 * @param elem a pointer to the element to add
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
356 * @retval zero success
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
357 * @retval non-zero memory allocation failure
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
358 * @see cxListAddArray()
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
359 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
360 cx_attr_nonnull
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
361 static inline int cxListAdd(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
362 CxList *list,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
363 const void *elem
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
364 ) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
365 return list->cl->insert_element(list, list->collection.size, elem);
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
366 }
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
367
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
368 /**
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
369 * Adds multiple items to the end of the list.
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
370 *
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
371 * This method is more efficient than invoking cxListAdd() multiple times.
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
372 *
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
373 * If there is not enough memory to add all elements, the returned value is
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
374 * less than @p n.
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
375 *
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
376 * If this list is storing pointers instead of objects @p array is expected to
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
377 * be an array of pointers.
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
378 *
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
379 * @param list the list
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
380 * @param array a pointer to the elements to add
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
381 * @param n the number of elements to add
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
382 * @return the number of added elements
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
383 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
384 cx_attr_nonnull
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
385 static inline size_t cxListAddArray(
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
386 CxList *list,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
387 const void *array,
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
388 size_t n
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
389 ) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
390 return list->cl->insert_array(list, list->collection.size, array, n);
629
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
391 }
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
392
6c81ee4f11ad #224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
393 /**
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
394 * Inserts an item at the specified index.
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
395 *
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
396 * If @p index equals the list @c size, this is effectively cxListAdd().
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
397 *
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
398 * @param list the list
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
399 * @param index the index the element shall have
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
400 * @param elem a pointer to the element to add
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
401 * @retval zero success
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
402 * @retval non-zero memory allocation failure or the index is out of bounds
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
403 * @see cxListInsertAfter()
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
404 * @see cxListInsertBefore()
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
405 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
406 cx_attr_nonnull
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
407 static inline int cxListInsert(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
408 CxList *list,
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
409 size_t index,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
410 const void *elem
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
411 ) {
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
412 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
413 }
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
414
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
415 /**
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
416 * Inserts an item into a sorted list.
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
417 *
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
418 * @param list the list
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
419 * @param elem a pointer to the element to add
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
420 * @retval zero success
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
421 * @retval non-zero memory allocation failure
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
422 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
423 cx_attr_nonnull
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
424 static inline int cxListInsertSorted(
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
425 CxList *list,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
426 const void *elem
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
427 ) {
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
428 const void *data = list->collection.store_pointer ? &elem : elem;
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
429 return list->cl->insert_sorted(list, data, 1) == 0;
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
430 }
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
431
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
432 /**
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
433 * Inserts multiple items to the list at the specified index.
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
434 * If @p index equals the list size, this is effectively cxListAddArray().
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
435 *
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
436 * This method is usually more efficient than invoking cxListInsert()
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
437 * multiple times.
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
438 *
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
439 * If there is not enough memory to add all elements, the returned value is
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
440 * less than @p n.
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
441 *
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
442 * If this list is storing pointers instead of objects @p array is expected to
641
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
443 * be an array of pointers.
d402fead3386 add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents: 640
diff changeset
444 *
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
445 * @param list the list
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
446 * @param index the index where to add the elements
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
447 * @param array a pointer to the elements to add
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
448 * @param n the number of elements to add
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
449 * @return the number of added elements
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
450 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
451 cx_attr_nonnull
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
452 static inline size_t cxListInsertArray(
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
453 CxList *list,
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
454 size_t index,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
455 const void *array,
638
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
456 size_t n
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
457 ) {
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
458 return list->cl->insert_array(list, index, array, n);
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
459 }
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
460
eafb45eefc51 add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents: 630
diff changeset
461 /**
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
462 * Inserts a sorted array into a sorted list.
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
463 *
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
464 * This method is usually more efficient than inserting each element separately,
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
465 * because consecutive chunks of sorted data are inserted in one pass.
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
466 *
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
467 * If there is not enough memory to add all elements, the returned value is
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
468 * less than @p n.
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
469 *
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
470 * If this list is storing pointers instead of objects @p array is expected to
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
471 * be an array of pointers.
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
472 *
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
473 * @param list the list
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
474 * @param array a pointer to the elements to add
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
475 * @param n the number of elements to add
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
476 * @return the number of added elements
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
477 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
478 cx_attr_nonnull
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
479 static inline size_t cxListInsertSortedArray(
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
480 CxList *list,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
481 const void *array,
876
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
482 size_t n
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
483 ) {
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
484 return list->cl->insert_sorted(list, array, n);
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
485 }
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
486
f4ce7df9cff0 add stupid default implementation for high level insertion sort
Mike Becker <universe@uap-core.de>
parents: 875
diff changeset
487 /**
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
488 * 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
489 *
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
490 * 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
491 * be considered invalidated.
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
492 *
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
493 * If @p iter is not a list iterator, the behavior is undefined.
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
494 * If @p iter is a past-the-end iterator, the new element gets appended to the list.
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
495 *
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
496 * @param iter an iterator
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
497 * @param elem the element to insert
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
498 * @retval zero success
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
499 * @retval non-zero memory allocation failure
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
500 * @see cxListInsert()
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
501 * @see cxListInsertBefore()
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
502 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
503 cx_attr_nonnull
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
504 static inline int cxListInsertAfter(
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
505 CxIterator *iter,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
506 const void *elem
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
507 ) {
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
508 return ((struct cx_list_s *) iter->src_handle.m)->cl->insert_iter(iter, elem, 0);
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
509 }
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
510
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
511 /**
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
512 * 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
513 *
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
514 * 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
515 * be considered invalidated.
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
516 *
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
517 * If @p iter is not a list iterator, the behavior is undefined.
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
518 * If @p iter is a past-the-end iterator, the new element gets appended to the list.
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
519 *
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
520 * @param iter an iterator
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
521 * @param elem the element to insert
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
522 * @retval zero success
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
523 * @retval non-zero memory allocation failure
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
524 * @see cxListInsert()
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
525 * @see cxListInsertAfter()
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
526 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
527 cx_attr_nonnull
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
528 static inline int cxListInsertBefore(
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
529 CxIterator *iter,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
530 const void *elem
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
531 ) {
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
532 return ((struct cx_list_s *) iter->src_handle.m)->cl->insert_iter(iter, elem, 1);
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
533 }
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
534
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
535 /**
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
536 * 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
537 *
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
538 * 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
539 * removing the element.
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
540 *
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
541 * @param list the list
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
542 * @param index the index of the element
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
543 * @retval zero success
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
544 * @retval non-zero index out of bounds
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
545 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
546 cx_attr_nonnull
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
547 static inline int cxListRemove(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
548 CxList *list,
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
549 size_t index
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
550 ) {
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
551 return list->cl->remove(list, index, 1, NULL) == 0;
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
552 }
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
553
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
554 /**
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
555 * Removes and returns the element at the specified index.
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
556 *
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
557 * No destructor is called and instead the element is copied to the
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
558 * @p targetbuf which MUST be large enough to hold the removed element.
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
559 *
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
560 * @param list the list
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
561 * @param index the index of the element
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
562 * @param targetbuf a buffer where to copy the element
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
563 * @retval zero success
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
564 * @retval non-zero index out of bounds
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
565 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
566 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
567 cx_attr_access_w(3)
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
568 static inline int cxListRemoveAndGet(
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
569 CxList *list,
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
570 size_t index,
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
571 void *targetbuf
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
572 ) {
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
573 return list->cl->remove(list, index, 1, targetbuf) == 0;
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
574 }
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
575
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
576 /**
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
577 * Removes multiple element starting at the specified index.
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
578 *
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
579 * If an element destructor function is specified, it is called for each
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
580 * element. It is guaranteed that the destructor is called before removing
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
581 * the element, however, due to possible optimizations it is neither guaranteed
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
582 * that the destructors are invoked for all elements before starting to remove
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
583 * them, nor that the element is removed immediately after the destructor call
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
584 * before proceeding to the next element.
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
585 *
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
586 * @param list the list
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
587 * @param index the index of the element
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
588 * @param num the number of elements to remove
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
589 * @return the actual number of removed elements
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
590 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
591 cx_attr_nonnull
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
592 static inline size_t cxListRemoveArray(
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
593 CxList *list,
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
594 size_t index,
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
595 size_t num
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
596 ) {
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
597 return list->cl->remove(list, index, num, NULL);
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
598 }
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
599
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
600 /**
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
601 * Removes and returns multiple element starting at the specified index.
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
602 *
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
603 * No destructor is called and instead the elements are copied to the
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
604 * @p targetbuf which MUST be large enough to hold all removed elements.
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
605 *
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
606 * @param list the list
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
607 * @param index the index of the element
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
608 * @param num the number of elements to remove
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
609 * @param targetbuf a buffer where to copy the elements
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
610 * @return the actual number of removed elements
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
611 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
612 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
613 cx_attr_access_w(4)
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
614 static inline size_t cxListRemoveArrayAndGet(
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
615 CxList *list,
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
616 size_t index,
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
617 size_t num,
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
618 void *targetbuf
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
619 ) {
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 892
diff changeset
620 return list->cl->remove(list, index, num, targetbuf);
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
621 }
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
622
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
623 /**
664
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
624 * 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
625 *
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
626 * If element destructor functions are specified, they are called for each
664
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
627 * element before removing them.
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
628 *
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
629 * @param list the list
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
630 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
631 cx_attr_nonnull
664
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
632 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
633 list->cl->clear(list);
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
634 }
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
635
af5bf4603a5d add cxListClear and fix missing destructor invocations - #241 #246
Mike Becker <universe@uap-core.de>
parents: 655
diff changeset
636 /**
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
637 * 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
638 *
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
639 * 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
640 * it is necessary.
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
641 *
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
642 * @param list the list
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
643 * @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
644 * @param j the index of the second element
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
645 * @retval zero success
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
646 * @retval non-zero one of the indices is out of bounds
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
647 * or the swap needed extra memory but allocation failed
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
648 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
649 cx_attr_nonnull
647
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
650 static inline int cxListSwap(
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
651 CxList *list,
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
652 size_t i,
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
653 size_t j
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
654 ) {
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
655 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
656 }
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
657
2e6e9d9f2159 implement swap function for list elements - fixes #218
Mike Becker <universe@uap-core.de>
parents: 641
diff changeset
658 /**
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
659 * 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
660 *
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
661 * @param list the list
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
662 * @param index the index of the element
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
663 * @return a pointer to the element or @c NULL if the index is out of bounds
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
664 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
665 cx_attr_nonnull
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
666 static inline void *cxListAt(
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
667 const CxList *list,
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
668 size_t index
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
669 ) {
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
670 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
671 }
439
9a5adedd6de6 add high-level function cxListAt()
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
672
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
673 /**
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
674 * 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
675 *
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
676 * The returned iterator is position-aware.
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
677 *
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
678 * 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
679 *
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
680 * @param list the list
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
681 * @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
682 * @return a new iterator
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
683 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
684 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
685 cx_attr_nodiscard
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
686 static inline CxIterator cxListIteratorAt(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
687 const CxList *list,
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
688 size_t index
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
689 ) {
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
690 return list->cl->iterator(list, index, false);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
691 }
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
692
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
693 /**
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
694 * 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
695 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
696 * The returned iterator is position-aware.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
697 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
698 * 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
699 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
700 * @param list the list
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
701 * @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
702 * @return a new iterator
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
703 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
704 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
705 cx_attr_nodiscard
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
706 static inline CxIterator cxListBackwardsIteratorAt(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
707 const CxList *list,
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
708 size_t index
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
709 ) {
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
710 return list->cl->iterator(list, index, true);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
711 }
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
712
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
713 /**
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
714 * 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
715 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
716 * The returned iterator is position-aware.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
717 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
718 * 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
719 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
720 * @param list the list
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
721 * @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
722 * @return a new iterator
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
723 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
724 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
725 cx_attr_nodiscard
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
726 CxIterator cxListMutIteratorAt(
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
727 CxList *list,
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
728 size_t index
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
729 );
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
730
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
731 /**
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
732 * 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
733 * specified index.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
734 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
735 * The returned iterator is position-aware.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
736 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
737 * 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
738 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
739 * @param list the list
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
740 * @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
741 * @return a new iterator
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
742 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
743 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
744 cx_attr_nodiscard
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
745 CxIterator cxListMutBackwardsIteratorAt(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
746 CxList *list,
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
747 size_t index
640
55cc3b373c5e simplify list class - fixes #236
Mike Becker <universe@uap-core.de>
parents: 638
diff changeset
748 );
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
749
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
750 /**
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
751 * 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
752 *
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
753 * The returned iterator is position-aware.
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
754 *
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
755 * 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
756 *
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
757 * @param list the list
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
758 * @return a new iterator
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
759 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
760 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
761 cx_attr_nodiscard
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
762 static inline CxIterator cxListIterator(const CxList *list) {
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
763 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
764 }
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
765
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 490
diff changeset
766 /**
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
767 * 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
768 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
769 * The returned iterator is position-aware.
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
770 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
771 * 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
772 *
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
773 * @param list the list
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
774 * @return a new iterator
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
775 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
776 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
777 cx_attr_nodiscard
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
778 static inline CxIterator cxListMutIterator(CxList *list) {
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
779 return cxListMutIteratorAt(list, 0);
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
780 }
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
781
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
782
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
783 /**
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
784 * 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
785 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
786 * The returned iterator is position-aware.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
787 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
788 * 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
789 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
790 * @param list the list
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
791 * @return a new iterator
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
792 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
793 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
794 cx_attr_nodiscard
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
795 static inline CxIterator cxListBackwardsIterator(const CxList *list) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
796 return list->cl->iterator(list, list->collection.size - 1, true);
655
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
797 }
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
798
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
799 /**
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
800 * 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
801 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
802 * The returned iterator is position-aware.
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
803 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
804 * 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
805 *
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
806 * @param list the list
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
807 * @return a new iterator
7340c4255f1f implement backwards iterator - fixes #238
Mike Becker <universe@uap-core.de>
parents: 647
diff changeset
808 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
809 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
810 cx_attr_nodiscard
853
d4baf4dd55c3 simplify iterator structures
Mike Becker <universe@uap-core.de>
parents: 764
diff changeset
811 static inline CxIterator cxListMutBackwardsIterator(CxList *list) {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
812 return cxListMutBackwardsIteratorAt(list, list->collection.size - 1);
630
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
813 }
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
814
ac5e7f789048 separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents: 629
diff changeset
815 /**
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
816 * Returns the index of the first element that equals @p elem.
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
817 *
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
818 * 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
819 *
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
820 * @param list the list
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
821 * @param elem the element to find
699
35b2b99ee523 make list find return a negative value when elem not found
Mike Becker <universe@uap-core.de>
parents: 698
diff changeset
822 * @return the index of the element or a negative
35b2b99ee523 make list find return a negative value when elem not found
Mike Becker <universe@uap-core.de>
parents: 698
diff changeset
823 * value when the element is not found
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
824 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
825 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
826 cx_attr_nodiscard
699
35b2b99ee523 make list find return a negative value when elem not found
Mike Becker <universe@uap-core.de>
parents: 698
diff changeset
827 static inline ssize_t cxListFind(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
828 const CxList *list,
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
829 const void *elem
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
830 ) {
764
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
831 return list->cl->find_remove((CxList*)list, elem, false);
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
832 }
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
833
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
834 /**
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
835 * Removes and returns the index of the first element that equals @p elem.
764
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
836 *
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
837 * Determining equality is performed by the list's comparator function.
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
838 *
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
839 * @param list the list
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
840 * @param elem the element to find and remove
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
841 * @return the index of the now removed element or a negative
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
842 * value when the element is not found or could not be removed
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
843 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
844 cx_attr_nonnull
764
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
845 static inline ssize_t cxListFindRemove(
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
846 CxList *list,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
847 const void *elem
764
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
848 ) {
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
849 return list->cl->find_remove(list, elem, true);
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
850 }
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
851
464
7fafc95968fc add documentation for list.h
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
852 /**
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
853 * Sorts the list.
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
854 *
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
855 * @remark The underlying sort algorithm is implementation defined.
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
856 *
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 464
diff changeset
857 * @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
858 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
859 cx_attr_nonnull
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
860 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
861 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
862 }
404
86ebc3745e62 adds cxListLast
Mike Becker <universe@uap-core.de>
parents: 401
diff changeset
863
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
864 /**
490
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
865 * Reverses the order of the items.
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
866 *
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
867 * @param list the list
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
868 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
869 cx_attr_nonnull
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
870 static inline void cxListReverse(CxList *list) {
490
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
871 list->cl->reverse(list);
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
872 }
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
873
e66551b47466 add cxListReverse()
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
874 /**
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
875 * 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
876 *
618
1f5a8f6f3015 #219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
877 * First, the list sizes are compared.
1f5a8f6f3015 #219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
878 * 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
879 *
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
880 * @param list the list
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
881 * @param other the list to compare to
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
882 * @retval zero both lists are equal element wise
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
883 * @retval negative the first list is smaller
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
884 * or the first non-equal element in the first list is smaller
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
885 * @retval positive the first list is larger
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
886 * or the first non-equal element in the first list is larger
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
887 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
888 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
889 cx_attr_nodiscard
618
1f5a8f6f3015 #219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
890 int cxListCompare(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
891 const CxList *list,
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 882
diff changeset
892 const CxList *other
618
1f5a8f6f3015 #219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
893 );
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
894
503
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
895 /**
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
896 * 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
897 *
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
898 * Also calls the content destructor functions for each element, if specified.
503
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
899 *
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
900 * @param list the list which shall be freed
503
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
901 */
1109
89ec23988b88 free functions should not be inline in release mode - relates to #541
Mike Becker <universe@uap-core.de>
parents: 1101
diff changeset
902 void cxListFree(CxList *list);
503
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
903
704
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 699
diff changeset
904 /**
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 699
diff changeset
905 * A shared instance of an empty list.
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 699
diff changeset
906 *
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
907 * Writing to that list is not allowed.
1101
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
908 *
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
909 * You can use this is a placeholder for initializing CxList pointers
2872f287fadc refine docs for list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
910 * for which you do not want to reserve memory right from the beginning.
704
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 699
diff changeset
911 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 919
diff changeset
912 extern CxList *const cxEmptyList;
704
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 699
diff changeset
913
35f06c5eeb0e add empty list implementation - fixes #258
Mike Becker <universe@uap-core.de>
parents: 699
diff changeset
914
415
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
915 #ifdef __cplusplus
628
1e2be40f0cb5 use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents: 621
diff changeset
916 } // extern "C"
415
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
917 #endif
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
918
628
1e2be40f0cb5 use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents: 621
diff changeset
919 #endif // UCX_LIST_H

mercurial