ucx/cx/array_list.h

Fri, 19 Dec 2025 17:53:18 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 19 Dec 2025 17:53:18 +0100
branch
dav-2
changeset 891
4d58cbcc9efa
parent 889
42cdbf9bbd49
permissions
-rw-r--r--

update ucx

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

mercurial