src/cx/array_list.h

Sun, 28 Dec 2025 17:31:20 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 28 Dec 2025 17:31:20 +0100
changeset 1675
36c0fb2b60b2
parent 1626
a2565f9fc6de
permissions
-rw-r--r--

overhaul all attributes

606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
314e9288af2f add array list tests
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
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 /**
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
29 * @file array_list.h
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
30 * @brief Array list implementation.
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
31 * @author Mike Becker
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
32 * @author Olaf Wintermann
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
33 * @copyright 2-Clause BSD License
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 */
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 #ifndef UCX_ARRAY_LIST_H
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 #define UCX_ARRAY_LIST_H
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39
617
cec11387c1be fix include in array_list.h
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 612
diff changeset
40 #include "list.h"
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 /**
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
43 * The maximum item size in an array list that fits into
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
44 * a stack buffer when swapped.
804
5136f2fc32ec add CX_DISABLE_ARRAY_LIST_SWAP_SBO flag
Mike Becker <universe@uap-core.de>
parents: 795
diff changeset
45 */
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1425
diff changeset
46 CX_EXPORT extern const unsigned cx_array_swap_sbo_size;
804
5136f2fc32ec add CX_DISABLE_ARRAY_LIST_SWAP_SBO flag
Mike Becker <universe@uap-core.de>
parents: 795
diff changeset
47
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
48 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
49 * Declares a typed array with size and capacity.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
50 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
51 * @param type the type of the elements
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
52 * @param name the name of the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
53 */
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
54 #define CX_ARRAY(type, name) \
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
55 struct { \
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
56 type *data; \
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
57 size_t size; \
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
58 size_t capacity; \
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
59 } name
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
60
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
61 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
62 * Internal structure for arrays.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
63 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
64 * A generalization of array structures declared with CX_ARRAY().
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
65 */
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
66 typedef struct cx_array_s {
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
67 /** The array data. */
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
68 void *data;
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
69 /** The number of elements. */
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
70 size_t size;
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
71 /** The maximum number of elements. */
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
72 size_t capacity;
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
73 } CxArray;
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
74
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
75 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
76 * Initializes an array by allocating memory.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
77 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
78 * Internal function - do not use manually.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
79 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
80 * @param allocator the allocator for the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
81 * @param array a pointer to the array structure
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
82 * @param elem_size size of one element
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
83 * @param capacity the initial maximum number of elements
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
84 * @retval zero allocation was successful
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
85 * @retval non-zero allocation failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
86 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
87 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
88 int cx_array_init_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity);
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
89
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
90 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
91 * Initializes an array by allocating memory.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
92 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
93 * The size is set to zero.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
94 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
95 * @attention If the array was already initialized, this will leak memory.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
96 * Use cx_array_reserve() to change the capacity of an initialized array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
97 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
98 * @param allocator (@c CxAllocator*) the allocator for the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
99 * @param array the name of the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
100 * @param capacity (@c size_t) the initial maximum number of elements
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
101 * @retval zero allocation was successful
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
102 * @retval non-zero allocation failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
103 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
104 #define cx_array_init_a(allocator, array, capacity) cx_array_init_(allocator, (CxArray*)&(array), sizeof((array).data[0]), capacity)
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
105
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
106 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
107 * Initializes an array by allocating memory.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
108 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
109 * The size is set to zero.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
110 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
111 * @attention If the array was already initialized, this will leak memory.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
112 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
113 * @param array the name of the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
114 * @param capacity (@c size_t) the initial maximum number of elements
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
115 * @retval zero allocation was successful
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
116 * @retval non-zero allocation failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
117 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
118 #define cx_array_init(array, capacity) cx_array_init_a(cxDefaultAllocator, array, capacity)
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
119
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
120 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
121 * Initializes an array with fixed size memory.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
122 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
123 * Internal function - do not use manually.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
124 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
125 * @param array a pointer to the array structure
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
126 * @param data the fixed size array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
127 * @param capacity the capacity of the fixed size array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
128 * @param size the number of initialized elements in the fixed size array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
129 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
130 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
131 void cx_array_init_fixed_(CxArray *array, const void *data, size_t capacity, size_t size);
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
132
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
133 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
134 * Initializes an array with fixed size memory.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
135 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
136 * This is useful, for example, when you want to work with memory on the stack
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
137 * and only want to move to the heap when the stack memory is not enough.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
138 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
139 * With the @p num_initialized argument you can specify how many elements in the
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
140 * fixed size array are already correctly initialized, which determines the
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
141 * initial size of the array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
142 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
143 * The capacity is determined automatically by the compiler.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
144 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
145 * @attention When you add elements to an array that was initialized with fixed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
146 * size memory, you MUST check the capacity before adding the element and invoke
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
147 * cx_array_copy_to_new() when you intend to exceed the capacity.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
148 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
149 * @attention When you pass a pointer to an array that does not have a fixed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
150 * size, the behavior is unspecified.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
151 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
152 * @param array the name of the array to initialize
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
153 * @param fixed_size_array (@c void*) the fixed size array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
154 * @param num_initialized (@c size_t) the number of already initialized elements in the fixed size array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
155 * @see cx_array_copy_to_new()
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
156 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
157 #define cx_array_init_fixed(array, fixed_size_array, num_initialized) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
158 cx_array_init_fixed_((CxArray*)&(array), fixed_size_array, cx_nmemb(fixed_size_array), num_initialized)
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
159
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
160 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
161 * Changes the capacity of an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
162 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
163 * Internal function - do not use.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
164 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
165 * @param allocator the allocator
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
166 * @param array a pointer to the array structure
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
167 * @param elem_size the size of one element
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
168 * @param capacity the new capacity
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
169 * @retval zero allocation was successful
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
170 * @retval non-zero allocation failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
171 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
172 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
173 int cx_array_reserve_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity);
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
174
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
175 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
176 * Changes the capacity of an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
177 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
178 * If required, the size is reduced to fit into the new capacity.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
179 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
180 * @param allocator (@c CxAllocator*) the allocator for the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
181 * @param array the name of the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
182 * @param capacity (@c size_t) the new maximum number of elements
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
183 * @retval zero allocation was successful
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
184 * @retval non-zero allocation failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
185 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
186 #define cx_array_reserve_a(allocator, array, capacity) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
187 cx_array_reserve_(allocator, (CxArray*)&(array), sizeof((array).data[0]), capacity)
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
188
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
189 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
190 * Changes the capacity of an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
191 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
192 * If required, the size is reduced to fit into the new capacity.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
193 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
194 * @param array the name of the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
195 * @param capacity (@c size_t) the new maximum number of elements
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
196 * @retval zero allocation was successful
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
197 * @retval non-zero allocation failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
198 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
199 #define cx_array_reserve(array, capacity) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
200 cx_array_reserve_a(cxDefaultAllocator, array, capacity)
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
201
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
202 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
203 * Copies the array to a new memory region.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
204 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
205 * Internal function - do not use.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
206 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
207 * @param allocator the allocator for new new memory
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
208 * @param array a pointer to the array structure
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
209 * @param elem_size the size of one element
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
210 * @param capacity the new capacity
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
211 * @retval zero allocation was successful
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
212 * @retval non-zero allocation failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
213 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
214 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
215 int cx_array_copy_to_new_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity);
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
216
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
217 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
218 * Copies the array to a new memory region.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
219 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
220 * This is useful when you have initialized the array with a fixed size memory
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
221 * using cx_array_init_fixed(), and now you want to increase the capacity.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
222 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
223 * @attention When the original memory does not belong to stack memory, and
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
224 * you do not have another reference to this memory, it will leak.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
225 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
226 * @param allocator (@c CxAllocator*) the allocator for the new memory
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
227 * @param array the name of the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
228 * @param capacity (@c size_t) the new maximum number of elements
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
229 * @retval zero allocation was successful
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
230 * @retval non-zero allocation failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
231 * @see cx_array_init_fixed()
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
232 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
233 #define cx_array_copy_to_new_a(allocator, array, capacity) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
234 cx_array_copy_to_new_(allocator, (CxArray*)&(array), sizeof((array).data[0]), capacity)
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
235
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
236 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
237 * Copies the array to a new memory region.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
238 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
239 * This is useful when you have initialized the array with a fixed size memory
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
240 * using cx_array_init_fixed(), and now you want to increase the capacity.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
241 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
242 * @attention When the original memory does not belong to stack memory, and
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
243 * you do not have another reference to this memory, it will leak.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
244 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
245 * @param array the name of the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
246 * @param capacity (@c size_t) the new maximum number of elements
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
247 * @retval zero allocation was successful
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
248 * @retval non-zero allocation failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
249 * @see cx_array_init_fixed()
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
250 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
251 #define cx_array_copy_to_new(array, capacity) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
252 cx_array_copy_to_new_a(cxDefaultAllocator, array, capacity)
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
253
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
254 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
255 * Inserts data into an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
256 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
257 * Internal function - do not use.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
258 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
259 * @param allocator the allocator to use for a possible reallocation
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
260 * @param array a pointer to the array structure
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
261 * @param elem_size the size of one element
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
262 * @param index the index where to insert the @p other data
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
263 * @param other a pointer to an array of data that shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
264 * @param n the number of elements that shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
265 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
266 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
267 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
268 CX_EXTERN CX_NONNULL_ARG(1, 2)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
269 int cx_array_insert_(const CxAllocator *allocator, CxArray *array,
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
270 size_t elem_size, size_t index, const void *other, size_t n);
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
271
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
272 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
273 * Appends an element to an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
274 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
275 * When the capacity is not enough to hold the new element, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
276 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
277 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
278 * @param array the name of the array where the element shall be added
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
279 * @param element the element that shall be added
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
280 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
281 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
282 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
283 #define cx_array_add_a(allocator, array, element) \
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
284 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (array).size, (void*)&(element), 1)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
285
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
286 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
287 * Appends an element to an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
288 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
289 * When the capacity is not enough to hold the new element, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
290 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
291 * @param array the name of the array where the element shall be added
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
292 * @param element (@c void*) a pointer to the element that shall be added
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
293 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
294 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
295 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
296 #define cx_array_add(array, element) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
297 cx_array_add_a(cxDefaultAllocator, array, element)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
298
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
299 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
300 * Inserts an element into an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
301 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
302 * When the capacity is not enough to hold the new element, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
303 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
304 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
305 * @param array the name of the array where the element shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
306 * @param index (@c size_t) the index where to insert the @p element
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
307 * @param element the element that shall be inserted
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
308 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
309 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
310 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
311 #define cx_array_insert_a(allocator, array, index, element) \
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
312 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), index, (void*)&(element), 1)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
313
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
314 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
315 * Inserts an element into an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
316 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
317 * When the capacity is not enough to hold the new element, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
318 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
319 * @param array the name of the array where the element shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
320 * @param index (@c size_t) the index where to insert the @p element
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
321 * @param element (@c void*) a pointer to the element that shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
322 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
323 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
324 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
325 #define cx_array_insert(array, index, element) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
326 cx_array_insert_a(cxDefaultAllocator, array, index, element)
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
327
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
328 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
329 * Inserts data into an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
330 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
331 * When the capacity is not enough to hold the new elements, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
332 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
333 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
334 * @param array the name of the array where the elements shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
335 * @param index (@c size_t) the index where to insert the @p other data
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
336 * @param other (@c void*) a pointer to an array of data that shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
337 * @param n (@c size_t) the number of elements that shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
338 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
339 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
340 */
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
341 #define cx_array_insert_array_a(allocator, array, index, other, n) \
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
342 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), index, other, n)
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
343
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
344 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
345 * Inserts data into an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
346 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
347 * When the capacity is not enough to hold the new elements, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
348 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
349 * @param array the name of the array where the elements shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
350 * @param index (@c size_t) the index where to insert the @p other data
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
351 * @param other (@c void*) a pointer to an array of data that shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
352 * @param n (@c size_t) the number of elements that shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
353 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
354 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
355 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
356 #define cx_array_insert_array(array, index, other, n) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
357 cx_array_insert_array_a(cxDefaultAllocator, array, index, other, n)
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
358
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
359 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
360 * Appends data to an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
361 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
362 * When the capacity is not enough to hold the new elements, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
363 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
364 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
365 * @param array the name of the array where the elements shall be added
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
366 * @param other (@c void*) a pointer to an array of data that shall be added
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
367 * @param n (@c size_t) the number of elements that shall be added
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
368 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
369 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
370 */
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
371 #define cx_array_add_array_a(allocator, array, other, n) \
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
372 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (array).size, other, n)
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
373
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
374 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
375 * Appends data to an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
376 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
377 * When the capacity is not enough to hold the new elements, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
378 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
379 * @param array the name of the array where the elements shall be added
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
380 * @param other (@c void*) a pointer to an array of data that shall be added
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
381 * @param n (@c size_t) the number of elements that shall be added
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
382 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
383 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
384 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
385 #define cx_array_add_array(array, other, n) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
386 cx_array_add_array_a(cxDefaultAllocator, array, other, n)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
387
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
388 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
389 * Inserts sorted data into a sorted array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
390 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
391 * Internal function - do not use.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
392 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
393 * @param allocator the allocator to use for a possible reallocation
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
394 * @param array a pointer to the array structure
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
395 * @param elem_size the size of one element
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
396 * @param sorted_data a pointer to an array of data that shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
397 * @param n the number of elements that shall be inserted
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
398 * @param cmp_func the compare function
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
399 * @param allow_duplicates @c false if duplicates shall be skipped during insertion
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
400 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
401 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
402 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
403 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
404 int cx_array_insert_sorted_(const CxAllocator *allocator, CxArray *array,
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
405 size_t elem_size, const void *sorted_data, size_t n,
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
406 cx_compare_func cmp_func, bool allow_duplicates);
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
407
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
408 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
409 * Inserts an element into a sorted array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
410 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
411 * When the capacity is not enough to hold the new element, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
412 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
413 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
414 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
415 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
416 * @param array the name of the array where the elements shall be inserted
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
417 * @param element the element that shall be inserted
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
418 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
419 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
420 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
421 */
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
422 #define cx_array_insert_sorted_a(allocator, array, element, cmp_func) \
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
423 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, true)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
424
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
425 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
426 * Inserts an element into a sorted array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
427 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
428 * When the capacity is not enough to hold the new element, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
429 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
430 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
431 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
432 * @param array the name of the array where the elements shall be inserted
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
433 * @param element the element that shall be inserted
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
434 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
435 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
436 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
437 */
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
438 #define cx_array_insert_sorted(array, element, cmp_func) \
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
439 cx_array_insert_sorted_a(cxDefaultAllocator, array, element, cmp_func)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
440
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
441 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
442 * Inserts sorted data into a sorted array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
443 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
444 * When the capacity is not enough to hold the new elements, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
445 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
446 * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
447 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
448 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
449 * @param array the name of the array where the elements shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
450 * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
451 * @param n (@c size_t) the number of elements that shall be inserted
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
452 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
453 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
454 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
455 */
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
456 #define cx_array_insert_sorted_array_a(allocator, array, sorted_data, n, cmp_func) \
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
457 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, true)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
458
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
459 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
460 * Inserts sorted data into a sorted array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
461 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
462 * When the capacity is not enough to hold the new elements, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
463 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
464 * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
465 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
466 * @param array the name of the array where the elements shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
467 * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
468 * @param n (@c size_t) the number of elements that shall be inserted
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
469 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
470 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
471 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
472 */
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
473 #define cx_array_insert_sorted_array(array, sorted_data, n, cmp_func) \
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
474 cx_array_insert_sorted_array_a(cxDefaultAllocator, array, sorted_data, n, cmp_func)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
475
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
476 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
477 * Inserts an element into a sorted array if it is not already contained.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
478 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
479 * When the capacity is not enough to hold the new element, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
480 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
481 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
482 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
483 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
484 * @param array the name of the array where the elements shall be inserted
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
485 * @param element the element that shall be inserted
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
486 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
487 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
488 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
489 */
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
490 #define cx_array_insert_unique_a(allocator, array, element, cmp_func) \
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
491 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, false)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
492
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
493 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
494 * Inserts an element into a sorted array if it is not already contained.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
495 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
496 * When the capacity is not enough to hold the new element, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
497 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
498 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
499 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
500 * @param array the name of the array where the elements shall be inserted
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
501 * @param element the element that shall be inserted
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
502 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
503 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
504 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
505 */
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
506 #define cx_array_insert_unique(array, element, cmp_func) \
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
507 cx_array_insert_unique_a(cxDefaultAllocator, array, element, cmp_func)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
508
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
509 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
510 * Inserts sorted data into a sorted array, skipping duplicates.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
511 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
512 * When the capacity is not enough to hold the new elements, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
513 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
514 * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
515 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
516 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
517 * @param array the name of the array where the elements shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
518 * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
519 * @param n (@c size_t) the number of elements that shall be inserted
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
520 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
521 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
522 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
523 */
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
524 #define cx_array_insert_unique_array_a(allocator, array, sorted_data, n, cmp_func) \
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
525 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, false)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
526
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
527 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
528 * Inserts sorted data into a sorted array, skipping duplicates.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
529 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
530 * When the capacity is not enough to hold the new elements, a re-allocation is attempted.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
531 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
532 * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
533 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
534 * @param array the name of the array where the elements shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
535 * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
536 * @param n (@c size_t) the number of elements that shall be inserted
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
537 * @param cmp_func (@c cx_compare_func) the compare function that establishes the order
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
538 * @retval zero success
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
539 * @retval non-zero a re-allocation was necessary but failed
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
540 */
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
541 #define cx_array_insert_unique_array(array, sorted_data, n, cmp_func) \
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
542 cx_array_insert_unique_array_a(cxDefaultAllocator, array, sorted_data, n, cmp_func)
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
543
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
544 /**
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
545 * Inserts sorted data into a sorted array.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
546 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
547 * Internal function - do not use.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
548 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
549 * @param allocator the allocator to use for a possible reallocation
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
550 * @param array a pointer to the array structure
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
551 * @param elem_size the size of one element
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
552 * @param sorted_data a pointer to an array of data that shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
553 * @param n the number of elements that shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
554 * @param cmp_func the compare function
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
555 * @param context additional context for the compare function
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
556 * @param allow_duplicates @c false if duplicates shall be skipped during insertion
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
557 * @retval zero success
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
558 * @retval non-zero a re-allocation was necessary but failed
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
559 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
560 CX_EXTERN CX_NONNULL_ARG(1, 2, 4, 6)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
561 int cx_array_insert_sorted_c_(const CxAllocator *allocator, CxArray *array,
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
562 size_t elem_size, const void *sorted_data, size_t n,
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
563 cx_compare_func2 cmp_func, void *context, bool allow_duplicates);
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
564
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
565 /**
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
566 * Inserts an element into a sorted array.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
567 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
568 * When the capacity is not enough to hold the new element, a re-allocation is attempted.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
569 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
570 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
571 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
572 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
573 * @param array the name of the array where the elements shall be inserted
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
574 * @param element the element that shall be inserted
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
575 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
576 * @param context (@c void*) additional context for the compare function
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
577 * @retval zero success
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
578 * @retval non-zero a re-allocation was necessary but failed
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
579 */
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
580 #define cx_array_insert_sorted_ca(allocator, array, element, cmp_func) \
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
581 cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, context, true)
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
582
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
583 /**
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
584 * Inserts an element into a sorted array.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
585 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
586 * When the capacity is not enough to hold the new element, a re-allocation is attempted.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
587 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
588 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
589 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
590 * @param array the name of the array where the elements shall be inserted
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
591 * @param element the element that shall be inserted
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
592 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
593 * @param context (@c void*) additional context for the compare function
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
594 * @retval zero success
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
595 * @retval non-zero a re-allocation was necessary but failed
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
596 */
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
597 #define cx_array_insert_sorted_c(array, element, cmp_func, context) \
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
598 cx_array_insert_sorted_ca(cxDefaultAllocator, array, element, cmp_func, context)
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
599
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
600 /**
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
601 * Inserts sorted data into a sorted array.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
602 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
603 * When the capacity is not enough to hold the new elements, a re-allocation is attempted.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
604 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
605 * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
606 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
607 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
608 * @param array the name of the array where the elements shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
609 * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
610 * @param n (@c size_t) the number of elements that shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
611 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
612 * @param context (@c void*) additional context for the compare function
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
613 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
614 * @retval non-zero a re-allocation was necessary but failed
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
615 */
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
616 #define cx_array_insert_sorted_array_ca(allocator, array, sorted_data, n, cmp_func, context) \
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
617 cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, context, true)
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
618
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
619 /**
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
620 * Inserts sorted data into a sorted array.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
621 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
622 * When the capacity is not enough to hold the new elements, a re-allocation is attempted.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
623 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
624 * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
625 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
626 * @param array the name of the array where the elements shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
627 * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
628 * @param n (@c size_t) the number of elements that shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
629 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
630 * @param context (@c void*) additional context for the compare function
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
631 * @retval zero success
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
632 * @retval non-zero a re-allocation was necessary but failed
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
633 */
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
634 #define cx_array_insert_sorted_array_c(array, sorted_data, n, cmp_func, context) \
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
635 cx_array_insert_sorted_array_ca(cxDefaultAllocator, array, sorted_data, n, cmp_func, context)
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
636
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
637 /**
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
638 * Inserts an element into a sorted array if it is not already contained.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
639 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
640 * When the capacity is not enough to hold the new element, a re-allocation is attempted.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
641 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
642 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
643 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
644 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
645 * @param array the name of the array where the elements shall be inserted
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
646 * @param element the element that shall be inserted
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
647 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
648 * @param context (@c void*) additional context for the compare function
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
649 * @retval zero success
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
650 * @retval non-zero a re-allocation was necessary but failed
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
651 */
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
652 #define cx_array_insert_unique_ca(allocator, array, element, cmp_func, context) \
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
653 cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, context, false)
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
654
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
655 /**
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
656 * Inserts an element into a sorted array if it is not already contained.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
657 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
658 * When the capacity is not enough to hold the new element, a re-allocation is attempted.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
659 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
660 * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
661 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
662 * @param array the name of the array where the elements shall be inserted
1625
89a2d53308e4 changes macros for adding/inserting a single element into an array to automatically take the address - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1623
diff changeset
663 * @param element the element that shall be inserted
1622
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
664 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
665 * @param context (@c void*) additional context for the compare function
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
666 * @retval zero success
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
667 * @retval non-zero a re-allocation was necessary but failed
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
668 */
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
669 #define cx_array_insert_unique_c(array, element, cmp_func, context) \
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
670 cx_array_insert_unique_ca(cxDefaultAllocator, array, element, cmp_func, context)
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
671
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
672 /**
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
673 * Inserts sorted data into a sorted array, skipping duplicates.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
674 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
675 * When the capacity is not enough to hold the new elements, a re-allocation is attempted.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
676 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
677 * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
678 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
679 * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
680 * @param array the name of the array where the elements shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
681 * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
682 * @param n (@c size_t) the number of elements that shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
683 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
684 * @param context (@c void*) additional context for the compare function
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
685 * @retval zero success
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
686 * @retval non-zero a re-allocation was necessary but failed
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
687 */
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
688 #define cx_array_insert_unique_array_ca(allocator, array, sorted_data, n, cmp_func, context) \
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
689 cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, context, false)
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
690
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
691 /**
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
692 * Inserts sorted data into a sorted array, skipping duplicates.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
693 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
694 * When the capacity is not enough to hold the new elements, a re-allocation is attempted.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
695 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
696 * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined.
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
697 *
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
698 * @param array the name of the array where the elements shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
699 * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
700 * @param n (@c size_t) the number of elements that shall be inserted
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
701 * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
702 * @param context (@c void*) additional context for the compare function
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
703 * @retval zero success
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
704 * @retval non-zero a re-allocation was necessary but failed
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
705 */
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
706 #define cx_array_insert_unique_array_c(array, sorted_data, n, cmp_func, context) \
27e7a4bf1a39 add missing compare_func2 variants of the array functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1621
diff changeset
707 cx_array_insert_unique_array_ca(cxDefaultAllocator, array, sorted_data, n, cmp_func, context)
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
708
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
709 /**
1620
bf5d647f939d use qsort_r() when it is available - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
710 * An alternative to qsort_r() when that is not available on your platform.
bf5d647f939d use qsort_r() when it is available - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
711 *
bf5d647f939d use qsort_r() when it is available - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
712 * If it is available, qsort_r() is used directly.
bf5d647f939d use qsort_r() when it is available - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
713 *
bf5d647f939d use qsort_r() when it is available - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
714 * @param array the array that shall be sorted
bf5d647f939d use qsort_r() when it is available - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
715 * @param nmemb the number of elements in the array
bf5d647f939d use qsort_r() when it is available - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
716 * @param size the size of one element
bf5d647f939d use qsort_r() when it is available - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
717 * @param fn the compare function
bf5d647f939d use qsort_r() when it is available - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
718 * @param context the context for the compare function
bf5d647f939d use qsort_r() when it is available - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
719 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
720 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
721 void cx_array_qsort_c(void *array, size_t nmemb, size_t size,
1620
bf5d647f939d use qsort_r() when it is available - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
722 cx_compare_func2 fn, void *context);
bf5d647f939d use qsort_r() when it is available - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
723
bf5d647f939d use qsort_r() when it is available - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
724 /**
1621
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
725 * Sorts an array.
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
726 *
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
727 * Internal function - do not use.
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
728 *
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
729 * @param array a pointer to the array structure
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
730 * @param elem_size the size of one element
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
731 * @param fn the compare function
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
732 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
733 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
734 void cx_array_sort_(CxArray *array, size_t elem_size,
1621
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
735 cx_compare_func fn);
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
736
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
737 /**
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
738 * Sorts an array.
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
739 *
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
740 * Internal function - do not use.
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
741 *
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
742 * @param array a pointer to the array structure
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
743 * @param elem_size the size of one element
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
744 * @param fn the compare function
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
745 * @param context the context for the compare function
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
746 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
747 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
748 void cx_array_sort_c_(CxArray *array, size_t elem_size,
1621
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
749 cx_compare_func2 fn, void *context);
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
750
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
751 /**
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
752 * Sorts an array.
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
753 *
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
754 * @param array the name of the array
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
755 * @param fn (@c cx_compare_func) the compare function
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
756 * @param context (@c void*) the context for the compare function
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
757 */
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
758 #define cx_array_sort(array, fn) \
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
759 cx_array_sort_((CxArray*)&(array), sizeof((array).data[0]), fn)
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
760
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
761 /**
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
762 * Sorts an array.
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
763 *
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
764 * @param array the name of the array
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
765 * @param fn (@c cx_compare_func2) the compare function
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
766 * @param context (@c void*) the context for the compare function
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
767 */
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
768 #define cx_array_sort_c(array, fn, context) \
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
769 cx_array_sort_c_((CxArray*)&(array), sizeof((array).data[0]), fn, context)
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
770
c52a4c67e29e add convenience array_sort functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1620
diff changeset
771 /**
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
772 * Creates an iterator over the elements of an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
773 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
774 * Internal function - do not use.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
775 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
776 * @param array a pointer to the array structure
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
777 * @param elem_size the size of one element
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
778 * @return an iterator over the elements
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
779 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
780 CX_EXTERN CX_NODISCARD CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
781 CxIterator cx_array_iterator_(CxArray *array, size_t elem_size);
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
782
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
783 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
784 * Creates an iterator over the elements of an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
785 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
786 * The iterator will yield pointers to the elements.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
787 *
1626
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
788 * This iterator cannot be used to remove elements
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
789 * because it does not get a modifiable reference to the array's size.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
790 *
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
791 * @param array the name of the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
792 * @return an iterator over the elements
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
793 * @see cx_array_iterator_ptr()
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
794 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
795 #define cx_array_iterator(array) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
796 cx_array_iterator_((CxArray*)&(array), sizeof((array).data[0]))
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
797
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
798 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
799 * Creates an iterator over the elements of an array containing pointers.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
800 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
801 * Internal function - do not use.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
802 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
803 * @param array the name of the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
804 * @return an iterator over the elements
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
805 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
806 CX_EXTERN CX_NODISCARD CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
807 CxIterator cx_array_iterator_ptr_(CxArray *array);
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
808
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
809 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
810 * Creates an iterator over the elements of an array containing pointers.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
811 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
812 * The iterator will yield the elements themselves, which are supposed to
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
813 * be pointers.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
814 *
1626
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
815 * This iterator cannot be used to remove elements
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
816 * because it does not get a modifiable reference to the array's size.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
817 *
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
818 * @param array the name of the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
819 * @return an iterator over the elements
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
820 * @see cx_array_iterator()
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
821 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
822 #define cx_array_iterator_ptr(array) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
823 cx_array_iterator_ptr_((CxArray*)&(array))
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
824
1626
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
825
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
826 /**
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
827 * Removes elements from the array.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
828 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
829 * Internal function - do not use.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
830 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
831 * @param array a pointer to the array structure
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
832 * @param elem_size the size of one element
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
833 * @param index the index of the first element to remove
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
834 * @param n the number of elements to remove
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
835 * @param fast indicates whether tail elements should be copied into the gap
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
836 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
837 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
838 void cx_array_remove_(CxArray *array, size_t elem_size, size_t index, size_t n, bool fast);
1626
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
839
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
840 /**
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
841 * Removes one element from the array.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
842 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
843 * Tail elements are all moved by one. If you don't need a stable order
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
844 * in the array, consider using cx_array_remove_fast().
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
845 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
846 * If the index is out of bounds, this function does nothing.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
847 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
848 * @param array the name of the array
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
849 * @param index (@c size_t) the index of the element to remove
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
850 * @see cx_array_remove_fast()
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
851 */
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
852 #define cx_array_remove(array, index) \
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
853 cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, 1, false)
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
854
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
855 /**
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
856 * Removes one element from the array.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
857 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
858 * The gap will be filled with a copy of the last element in the array.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
859 * This changes the order of elements. If you want a stable order,
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
860 * use cx_array_remove() instead.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
861 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
862 * If the index is out of bounds, this function does nothing.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
863 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
864 * @param array the name of the array
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
865 * @param index (@c size_t) the index of the element to remove
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
866 * @see cx_array_remove()
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
867 */
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
868 #define cx_array_remove_fast(array, index) \
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
869 cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, 1, true)
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
870
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
871 /**
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
872 * Removes multiple elements from the array.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
873 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
874 * Tail elements are all moved to close the gap. If you don't need a stable
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
875 * order in the array, consider using cx_array_remove_array_fast().
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
876 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
877 * If the index is out of bounds, this function does nothing.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
878 * If @n overflows the array, this function removes as many elements as it can.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
879 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
880 * @param array the name of the array
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
881 * @param index (@c size_t) the index of the first element to remove
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
882 * @param n (@c size_t) the number of elements to remove
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
883 * @see cx_array_remove_array_fast()
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
884 */
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
885 #define cx_array_remove_array(array, index, n) \
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
886 cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, n, false)
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
887
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
888 /**
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
889 * Removes multiple elements from the array.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
890 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
891 * Tail elements are copied into the gap. If you have more tail elements
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
892 * than the number of elements that are removed, this will change the order
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
893 * of elements. If you want a stable order, use cx_array_remove_array() instead.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
894 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
895 * If the index is out of bounds, this function does nothing.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
896 * If @n overflows the array, this function removes as many elements as it can.
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
897 *
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
898 * @param array the name of the array
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
899 * @param index (@c size_t) the index of the first element to remove
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
900 * @param n (@c size_t) the number of elements to remove
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
901 * @see cx_array_remove_array()
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
902 */
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
903 #define cx_array_remove_array_fast(array, index, n) \
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
904 cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, n, true)
a2565f9fc6de add cx_array_remove() and cx_array_remove_fast()
Mike Becker <universe@uap-core.de>
parents: 1625
diff changeset
905
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
906 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
907 * Deallocates an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
908 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
909 * Internal function - do not use.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
910 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
911 * @param allocator (@c CxAllocator*) the allocator which was used to allocate the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
912 * @param array a pointer to the array structure
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
913 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
914 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
915 void cx_array_free_(const CxAllocator *allocator, CxArray *array);
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
916
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
917 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
918 * Deallocates an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
919 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
920 * The structure is reset to zero and can be re-initialized with
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
921 * cx_array_inita().
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
922 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
923 * @param array the name of the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
924 */
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
925 #define cx_array_free(array) cx_array_free_(cxDefaultAllocator, (CxArray*)&(array))
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
926
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
927 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
928 * Deallocates an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
929 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
930 * The structure is reset to zero and can be re-initialized with
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
931 * cx_array_init_a().
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
932 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
933 * @param allocator (@c CxAllocator*) the allocator which was used to allocate the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
934 * @param array the name of the array
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
935 */
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
936 #define cx_array_free_a(allocator, array) cx_array_free_(allocator, (CxArray*)&(array))
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
937
998
bb196054f3fd make cx_array_copy() support different types for size/capacity - fixes #492
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
938
884
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
939 /**
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
940 * Searches the largest lower bound in a sorted array.
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
941 *
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
942 * In other words, this function returns the index of the largest element
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
943 * in @p arr that is less or equal to @p elem with respect to @p cmp_func.
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
944 * When no such element exists, @p size is returned.
884
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
945 *
1507
f4010cda9a2a stable return value for binary search when there are duplicates in the array
Mike Becker <universe@uap-core.de>
parents: 1482
diff changeset
946 * When such an element exists more than once, the largest index of all those
f4010cda9a2a stable return value for binary search when there are duplicates in the array
Mike Becker <universe@uap-core.de>
parents: 1482
diff changeset
947 * elements is returned.
f4010cda9a2a stable return value for binary search when there are duplicates in the array
Mike Becker <universe@uap-core.de>
parents: 1482
diff changeset
948 *
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
949 * If @p elem is contained in the array, this is identical to
884
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
950 * #cx_array_binary_search().
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
951 *
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
952 * If the array is not sorted with respect to the @p cmp_func, the behavior
884
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
953 * is undefined.
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
954 *
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
955 * @param arr the array to search
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
956 * @param size the size of the array
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
957 * @param elem_size the size of one element
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
958 * @param elem the element to find
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
959 * @param cmp_func the compare function
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
960 * @return the index of the largest lower bound, or @p size
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
961 * @see cx_array_binary_search_sup()
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
962 * @see cx_array_binary_search()
884
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
963 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
964 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
965 size_t cx_array_binary_search_inf(const void *arr, size_t size,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1425
diff changeset
966 size_t elem_size, const void *elem, cx_compare_func cmp_func);
884
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
967
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
968 /**
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
969 * Searches an item in a sorted array.
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
970 *
1507
f4010cda9a2a stable return value for binary search when there are duplicates in the array
Mike Becker <universe@uap-core.de>
parents: 1482
diff changeset
971 * When such an element exists more than once, the largest index of all those
f4010cda9a2a stable return value for binary search when there are duplicates in the array
Mike Becker <universe@uap-core.de>
parents: 1482
diff changeset
972 * elements is returned.
f4010cda9a2a stable return value for binary search when there are duplicates in the array
Mike Becker <universe@uap-core.de>
parents: 1482
diff changeset
973 *
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
974 * If the array is not sorted with respect to the @p cmp_func, the behavior
884
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
975 * is undefined.
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
976 *
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
977 * @param arr the array to search
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
978 * @param size the size of the array
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
979 * @param elem_size the size of one element
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
980 * @param elem the element to find
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
981 * @param cmp_func the compare function
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
982 * @return the index of the element in the array, or @p size if the element
884
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
983 * cannot be found
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
984 * @see cx_array_binary_search_inf()
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
985 * @see cx_array_binary_search_sup()
884
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
986 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
987 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
988 size_t cx_array_binary_search(const void *arr, size_t size,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1425
diff changeset
989 size_t elem_size, const void *elem, cx_compare_func cmp_func);
884
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
990
831
7970eac1c598 add convenience macros for cx_array_*
Mike Becker <universe@uap-core.de>
parents: 819
diff changeset
991 /**
886
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
992 * Searches the smallest upper bound in a sorted array.
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
993 *
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
994 * In other words, this function returns the index of the smallest element
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
995 * in @p arr that is greater or equal to @p elem with respect to @p cmp_func.
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
996 * When no such element exists, @p size is returned.
886
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
997 *
1507
f4010cda9a2a stable return value for binary search when there are duplicates in the array
Mike Becker <universe@uap-core.de>
parents: 1482
diff changeset
998 * When such an element exists more than once, the smallest index of all those
f4010cda9a2a stable return value for binary search when there are duplicates in the array
Mike Becker <universe@uap-core.de>
parents: 1482
diff changeset
999 * elements is returned.
f4010cda9a2a stable return value for binary search when there are duplicates in the array
Mike Becker <universe@uap-core.de>
parents: 1482
diff changeset
1000 *
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
1001 * If @p elem is contained in the array, this is identical to
886
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
1002 * #cx_array_binary_search().
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
1003 *
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
1004 * If the array is not sorted with respect to the @p cmp_func, the behavior
886
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
1005 * is undefined.
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
1006 *
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
1007 * @param arr the array to search
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
1008 * @param size the size of the array
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
1009 * @param elem_size the size of one element
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
1010 * @param elem the element to find
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
1011 * @param cmp_func the compare function
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
1012 * @return the index of the smallest upper bound, or @p size
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
1013 * @see cx_array_binary_search_inf()
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
1014 * @see cx_array_binary_search()
886
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
1015 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
1016 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
1017 size_t cx_array_binary_search_sup(const void *arr, size_t size,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1425
diff changeset
1018 size_t elem_size, const void *elem, cx_compare_func cmp_func);
886
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
1019
1618
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1020
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1021 /**
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1022 * Searches the largest lower bound in a sorted array.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1023 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1024 * In other words, this function returns the index of the largest element
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1025 * in @p arr that is less or equal to @p elem with respect to @p cmp_func.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1026 * When no such element exists, @p size is returned.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1027 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1028 * When such an element exists more than once, the largest index of all those
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1029 * elements is returned.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1030 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1031 * If @p elem is contained in the array, this is identical to
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1032 * #cx_array_binary_search().
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1033 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1034 * If the array is not sorted with respect to the @p cmp_func, the behavior
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1035 * is undefined.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1036 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1037 * @param arr the array to search
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1038 * @param size the size of the array
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1039 * @param elem_size the size of one element
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1040 * @param elem the element to find
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1041 * @param cmp_func the compare function
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1042 * @param context the context for the compare function
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1043 * @return the index of the largest lower bound, or @p size
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1044 * @see cx_array_binary_search_sup()
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1045 * @see cx_array_binary_search()
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1046 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
1047 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
1048 size_t cx_array_binary_search_inf_c(const void *arr, size_t size,
1618
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1049 size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context);
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1050
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1051 /**
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1052 * Searches an item in a sorted array.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1053 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1054 * When such an element exists more than once, the largest index of all those
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1055 * elements is returned.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1056 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1057 * If the array is not sorted with respect to the @p cmp_func, the behavior
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1058 * is undefined.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1059 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1060 * @param arr the array to search
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1061 * @param size the size of the array
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1062 * @param elem_size the size of one element
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1063 * @param elem the element to find
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1064 * @param cmp_func the compare function
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1065 * @param context the context for the compare function
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1066 * @return the index of the element in the array, or @p size if the element
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1067 * cannot be found
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1068 * @see cx_array_binary_search_inf()
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1069 * @see cx_array_binary_search_sup()
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1070 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
1071 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
1072 size_t cx_array_binary_search_c(const void *arr, size_t size,
1618
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1073 size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context);
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1074
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1075 /**
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1076 * Searches the smallest upper bound in a sorted array.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1077 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1078 * In other words, this function returns the index of the smallest element
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1079 * in @p arr that is greater or equal to @p elem with respect to @p cmp_func.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1080 * When no such element exists, @p size is returned.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1081 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1082 * When such an element exists more than once, the smallest index of all those
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1083 * elements is returned.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1084 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1085 * If @p elem is contained in the array, this is identical to
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1086 * #cx_array_binary_search().
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1087 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1088 * If the array is not sorted with respect to the @p cmp_func, the behavior
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1089 * is undefined.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1090 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1091 * @param arr the array to search
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1092 * @param size the size of the array
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1093 * @param elem_size the size of one element
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1094 * @param elem the element to find
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1095 * @param cmp_func the compare function
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1096 * @param context the context for the compare function
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1097 * @return the index of the smallest upper bound, or @p size
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1098 * @see cx_array_binary_search_inf()
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1099 * @see cx_array_binary_search()
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1100 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
1101 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
1102 size_t cx_array_binary_search_sup_c(const void *arr, size_t size,
1618
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1103 size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context);
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1611
diff changeset
1104
886
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
1105 /**
623
21082350a590 #219 array list: implement reverse
Mike Becker <universe@uap-core.de>
parents: 617
diff changeset
1106 * Swaps two array elements.
21082350a590 #219 array list: implement reverse
Mike Becker <universe@uap-core.de>
parents: 617
diff changeset
1107 *
21082350a590 #219 array list: implement reverse
Mike Becker <universe@uap-core.de>
parents: 617
diff changeset
1108 * @param arr the array
21082350a590 #219 array list: implement reverse
Mike Becker <universe@uap-core.de>
parents: 617
diff changeset
1109 * @param elem_size the element size
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
1110 * @param idx1 index of the first element
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
1111 * @param idx2 index of the second element
623
21082350a590 #219 array list: implement reverse
Mike Becker <universe@uap-core.de>
parents: 617
diff changeset
1112 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
1113 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
1114 void cx_array_swap(void *arr, size_t elem_size, size_t idx1, size_t idx2);
623
21082350a590 #219 array list: implement reverse
Mike Becker <universe@uap-core.de>
parents: 617
diff changeset
1115
608
2e93521145ac proposal for a low level array copy
Mike Becker <universe@uap-core.de>
parents: 606
diff changeset
1116 /**
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
1117 * Allocates an array list for storing elements with @p elem_size bytes each.
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1118 *
1111
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1089
diff changeset
1119 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
1120 * copies of the added elements, and the compare function will be automatically set
1605
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1507
diff changeset
1121 * to cx_cmp_ptr().
669
dce9b8450656 add docs for CX_STORE_POINTERS and remove cxHashMapCreateForPointers()
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
1122 *
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1123 * @param allocator the allocator for allocating the list memory
1318
12fa1d37fe48 allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents: 1239
diff changeset
1124 * (if @c NULL, the cxDefaultAllocator will be used)
855
35bcb3216c0d fix inconsistent use of item_size and elem_size
Mike Becker <universe@uap-core.de>
parents: 844
diff changeset
1125 * @param elem_size the size of each element in bytes
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1126 * @param initial_capacity the initial number of elements the array can store
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1127 * @return the created list
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1128 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
1129 CX_EXTERN CX_NODISCARD CX_MALLOC CX_DEALLOC(cxListFree, 1)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1626
diff changeset
1130 CxList *cxArrayListCreate(const CxAllocator *allocator,
1605
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1507
diff changeset
1131 size_t elem_size, size_t initial_capacity);
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1132
628
1e2be40f0cb5 use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
1133 #endif // UCX_ARRAY_LIST_H

mercurial