ucx/cx/array_list.h

Sat, 08 Nov 2025 23:06:11 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 08 Nov 2025 23:06:11 +0100
changeset 888
af685cc9d623
parent 854
1c8401ece69e
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 /**
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
47 * The maximum item size in an array list that fits into
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
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 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
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 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
53 * Declares variables for an array that can be used with the convenience macros.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
54 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
55 * @par Examples
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
56 * @code
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
57 * // integer array with at most 255 elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
58 * CX_ARRAY_DECLARE_SIZED(int, myarray, uint8_t)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
59 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
60 * // array of MyObject* pointers where size and capacity are stored as unsigned int
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
61 * CX_ARRAY_DECLARE_SIZED(MyObject*, objects, unsigned int)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
62 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
63 * // initializing code
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
64 * cx_array_initialize(myarray, 16); // reserve space for 16
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
65 * cx_array_initialize(objects, 100); // reserve space for 100
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
66 * @endcode
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
67 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
68 * @param type the type of the data
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
69 * @param name the name of the array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
70 * @param size_type the type of the size (should be uint8_t, uint16_t, uint32_t, or size_t)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
71 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
72 * @see cx_array_initialize()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
73 * @see cx_array_simple_add()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
74 * @see cx_array_simple_copy()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
75 * @see cx_array_simple_add_sorted()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
76 * @see cx_array_simple_insert_sorted()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
77 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
78 #define CX_ARRAY_DECLARE_SIZED(type, name, size_type) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
79 type * name; \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
80 /** Array size. */ size_type name##_size; \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
81 /** Array capacity. */ size_type name##_capacity
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
82
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
83 /**
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
84 * Declares variables for an array that can be used with the convenience macros.
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
85 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
86 * The size and capacity variables will have type @c size_t.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
87 * Use #CX_ARRAY_DECLARE_SIZED() to specify a different type.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
88 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
89 * @par Examples
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
90 * @code
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
91 * // int array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
92 * CX_ARRAY_DECLARE(int, myarray)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
93 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
94 * // initializing code
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
95 * cx_array_initialize(myarray, 32); // reserve space for 32
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
96 * @endcode
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
97 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
98 * @param type the type of the data
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
99 * @param name the name of the array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
100 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
101 * @see cx_array_initialize()
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
102 * @see cx_array_simple_add()
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
103 * @see cx_array_simple_copy()
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
104 * @see cx_array_simple_add_sorted()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
105 * @see cx_array_simple_insert_sorted()
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
106 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
107 #define CX_ARRAY_DECLARE(type, name) CX_ARRAY_DECLARE_SIZED(type, name, size_t)
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
108
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
109 /**
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
110 * Initializes an array with the given capacity.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
111 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
112 * The type of the capacity depends on the type used during declaration.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
113 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
114 * @par Examples
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
115 * @code
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
116 * CX_ARRAY_DECLARE_SIZED(int, arr1, uint8_t)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
117 * CX_ARRAY_DECLARE(int, arr2) // size and capacity are implicitly size_t
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
118 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
119 * // initializing code
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
120 * cx_array_initialize(arr1, 500); // error: maximum for uint8_t is 255
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
121 * cx_array_initialize(arr2, 500); // OK
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
122 * @endcode
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
123 *
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
124 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
125 * The memory for the array is allocated with the cxDefaultAllocator.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
126 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
127 * @param array the name of the array
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
128 * @param capacity the initial capacity
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
129 * @see cx_array_initialize_a()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
130 * @see CX_ARRAY_DECLARE_SIZED()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
131 * @see CX_ARRAY_DECLARE()
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
132 */
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
133 #define cx_array_initialize(array, capacity) \
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
134 array##_capacity = capacity; \
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
135 array##_size = 0; \
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
136 array = cxMallocDefault(sizeof(array[0]) * capacity)
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
137
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
138 /**
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
139 * Initializes an array with the given capacity using the specified allocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
140 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
141 * @par Example
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
142 * @code
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
143 * CX_ARRAY_DECLARE(int, myarray)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
144 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
145 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
146 * const CxAllocator *al = // ...
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
147 * cx_array_initialize_a(al, myarray, 128);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
148 * // ...
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
149 * cxFree(al, myarray); // remember to free with the same allocator
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
150 * @endcode
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
151 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
152 * @param allocator (@c CxAllocator*) the allocator
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
153 * @param array the name of the array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
154 * @param capacity the initial capacity
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
155 * @see cx_array_initialize()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
156 * @see CX_ARRAY_DECLARE_SIZED()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
157 * @see CX_ARRAY_DECLARE()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
158 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
159 #define cx_array_initialize_a(allocator, array, capacity) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
160 array##_capacity = capacity; \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
161 array##_size = 0; \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
162 array = cxMalloc(allocator, sizeof(array[0]) * capacity)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
163
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
164 /**
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 * Defines a reallocation mechanism for arrays.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
166 * You can create your own, use cx_array_reallocator(), or
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
167 * use the #cx_array_default_reallocator.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 struct cx_array_reallocator_s {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 /**
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
171 * Reallocates space for the given array.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 * Implementations are not required to free the original array.
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
174 * This allows reallocation of static or stack memory by allocating heap memory
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
175 * and copying the array contents; namely when @c stack_ptr in this struct
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
176 * is not @c NULL and @p array equals @c stack_ptr.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 * @param array the array to reallocate
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
179 * @param old_capacity the old number of elements
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
180 * @param new_capacity the new number of elements
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 * @param elem_size the size of each element
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 * @param alloc a reference to this allocator
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
183 * @return a pointer to the reallocated memory or @c NULL on failure
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
185 void *(*realloc)( void *array, size_t old_capacity, size_t new_capacity,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
186 size_t elem_size, struct cx_array_reallocator_s *alloc);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 /**
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
189 * The allocator that shall be used for the reallocations.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
191 const CxAllocator *allocator;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 /**
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
193 * Optional pointer to stack memory
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
194 * if the array is originally located on the stack.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
196 const void *stack_ptr;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 };
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 /**
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
200 * Typedef for the array reallocator struct.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
201 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
202 typedef struct cx_array_reallocator_s CxArrayReallocator;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
203
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
204 /**
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
205 * A default array reallocator that is based on the cxDefaultAllocator.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
207 CX_EXPORT extern CxArrayReallocator *cx_array_default_reallocator;
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
208
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
209 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
210 * Creates a new array reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
211 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
212 * When @p allocator is @c NULL, the cxDefaultAllocator will be used.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
213 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
214 * When @p stack_ptr is not @c NULL, the reallocator is supposed to be used
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
215 * @em only for the specific array initially located at @p stack_ptr.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
216 * When reallocation is needed, the reallocator checks if the array is
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
217 * still located at @p stack_ptr and copies the contents to the heap.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
218 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
219 * @note Invoking this function with both arguments being @c NULL will return a
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
220 * reallocator that behaves like #cx_array_default_reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
221 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
222 * @param allocator the allocator this reallocator shall be based on
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
223 * @param stack_ptr the address of the array when the array is initially located
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
224 * on the stack or shall not reallocate in place
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
225 * @return an array reallocator
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
226 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
227 CX_EXPORT CxArrayReallocator cx_array_reallocator(
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
228 const struct cx_allocator_s *allocator, const void *stack_ptr);
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
229
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
230 /**
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
231 * Reserves memory for additional elements.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
232 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
233 * This function checks if the @p capacity of the array is sufficient to hold
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
234 * at least @p size plus @p elem_count elements. If not, a reallocation is
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
235 * performed with the specified @p reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
236 * You can create your own reallocator by hand, use #cx_array_default_reallocator,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
237 * or use the convenience function cx_array_reallocator() to create a custom reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
238 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
239 * This function can be useful to replace subsequent calls to cx_array_copy()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
240 * with one single cx_array_reserve() and then - after guaranteeing a
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
241 * sufficient capacity - use simple memmove() or memcpy().
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
242 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
243 * The @p width in bytes refers to the size and capacity.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
244 * Both must have the same width.
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
245 * Supported are 0, 1, 2, and 4, as well as 8 if running on a 64-bit
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
246 * architecture. If set to zero, the native word width is used.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
247 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
248 * @param array a pointer to the target array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
249 * @param size a pointer to the size of the array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
250 * @param capacity a pointer to the capacity of the array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
251 * @param width the width in bytes for the @p size and @p capacity or zero for default
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
252 * @param elem_size the size of one element
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
253 * @param elem_count the number of expected additional elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
254 * @param reallocator the array reallocator to use
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
255 * (@c NULL defaults to #cx_array_default_reallocator)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
256 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
257 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
258 * @see cx_array_reallocator()
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
259 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
260 cx_attr_nonnull_arg(1, 2, 3)
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
261 CX_EXPORT int cx_array_reserve(void **array, void *size, void *capacity,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
262 unsigned width, size_t elem_size, size_t elem_count,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
263 CxArrayReallocator *reallocator);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 * Copies elements from one array to another.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
268 * The elements are copied to the @p target array at the specified @p index,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
269 * overwriting possible elements. The @p index does not need to be in range of
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
270 * the current array @p size. If the new index plus the number of elements added
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
271 * extends the array's size, the remaining @p capacity is used.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
273 * If the @p capacity is also insufficient to hold the new data, a reallocation
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
274 * attempt is made with the specified @p reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
275 * You can create your own reallocator by hand, use #cx_array_default_reallocator,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
276 * or use the convenience function cx_array_reallocator() to create a custom reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
277 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
278 * The @p width in bytes refers to the size and capacity.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
279 * Both must have the same width.
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
280 * Supported are 0, 1, 2, and 4, as well as 8 if running on a 64-bit
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
281 * architecture. If set to zero, the native word width is used.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 *
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
283 * @param target a pointer to the target array
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 * @param size a pointer to the size of the target array
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
285 * @param capacity a pointer to the capacity of the target array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
286 * @param width the width in bytes for the @p size and @p capacity or zero for default
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 * @param index the index where the copied elements shall be placed
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 * @param src the source array
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 * @param elem_size the size of one element
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 * @param elem_count the number of elements to copy
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
291 * @param reallocator the array reallocator to use
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
292 * (@c NULL defaults to #cx_array_default_reallocator)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
293 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
294 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
295 * @see cx_array_reallocator()
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
297 cx_attr_nonnull_arg(1, 2, 3, 6)
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
298 CX_EXPORT int cx_array_copy(void **target, void *size, void *capacity, unsigned width,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
299 size_t index, const void *src, size_t elem_size, size_t elem_count,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
300 CxArrayReallocator *reallocator);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
301
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 * Convenience macro that uses cx_array_copy() with a default layout and
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
304 * the specified reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
305 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
306 * @param reallocator (@c CxArrayReallocator*) the array reallocator to use
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
307 * @param array the name of the array (NOT a pointer or alias to the array)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
308 * @param index (@c size_t) the index where the copied elements shall be placed
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
309 * @param src (@c void*) the source array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
310 * @param count (@c size_t) the number of elements to copy
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
311 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
312 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
313 * @see CX_ARRAY_DECLARE()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
314 * @see cx_array_simple_copy()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
315 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
316 #define cx_array_simple_copy_a(reallocator, array, index, src, count) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
317 cx_array_copy((void**)&(array), &(array##_size), &(array##_capacity), \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
318 sizeof(array##_size), index, src, sizeof((array)[0]), count, \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
319 reallocator)
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
321 /**
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
322 * Convenience macro that uses cx_array_copy() with a default layout and
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
323 * the default reallocator.
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
324 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
325 * @param array the name of the array (NOT a pointer or alias to the array)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
326 * @param index (@c size_t) the index where the copied elements shall be placed
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
327 * @param src (@c void*) the source array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
328 * @param count (@c size_t) the number of elements to copy
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
329 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
330 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
331 * @see CX_ARRAY_DECLARE()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
332 * @see cx_array_simple_copy_a()
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
333 */
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
334 #define cx_array_simple_copy(array, index, src, count) \
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
335 cx_array_simple_copy_a(NULL, array, index, src, count)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
336
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
337 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
338 * Convenience macro that uses cx_array_reserve() with a default layout and
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
339 * the specified reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
340 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
341 * @param reallocator (@c CxArrayReallocator*) the array reallocator to use
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
342 * @param array the name of the array (NOT a pointer or alias to the array)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
343 * @param count (@c size_t) the number of expected @em additional elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
344 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
345 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
346 * @see CX_ARRAY_DECLARE()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
347 * @see cx_array_simple_reserve()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
348 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
349 #define cx_array_simple_reserve_a(reallocator, array, count) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
350 cx_array_reserve((void**)&(array), &(array##_size), &(array##_capacity), \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
351 sizeof(array##_size), sizeof((array)[0]), count, \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
352 reallocator)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
353
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
354 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
355 * Convenience macro that uses cx_array_reserve() with a default layout and
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
356 * the default reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
357 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
358 * @param array the name of the array (NOT a pointer or alias to the array)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
359 * @param count (@c size_t) the number of expected additional elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
360 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
361 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
362 * @see CX_ARRAY_DECLARE()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
363 * @see cx_array_simple_reserve_a()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
364 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
365 #define cx_array_simple_reserve(array, count) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
366 cx_array_simple_reserve_a(NULL, array, count)
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
367
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
368 /**
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
369 * Adds an element to an array with the possibility of allocating more space.
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
370 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
371 * The element @p elem is added to the end of the @p target array which contains
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
372 * @p size elements, already. The @p capacity must point to a variable denoting
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
373 * the current maximum number of elements the array can hold.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
374 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
375 * If the capacity is insufficient to hold the new element, an attempt to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
376 * increase the @p capacity is made and the new capacity is written back.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
377 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
378 * The \@ SIZE_TYPE is flexible and can be any unsigned integer type.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
379 * It is important, however, that @p size and @p capacity are pointers to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
380 * variables of the same type.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
381 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
382 * @param target (@c void**) a pointer to the target array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
383 * @param size (@c SIZE_TYPE*) a pointer to the size of the target array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
384 * @param capacity (@c SIZE_TYPE*) a pointer to the capacity of the target array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
385 * @param elem_size (@c size_t) the size of one element
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
386 * @param elem (@c void*) a pointer to the element to add
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
387 * @param reallocator (@c CxArrayReallocator*) the array reallocator to use
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
388 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
389 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
390 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
391 #define cx_array_add(target, size, capacity, elem_size, elem, reallocator) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
392 cx_array_copy((void**)(target), size, capacity, sizeof(*(size)), \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
393 *(size), elem, elem_size, 1, reallocator)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
394
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
395 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
396 * Convenience macro that uses cx_array_add() with a default layout and
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
397 * the specified reallocator.
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
398 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
399 * @param reallocator (@c CxArrayReallocator*) the array reallocator to use
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
400 * @param array the name of the array (NOT a pointer or alias to the array)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
401 * @param elem the element to add (NOT a pointer, address is automatically taken)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
402 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
403 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
404 * @see CX_ARRAY_DECLARE()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
405 * @see cx_array_simple_add()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
406 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
407 #define cx_array_simple_add_a(reallocator, array, elem) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
408 cx_array_simple_copy_a(reallocator, array, array##_size, &(elem), 1)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
409
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
410 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
411 * Convenience macro that uses cx_array_add() with a default layout and
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
412 * the default reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
413 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
414 * @param array the name of the array (NOT a pointer or alias to the array)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
415 * @param elem the element to add (NOT a pointer, address is automatically taken)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
416 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
417 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
418 * @see CX_ARRAY_DECLARE()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
419 * @see cx_array_simple_add_a()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
420 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
421 #define cx_array_simple_add(array, elem) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
422 cx_array_simple_add_a(cx_array_default_reallocator, array, elem)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
423
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
424 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
425 * Inserts a sorted array into another sorted array.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
426 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
427 * If either the target or the source array is not already sorted with respect
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
428 * to the specified @p cmp_func, the behavior is undefined.
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 * If the capacity is insufficient to hold the new data, a reallocation
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
431 * attempt is made.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
432 * You can create your own reallocator by hand, use #cx_array_default_reallocator,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
433 * or use the convenience function cx_array_reallocator() to create a custom reallocator.
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
434 *
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
435 * @param target a pointer to the target array
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
436 * @param size a pointer to the size of the target array
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
437 * @param capacity a pointer to the capacity of the target array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
438 * @param cmp_func the compare function for the elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
439 * @param src the source array
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
440 * @param elem_size the size of one element
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
441 * @param elem_count the number of elements to insert
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
442 * @param reallocator the array reallocator to use
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
443 * (@c NULL defaults to #cx_array_default_reallocator)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
444 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
445 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
446 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
447 cx_attr_nonnull_arg(1, 2, 3, 5)
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
448 CX_EXPORT int cx_array_insert_sorted(void **target, size_t *size, size_t *capacity,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
449 cx_compare_func cmp_func, const void *src, size_t elem_size, size_t elem_count,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
450 CxArrayReallocator *reallocator);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
451
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
452 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
453 * Inserts an element into a sorted array.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
454 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
455 * If the target array is not already sorted with respect
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
456 * to the specified @p cmp_func, the behavior is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
457 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
458 * If the capacity is not enough to hold the new data, a reallocation
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
459 * attempt is made.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
460 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
461 * The \@ SIZE_TYPE is flexible and can be any unsigned integer type.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
462 * It is important, however, that @p size and @p capacity are pointers to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
463 * variables of the same type.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
464 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
465 * @param target (@c void**) a pointer to the target array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
466 * @param size (@c SIZE_TYPE*) a pointer to the size of the target array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
467 * @param capacity (@c SIZE_TYPE*) a pointer to the capacity of the target array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
468 * @param elem_size (@c size_t) the size of one element
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
469 * @param elem (@c void*) a pointer to the element to add
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
470 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
471 * @param reallocator (@c CxArrayReallocator*) the array reallocator to use
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
472 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
473 * @retval non-zero failure
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
474 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
475 #define cx_array_add_sorted(target, size, capacity, elem_size, elem, cmp_func, reallocator) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
476 cx_array_insert_sorted((void**)(target), size, capacity, cmp_func, elem, elem_size, 1, reallocator)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
477
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
478 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
479 * Convenience macro for cx_array_add_sorted() with a default
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
480 * layout and the specified reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
481 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
482 * @param reallocator (@c CxArrayReallocator*) the array reallocator to use
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
483 * @param array the name of the array (NOT a pointer or alias to the array)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
484 * @param elem the element to add (NOT a pointer, address is automatically taken)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
485 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
486 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
487 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
488 * @see CX_ARRAY_DECLARE()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
489 * @see cx_array_simple_add_sorted()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
490 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
491 #define cx_array_simple_add_sorted_a(reallocator, array, elem, cmp_func) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
492 cx_array_add_sorted(&array, &(array##_size), &(array##_capacity), \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
493 sizeof((array)[0]), &(elem), cmp_func, reallocator)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
494
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
495 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
496 * Convenience macro for cx_array_add_sorted() with a default
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
497 * layout and the default reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
498 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
499 * @param array the name of the array (NOT a pointer or alias to the array)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
500 * @param elem the element to add (NOT a pointer, address is automatically taken)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
501 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
502 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
503 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
504 * @see CX_ARRAY_DECLARE()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
505 * @see cx_array_simple_add_sorted_a()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
506 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
507 #define cx_array_simple_add_sorted(array, elem, cmp_func) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
508 cx_array_simple_add_sorted_a(NULL, array, elem, cmp_func)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
509
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
510 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
511 * Convenience macro for cx_array_insert_sorted() with a default
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
512 * layout and the specified reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
513 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
514 * @param reallocator (@c CxArrayReallocator*) the array reallocator to use
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
515 * @param array the name of the array (NOT a pointer or alias to the array)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
516 * @param src (@c void*) pointer to the source array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
517 * @param n (@c size_t) number of elements in the source array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
518 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
519 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
520 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
521 * @see CX_ARRAY_DECLARE()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
522 * @see cx_array_simple_insert_sorted()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
523 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
524 #define cx_array_simple_insert_sorted_a(reallocator, array, src, n, cmp_func) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
525 cx_array_insert_sorted((void**)(&array), &(array##_size), &(array##_capacity), \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
526 cmp_func, src, sizeof((array)[0]), n, reallocator)
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
527
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
528 /**
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
529 * Convenience macro for cx_array_insert_sorted() with a default
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
530 * layout and the default reallocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
531 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
532 * @param array the name of the array (NOT a pointer or alias to the array)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
533 * @param src (@c void*) pointer to the source array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
534 * @param n (@c size_t) number of elements in the source array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
535 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
536 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
537 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
538 * @see CX_ARRAY_DECLARE()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
539 * @see cx_array_simple_insert_sorted_a()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
540 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
541 #define cx_array_simple_insert_sorted(array, src, n, cmp_func) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
542 cx_array_simple_insert_sorted_a(NULL, array, src, n, cmp_func)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
543
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
544
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
545 /**
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
546 * Inserts a sorted array into another sorted array, avoiding duplicates.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
547 *
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
548 * If either the target or the source array is not already sorted with respect
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
549 * to the specified @p cmp_func, the behavior is undefined.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
550 *
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
551 * If the capacity is insufficient to hold the new data, a reallocation
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
552 * attempt is made.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
553 * You can create your own reallocator by hand, use #cx_array_default_reallocator,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
554 * or use the convenience function cx_array_reallocator() to create a custom reallocator.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
555 *
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
556 * @param target a pointer to the target array
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
557 * @param size a pointer to the size of the target array
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
558 * @param capacity a pointer to the capacity of the target array
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
559 * @param cmp_func the compare function for the elements
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
560 * @param src the source array
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
561 * @param elem_size the size of one element
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
562 * @param elem_count the number of elements to insert
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
563 * @param reallocator the array reallocator to use
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
564 * (@c NULL defaults to #cx_array_default_reallocator)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
565 * @retval zero success
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
566 * @retval non-zero failure
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
567 */
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
568 cx_attr_nonnull_arg(1, 2, 3, 5)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
569 CX_EXPORT int cx_array_insert_unique(void **target, size_t *size, size_t *capacity,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
570 cx_compare_func cmp_func, const void *src, size_t elem_size, size_t elem_count,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
571 CxArrayReallocator *reallocator);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
572
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
573 /**
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
574 * Inserts an element into a sorted array if it does not exist.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
575 *
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
576 * If the target array is not already sorted with respect
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
577 * to the specified @p cmp_func, the behavior is undefined.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
578 *
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
579 * If the capacity is insufficient to hold the new data, a reallocation
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
580 * attempt is made.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
581 *
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
582 * The \@ SIZE_TYPE is flexible and can be any unsigned integer type.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
583 * It is important, however, that @p size and @p capacity are pointers to
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
584 * variables of the same type.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
585 *
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
586 * @param target (@c void**) a pointer to the target array
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
587 * @param size (@c SIZE_TYPE*) a pointer to the size of the target array
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
588 * @param capacity (@c SIZE_TYPE*) a pointer to the capacity of the target array
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
589 * @param elem_size (@c size_t) the size of one element
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
590 * @param elem (@c void*) a pointer to the element to add
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
591 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
592 * @param reallocator (@c CxArrayReallocator*) the array reallocator to use
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
593 * @retval zero success (also when the element was already present)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
594 * @retval non-zero failure
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
595 */
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
596 #define cx_array_add_unique(target, size, capacity, elem_size, elem, cmp_func, reallocator) \
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
597 cx_array_insert_unique((void**)(target), size, capacity, cmp_func, elem, elem_size, 1, reallocator)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
598
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
599 /**
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
600 * Convenience macro for cx_array_add_unique() with a default
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
601 * layout and the specified reallocator.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
602 *
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
603 * @param reallocator (@c CxArrayReallocator*) the array reallocator to use
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
604 * @param array the name of the array (NOT a pointer or alias to the array)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
605 * @param elem the element to add (NOT a pointer, address is automatically taken)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
606 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
607 * @retval zero success
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
608 * @retval non-zero failure
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
609 * @see CX_ARRAY_DECLARE()
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
610 * @see cx_array_simple_add_unique()
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
611 */
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
612 #define cx_array_simple_add_unique_a(reallocator, array, elem, cmp_func) \
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
613 cx_array_add_unique(&array, &(array##_size), &(array##_capacity), \
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
614 sizeof((array)[0]), &(elem), cmp_func, reallocator)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
615
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
616 /**
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
617 * Convenience macro for cx_array_add_unique() with a default
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
618 * layout and the default reallocator.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
619 *
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
620 * @param array the name of the array (NOT a pointer or alias to the array)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
621 * @param elem the element to add (NOT a pointer, address is automatically taken)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
622 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
623 * @retval zero success
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
624 * @retval non-zero failure
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
625 * @see CX_ARRAY_DECLARE()
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
626 * @see cx_array_simple_add_unique_a()
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
627 */
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
628 #define cx_array_simple_add_unique(array, elem, cmp_func) \
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
629 cx_array_simple_add_unique_a(NULL, array, elem, cmp_func)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
630
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
631 /**
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
632 * Convenience macro for cx_array_insert_unique() with a default
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
633 * layout and the specified reallocator.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
634 *
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
635 * @param reallocator (@c CxArrayReallocator*) the array reallocator to use
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
636 * @param array the name of the array (NOT a pointer or alias to the array)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
637 * @param src (@c void*) pointer to the source array
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
638 * @param n (@c size_t) number of elements in the source array
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
639 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
640 * @retval zero success
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
641 * @retval non-zero failure
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
642 * @see CX_ARRAY_DECLARE()
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
643 * @see cx_array_simple_insert_unique()
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
644 */
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
645 #define cx_array_simple_insert_unique_a(reallocator, array, src, n, cmp_func) \
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
646 cx_array_insert_unique((void**)(&array), &(array##_size), &(array##_capacity), \
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
647 cmp_func, src, sizeof((array)[0]), n, reallocator)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
648
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
649 /**
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
650 * Convenience macro for cx_array_insert_unique() with a default
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
651 * layout and the default reallocator.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
652 *
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
653 * @param array the name of the array (NOT a pointer or alias to the array)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
654 * @param src (@c void*) pointer to the source array
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
655 * @param n (@c size_t) number of elements in the source array
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
656 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
657 * @retval zero success
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
658 * @retval non-zero failure
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
659 * @see CX_ARRAY_DECLARE()
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
660 * @see cx_array_simple_insert_unique_a()
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
661 */
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
662 #define cx_array_simple_insert_unique(array, src, n, cmp_func) \
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
663 cx_array_simple_insert_unique_a(NULL, array, src, n, cmp_func)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
664
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
665 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
666 * Searches the largest lower bound in a sorted array.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
667 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
668 * 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
669 * 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
670 * When no such element exists, @p size is returned.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
671 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
672 * 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
673 * #cx_array_binary_search().
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
674 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
675 * 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
676 * is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
677 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
678 * @param arr the array to search
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
679 * @param size the size of the array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
680 * @param elem_size the size of one element
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
681 * @param elem the element to find
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
682 * @param cmp_func the compare function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
683 * @return the index of the largest lower bound, or @p size
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
684 * @see cx_array_binary_search_sup()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
685 * @see cx_array_binary_search()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
686 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
687 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
688 CX_EXPORT size_t cx_array_binary_search_inf(const void *arr, size_t size,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
689 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
690
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
691 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
692 * 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
693 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
694 * 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
695 * is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
696 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
697 * @param arr the array to search
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
698 * @param size the size of the array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
699 * @param elem_size the size of one element
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
700 * @param elem the element to find
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
701 * @param cmp_func the compare function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
702 * @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
703 * cannot be found
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
704 * @see cx_array_binary_search_inf()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
705 * @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
706 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
707 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
708 CX_EXPORT size_t cx_array_binary_search(const void *arr, size_t size,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
709 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
710
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
711 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
712 * Searches the smallest upper bound in a sorted array.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
713 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
714 * 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
715 * 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
716 * When no such element exists, @p size is returned.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
717 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
718 * 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
719 * #cx_array_binary_search().
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
720 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
721 * 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
722 * is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
723 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
724 * @param arr the array to search
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
725 * @param size the size of the array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
726 * @param elem_size the size of one element
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
727 * @param elem the element to find
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
728 * @param cmp_func the compare function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
729 * @return the index of the smallest upper bound, or @p size
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
730 * @see cx_array_binary_search_inf()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
731 * @see cx_array_binary_search()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
732 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
733 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
734 CX_EXPORT size_t cx_array_binary_search_sup(const void *arr, size_t size,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
735 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
736
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
737 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
738 * 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
739 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
740 * @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
741 * @param elem_size the element size
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
742 * @param idx1 index of the first element
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
743 * @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
744 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
745 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
746 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
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
748 /**
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
749 * 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
750 *
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
751 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
752 * copies of the added elements, and the compare function will be automatically set
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
753 * to cx_cmp_ptr(), if none is given.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
754 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
755 * @param allocator the allocator for allocating the list memory
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
756 * (if @c NULL, the cxDefaultAllocator will be used)
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
757 * @param comparator the comparator for the elements
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
758 * (if @c NULL, and the list is not storing pointers, sort and find
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
759 * functions will not work)
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
760 * @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
761 * @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
762 * @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
763 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
764 cx_attr_nodiscard
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
765 cx_attr_malloc
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
766 cx_attr_dealloc(cxListFree, 1)
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
767 CX_EXPORT CxList *cxArrayListCreate(const CxAllocator *allocator,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
768 cx_compare_func comparator, 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
769
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
770 /**
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
771 * 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
772 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
773 * The list will use the cxDefaultAllocator and @em NO compare function.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
774 * If you want to call functions that need a compare function, you have to
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
775 * set it immediately after creation or use cxArrayListCreate().
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
776 *
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
777 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
778 * copies of the added elements and the compare function will be automatically set
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
779 * 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
780 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
781 * @param elem_size (@c size_t) the size of each element in bytes
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
782 * @param initial_capacity (@c size_t) the initial number of elements the array can store
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
783 * @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
784 */
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
785 #define cxArrayListCreateSimple(elem_size, initial_capacity) \
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
786 cxArrayListCreate(NULL, NULL, elem_size, 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
787
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
788 #ifdef __cplusplus
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
789 } // extern "C"
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
790 #endif
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
791
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
792 #endif // UCX_ARRAY_LIST_H

mercurial