src/cx/array_list.h

Tue, 16 Dec 2025 12:07:01 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 16 Dec 2025 12:07:01 +0100
changeset 1611
de21dd0d1426
parent 1608
46d8a8305948
permissions
-rw-r--r--

adds docstrings to the new array API - relates to #619

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 #ifdef __cplusplus
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 extern "C" {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 #endif
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 /**
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
47 * 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
48 * 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
49 */
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
50 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
51
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
52 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
53 * 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
54 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
55 * @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
56 * @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
57 */
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
58 #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
59 struct { \
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
60 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
61 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
62 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
63 } name
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
64
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
65 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
66 * 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
67 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
68 * 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
69 */
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 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
71 /** 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
72 void *data;
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
73 /** 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
74 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
75 /** 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
76 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
77 } CxArray;
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
78
1611
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 * 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
81 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
82 * 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
83 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
84 * @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
85 * @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
86 * @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
87 * @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
88 * @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
89 * @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
90 */
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
91 cx_attr_nonnull
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
92 CX_EXPORT int cx_array_init_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity);
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
93
1611
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 * 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
96 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
97 * 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
98 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
99 * @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
100 * 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
101 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
102 * @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
103 * @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
104 * @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
105 * @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
106 * @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
107 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
108 #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
109
1611
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 * 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
112 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
113 * 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
114 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
115 * @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
116 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
117 * @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
118 * @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
119 * @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
120 * @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
121 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
122 #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
123
1611
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 * 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
126 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
127 * 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
128 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
129 * @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
130 * @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
131 * @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
132 * @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
133 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
134 cx_attr_nonnull
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
135 CX_EXPORT void cx_array_init_fixed_(CxArray *array, const void *data, size_t capacity, size_t size);
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
136
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
137 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
138 * 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
139 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
140 * 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
141 * 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
142 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
143 * 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
144 * 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
145 * 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
146 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
147 * 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
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 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
150 * 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
151 * 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
152 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
153 * @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
154 * 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
155 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
156 * @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
157 * @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
158 * @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
159 * @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
160 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
161 #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
162 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
163
1611
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 * 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
166 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
167 * 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
168 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
169 * @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
170 * @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
171 * @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
172 * @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
173 * @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
174 * @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
175 */
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
176 cx_attr_nonnull
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
177 CX_EXPORT 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
178
1611
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 * 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
181 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
182 * 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
183 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
184 * @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
185 * @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
186 * @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
187 * @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
188 * @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
189 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
190 #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
191 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
192
1611
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 * 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
195 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
196 * 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
197 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
198 * @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
199 * @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
200 * @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
201 * @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
202 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
203 #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
204 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
205
1611
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 * 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
208 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
209 * 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
210 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
211 * @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
212 * @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
213 * @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
214 * @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
215 * @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
216 * @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
217 */
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
218 cx_attr_nonnull
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
219 CX_EXPORT int cx_array_copy_to_new_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity);
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
220
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
221 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
222 * 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
223 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
224 * 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
225 * 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
226 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
227 * @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
228 * 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
229 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
230 * @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
231 * @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
232 * @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
233 * @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
234 * @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
235 * @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
236 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
237 #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
238 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
239
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
240 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
241 * 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
242 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
243 * 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
244 * 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
245 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
246 * @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
247 * 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
248 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
249 * @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
250 * @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
251 * @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
252 * @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
253 * @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
254 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
255 #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
256 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
257
1611
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 * 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
260 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
261 * 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
262 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
263 * @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
264 * @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
265 * @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
266 * @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
267 * @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
268 * @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
269 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
270 * @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
271 */
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
272 cx_attr_nonnull_arg(1, 2)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
273 CX_EXPORT 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
274 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
275
1611
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 * 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
278 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
279 * 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
280 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
281 * @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
282 * @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
283 * @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
284 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
285 * @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
286 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
287 #define cx_array_add_a(allocator, array, element) \
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
288 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (array).size, element, 1)
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
289
1611
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 * 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
292 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
293 * 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
294 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
295 * @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
296 * @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
297 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
298 * @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
299 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
300 #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
301 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
302
1611
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 * 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
305 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
306 * 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
307 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
308 * @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
309 * @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
310 * @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
311 * @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
312 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
313 * @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
314 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
315 #define cx_array_insert_a(allocator, array, index, element) \
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
316 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), index, element, 1)
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
317
1611
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 * 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
320 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
321 * 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
322 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
323 * @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
324 * @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
325 * @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
326 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
327 * @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
328 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
329 #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
330 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
331
1611
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 * 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
334 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
335 * 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
336 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
337 * @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
338 * @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
339 * @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
340 * @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
341 * @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
342 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
343 * @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
344 */
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
345 #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
346 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
347
1611
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 * 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
350 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
351 * 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
352 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
353 * @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
354 * @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
355 * @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
356 * @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
357 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
358 * @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
359 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
360 #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
361 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
362
1611
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 * 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
365 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
366 * 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
367 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
368 * @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
369 * @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
370 * @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
371 * @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
372 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
373 * @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
374 */
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
375 #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
376 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
377
1611
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 * 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
380 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
381 * 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
382 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
383 * @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
384 * @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
385 * @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
386 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
387 * @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
388 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
389 #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
390 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
391
1611
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 * 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
394 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
395 * 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
396 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
397 * @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
398 * @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
399 * @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
400 * @param cmp_func
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
401 * @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
402 * @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
403 * @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
404 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
405 * @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
406 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
407 cx_attr_nonnull
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
408 CX_EXPORT int cx_array_insert_sorted_(const CxAllocator *allocator, CxArray *array,
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
409 size_t elem_size, cx_compare_func cmp_func, const void *sorted_data, size_t n,
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
410 bool allow_duplicates);
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
411
1611
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 * 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
414 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
415 * 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
416 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
417 * @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
418 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
419 * @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
420 * @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
421 * @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
422 * @param element (@c void*) a pointer to 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
423 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
424 * @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
425 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
426 #define cx_array_insert_sorted_a(allocator, array, cmp_func, element) \
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
427 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), cmp_func, element, 1, true)
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
428
1611
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 * 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
431 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
432 * 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
433 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
434 * @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
435 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
436 * @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
437 * @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
438 * @param element (@c void*) a pointer to 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
439 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
440 * @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
441 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
442 #define cx_array_insert_sorted(array, cmp_func, element) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
443 cx_array_insert_sorted_a(cxDefaultAllocator, array, cmp_func, element)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
444
1611
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 * 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
447 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
448 * 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
449 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
450 * @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
451 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
452 * @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
453 * @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
454 * @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
455 * @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
456 * @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
457 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
458 * @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
459 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
460 #define cx_array_insert_sorted_array_a(allocator, array, cmp_func, sorted_data, n) \
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
461 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), cmp_func, sorted_data, n, true)
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
462
1611
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 * 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
465 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
466 * 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
467 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
468 * @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
469 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
470 * @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
471 * @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
472 * @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
473 * @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
474 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
475 * @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
476 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
477 #define cx_array_insert_sorted_array(array, cmp_func, sorted_data, n) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
478 cx_array_insert_sorted_array_a(cxDefaultAllocator, array, cmp_func, sorted_data, n)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
479
1611
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 * 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
482 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
483 * 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
484 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
485 * @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
486 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
487 * @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
488 * @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
489 * @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
490 * @param element (@c void*) a pointer to 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
491 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
492 * @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
493 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
494 #define cx_array_insert_unique_a(allocator, array, cmp_func, element) \
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
495 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), cmp_func, element, 1, false)
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
496
1611
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 * 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
499 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
500 * 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
501 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
502 * @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
503 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
504 * @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
505 * @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
506 * @param element (@c void*) a pointer to 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
507 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
508 * @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
509 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
510 #define cx_array_insert_unique(array, cmp_func, element) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
511 cx_array_insert_unique_a(cxDefaultAllocator, array, cmp_func, element)
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
512
1611
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 * 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
515 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
516 * 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
517 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
518 * @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
519 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
520 * @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
521 * @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
522 * @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
523 * @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
524 * @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
525 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
526 * @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
527 */
1608
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
528 #define cx_array_insert_unique_array_a(allocator, array, cmp_func, sorted_data, n) \
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
529 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), cmp_func, sorted_data, n, false)
46d8a8305948 complete refactoring of low-level array list functions - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1607
diff changeset
530
1611
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 * 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
533 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
534 * 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
535 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
536 * @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
537 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
538 * @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
539 * @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
540 * @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
541 * @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
542 * @retval zero success
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
543 * @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
544 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
545 #define cx_array_insert_unique_array(array, cmp_func, sorted_data, n) \
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
546 cx_array_insert_unique_array_a(cxDefaultAllocator, array, cmp_func, sorted_data, 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
547
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
548 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
549 * 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
550 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
551 * 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
552 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
553 * @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
554 * @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
555 * @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
556 */
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
557 cx_attr_nodiscard cx_attr_nonnull
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
558 CX_EXPORT CxIterator cx_array_iterator_(CxArray *array, size_t elem_size);
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
559
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
560 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
561 * 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
562 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
563 * 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
564 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
565 * @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
566 * @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
567 * @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
568 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
569 #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
570 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
571
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
572 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
573 * 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
574 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
575 * 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
576 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
577 * @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
578 * @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
579 */
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
580 cx_attr_nodiscard cx_attr_nonnull
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
581 CX_EXPORT CxIterator cx_array_iterator_ptr_(CxArray *array);
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
582
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
583 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
584 * 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
585 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
586 * 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
587 * be pointers.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
588 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
589 * @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
590 * @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
591 * @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
592 */
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
593 #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
594 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
595
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
596 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
597 * Deallocates an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
598 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
599 * 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
600 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
601 * @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
602 * @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
603 */
1606
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
604 cx_attr_nonnull
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
605 CX_EXPORT void cx_array_free_(const CxAllocator *allocator, CxArray *array);
f5883f6e42e7 first draft for simplifying the low-level array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
606
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
607 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
608 * Deallocates an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
609 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
610 * 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
611 * cx_array_inita().
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
612 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
613 * @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
614 */
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
615 #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
616
1611
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
617 /**
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
618 * Deallocates an array.
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
619 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
620 * 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
621 * 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
622 *
de21dd0d1426 adds docstrings to the new array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1608
diff changeset
623 * @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
624 * @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
625 */
1607
0ecb13118cac next step of simplifying the array API - relates to #619
Mike Becker <universe@uap-core.de>
parents: 1606
diff changeset
626 #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
627
998
bb196054f3fd make cx_array_copy() support different types for size/capacity - fixes #492
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
628
884
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
629 /**
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
630 * 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
631 *
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
632 * 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
633 * 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
634 * 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
635 *
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
636 * 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
637 * 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
638 *
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
639 * 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
640 * #cx_array_binary_search().
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
641 *
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
642 * 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
643 * is undefined.
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
644 *
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
645 * @param arr the array to search
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
646 * @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
647 * @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
648 * @param elem the element to find
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
649 * @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
650 * @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
651 * @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
652 * @see cx_array_binary_search()
884
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
653 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 953
diff changeset
654 cx_attr_nonnull
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
655 CX_EXPORT size_t cx_array_binary_search_inf(const void *arr, size_t size,
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
656 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
657
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
658 /**
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
659 * 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
660 *
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
661 * 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
662 * 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
663 *
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
664 * 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
665 * is undefined.
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
666 *
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
667 * @param arr the array to search
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
668 * @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
669 * @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
670 * @param elem the element to find
d375d8056262 add cx_array_binary_search() - fixes #424
Mike Becker <universe@uap-core.de>
parents: 883
diff changeset
671 * @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
672 * @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
673 * cannot be found
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
674 * @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
675 * @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
676 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 953
diff changeset
677 cx_attr_nonnull
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
678 CX_EXPORT size_t cx_array_binary_search(const void *arr, size_t size,
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
679 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
680
831
7970eac1c598 add convenience macros for cx_array_*
Mike Becker <universe@uap-core.de>
parents: 819
diff changeset
681 /**
886
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
682 * 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
683 *
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
684 * 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
685 * 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
686 * 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
687 *
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
688 * 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
689 * 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
690 *
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
691 * 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
692 * #cx_array_binary_search().
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
693 *
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
694 * 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
695 * is undefined.
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
696 *
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
697 * @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
698 * @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
699 * @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
700 * @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
701 * @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
702 * @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
703 * @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
704 * @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
705 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 953
diff changeset
706 cx_attr_nonnull
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
707 CX_EXPORT size_t cx_array_binary_search_sup(const void *arr, size_t size,
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
708 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
709
5f5514bb104b also add a binary search for the supremum
Mike Becker <universe@uap-core.de>
parents: 885
diff changeset
710 /**
623
21082350a590 #219 array list: implement reverse
Mike Becker <universe@uap-core.de>
parents: 617
diff changeset
711 * Swaps two array elements.
21082350a590 #219 array list: implement reverse
Mike Becker <universe@uap-core.de>
parents: 617
diff changeset
712 *
21082350a590 #219 array list: implement reverse
Mike Becker <universe@uap-core.de>
parents: 617
diff changeset
713 * @param arr the array
21082350a590 #219 array list: implement reverse
Mike Becker <universe@uap-core.de>
parents: 617
diff changeset
714 * @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
715 * @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
716 * @param idx2 index of the second element
623
21082350a590 #219 array list: implement reverse
Mike Becker <universe@uap-core.de>
parents: 617
diff changeset
717 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 953
diff changeset
718 cx_attr_nonnull
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
719 CX_EXPORT 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
720
608
2e93521145ac proposal for a low level array copy
Mike Becker <universe@uap-core.de>
parents: 606
diff changeset
721 /**
1089
865c84fef6b4 refine docs for array_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1084
diff changeset
722 * 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
723 *
1111
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1089
diff changeset
724 * 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
725 * 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
726 * 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
727 *
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
728 * @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
729 * (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
730 * @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
731 * @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
732 * @return the created list
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
733 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 953
diff changeset
734 cx_attr_nodiscard
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 953
diff changeset
735 cx_attr_malloc
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 989
diff changeset
736 cx_attr_dealloc(cxListFree, 1)
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
737 CX_EXPORT 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
738 size_t elem_size, size_t initial_capacity);
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
739
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
740 #ifdef __cplusplus
628
1e2be40f0cb5 use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
741 } // extern "C"
606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
742 #endif
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
743
628
1e2be40f0cb5 use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents: 623
diff changeset
744 #endif // UCX_ARRAY_LIST_H

mercurial