src/ucx/ucx/array.h

Mon, 24 Aug 2020 17:07:41 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 24 Aug 2020 17:07:41 +0200
branch
config
changeset 256
19259b6c5cf7
parent 254
4784c14aa639
child 260
4779a6fb4fbe
permissions
-rw-r--r--

replace old server config loader

254
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2019 Mike Becker, Olaf Wintermann All rights reserved.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4784c14aa639 ucx update
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
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 * Dynamically allocated array implementation.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 * @file array.h
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 * @author Mike Becker
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 * @author Olaf Wintermann
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #ifndef UCX_ARRAY_H
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #define UCX_ARRAY_H
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "ucx.h"
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #include "allocator.h"
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #ifdef __cplusplus
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 extern "C" {
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 #endif
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 * UCX array type.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 typedef struct {
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 * The current capacity of the array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 size_t capacity;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 * The actual number of elements in the array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 size_t size;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 * The size of an individual element in bytes.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 size_t elemsize;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 * A pointer to the data.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 void* data;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 * The allocator used for the data.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 UcxAllocator* allocator;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 } UcxArray;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 * Sets an element in an arbitrary user defined array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 * If the capacity is insufficient, the array is automatically reallocated and
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 * the possibly new pointer is stored in the <code>array</code> argument.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 * On reallocation the capacity of the array is doubled until it is sufficient.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 * The new capacity is stored back to <code>capacity</code>.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 * @param array a pointer to location of the array pointer
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 * @param capacity a pointer to the capacity
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 * @param elmsize the size of each element
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 * @param idx the index of the element to set
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 * @param data the element data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 * @return zero on success or non-zero on error (errno will be set)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 #define ucx_array_util_set(array, capacity, elmsize, idx, data) \
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 ucx_array_util_set_a(ucx_default_allocator(), (void**)(array), capacity, \
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 elmsize, idx, data)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 * Convenience macro for ucx_array_util_set() which automatically computes
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 * <code>sizeof(data)</code>.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 * @param array a pointer to location of the array pointer
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 * @param capacity a pointer to the capacity
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 * @param idx the index of the element to set
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 * @param data the element data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 * @return zero on success or non-zero on error (errno will be set)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 * @see ucx_array_util_set()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 #define UCX_ARRAY_UTIL_SET(array, capacity, idx, data) \
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 ucx_array_util_set_a(ucx_default_allocator(), (void**)(array), capacity, \
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 sizeof(data), idx, data)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 * Sets an element in an arbitrary user defined array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 * If the capacity is insufficient, the array is automatically reallocated
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 * using the specified allocator and the possibly new pointer is stored in
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 * the <code>array</code> argument.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 * On reallocation the capacity of the array is doubled until it is sufficient.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 * The new capacity is stored back to <code>capacity</code>.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 * @param alloc the allocator that shall be used to reallocate the array
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 * @param array a pointer to location of the array pointer
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 * @param capacity a pointer to the capacity
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 * @param elmsize the size of each element
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 * @param idx the index of the element to set
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 * @param ... the element data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 * @return zero on success or non-zero on error (errno will be set)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 int ucx_array_util_set_a(UcxAllocator* alloc, void** array, size_t* capacity,
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 size_t elmsize, size_t idx, ...);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 * Convenience macro for ucx_array_util_set_a() which automatically computes
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 * <code>sizeof(data)</code>.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 * @param alloc the allocator that shall be used to reallocate the array
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 * @param array a pointer to location of the array pointer
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 * @param capacity a pointer to the capacity
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 * @param idx the index of the element to set
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 * @param data the element data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 * @return zero on success or non-zero on error (errno will be set)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 * @see ucx_array_util_set_a()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 #define UCX_ARRAY_UTIL_SET_A(alloc, array, capacity, idx, data) \
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 ucx_array_util_set_a(alloc, capacity, sizeof(data), idx, data)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 * Creates a new UCX array with the given capacity and element size.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 * @param capacity the initial capacity
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 * @param elemsize the element size
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 * @return a pointer to a new UCX array structure
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 UcxArray* ucx_array_new(size_t capacity, size_t elemsize);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 * Creates a new UCX array using the specified allocator.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 * @param capacity the initial capacity
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 * @param elemsize the element size
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 * @param allocator the allocator to use
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 * @return a pointer to new UCX array structure
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 UcxArray* ucx_array_new_a(size_t capacity, size_t elemsize,
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 UcxAllocator* allocator);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 * Initializes a UCX array structure with the given capacity and element size.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 * The structure must be uninitialized as the data pointer will be overwritten.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 * @param array the structure to initialize
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 * @param capacity the initial capacity
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 * @param elemsize the element size
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 void ucx_array_init(UcxArray* array, size_t capacity, size_t elemsize);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 * Initializes a UCX array structure using the specified allocator.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 * The structure must be uninitialized as the data pointer will be overwritten.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 * @param array the structure to initialize
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 * @param capacity the initial capacity
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 * @param elemsize the element size
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 * @param allocator the allocator to use
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 void ucx_array_init_a(UcxArray* array, size_t capacity, size_t elemsize,
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 UcxAllocator* allocator);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 * Creates an shallow copy of an array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 * This function clones the specified array by using memcpy().
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 * If the destination capacity is insufficient, an automatic reallocation is
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 * attempted.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 * Note: if the destination array is uninitialized, the behavior is undefined.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 * @param dest the array to copy to
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 * @param src the array to copy from
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 * @return zero on success, non-zero on reallocation failure.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 int ucx_array_clone(UcxArray* dest, UcxArray const* src);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 * Compares two UCX arrays element-wise by using a compare function.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 * Elements of the two specified arrays are compared by using the specified
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 * compare function and the additional data. The type and content of this
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 * additional data depends on the cmp_func() used.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 * This function always returns zero, if the element sizes of the arrays do
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 * not match and performs no comparisons in this case.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 * @param array1 the first array
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 * @param array2 the second array
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 * @param cmpfnc the compare function
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 * @param data additional data for the compare function
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 * @return 1, if and only if the two arrays equal element-wise, 0 otherwise
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 int ucx_array_equals(UcxArray const *array1, UcxArray const *array2,
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 cmp_func cmpfnc, void* data);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 * Destroys the array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 * The data is freed and both capacity and count are reset to zero.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 * If the array structure itself has been dynamically allocated, it has to be
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 * freed separately.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 * @param array the array to destroy
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 void ucx_array_destroy(UcxArray *array);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 * Destroys and frees the array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 * @param array the array to free
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 void ucx_array_free(UcxArray *array);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 * Inserts elements at the end of the array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 * This is an O(1) operation.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 * The array will automatically grow, if the capacity is exceeded.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 * If a pointer to data is provided, the data is copied into the array with
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 * memcpy(). Otherwise the new elements are completely zeroed.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 * @param array a pointer the array where to append the data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 * @param data a pointer to the data to insert (may be <code>NULL</code>)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 * @param count number of elements to copy from data (if data is
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 * <code>NULL</code>, zeroed elements are appended)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 * @return zero on success, non-zero if a reallocation was necessary but failed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 * @see ucx_array_set_from()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 * @see ucx_array_append()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 int ucx_array_append_from(UcxArray *array, void *data, size_t count);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 * Inserts elements at the beginning of the array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 * This is an expensive operation, because the contents must be moved.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 * If there is no particular reason to prepend data, you should use
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 * ucx_array_append_from() instead.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 * @param array a pointer the array where to prepend the data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 * @param data a pointer to the data to insert (may be <code>NULL</code>)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 * @param count number of elements to copy from data (if data is
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 * <code>NULL</code>, zeroed elements are inserted)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 * @return zero on success, non-zero if a reallocation was necessary but failed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 * @see ucx_array_append_from()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 * @see ucx_array_set_from()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 * @see ucx_array_prepend()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 int ucx_array_prepend_from(UcxArray *array, void *data, size_t count);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 * Sets elements starting at the specified index.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 * If the any index is out of bounds, the array automatically grows.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 * The pointer to the data may be NULL, in which case the elements are zeroed.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 * @param array a pointer the array where to set the data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 * @param index the index of the element to set
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 * @param data a pointer to the data to insert (may be <code>NULL</code>)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 * @param count number of elements to copy from data (if data is
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 * <code>NULL</code>, the memory in the array is zeroed)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 * @return zero on success, non-zero if a reallocation was necessary but failed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 * @see ucx_array_append_from()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 * @see ucx_array_set()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 int ucx_array_set_from(UcxArray *array, size_t index, void *data, size_t count);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 * Inserts an element at the end of the array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 * This is an O(1) operation.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 * The array will automatically grow, if the capacity is exceeded.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 * If the type of the argument has a different size than the element size of
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 * this array, the behavior is undefined.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 * @param array a pointer the array where to append the data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 * @param elem the value to insert
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 * @return zero on success, non-zero if a reallocation was necessary but failed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 * @see ucx_array_append_from()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 * @see ucx_array_set()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 #define ucx_array_append(array, elem) ucx_array_appendv(array, elem)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 * For internal use.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 * Use ucx_array_append()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 * @param array
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 * @param ...
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 * @return
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 * @see ucx_array_append()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 int ucx_array_appendv(UcxArray *array, ...);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322 * Inserts an element at the beginning of the array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324 * This is an expensive operation, because the contents must be moved.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 * If there is no particular reason to prepend data, you should use
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 * ucx_array_append() instead.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 * @param array a pointer the array where to prepend the data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 * @param elem the value to insert
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 * @return zero on success, non-zero if a reallocation was necessary but failed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 * @see ucx_array_append()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 * @see ucx_array_set_from()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 * @see ucx_array_prepend_from()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 #define ucx_array_prepend(array, elem) ucx_array_prependv(array, elem)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 * For internal use.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 * Use ucx_array_prepend()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 * @param array
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 * @param ...
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 * @return
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 * @see ucx_array_prepend()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 int ucx_array_prependv(UcxArray *array, ...);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 * Sets an element at the specified index.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
352 * If the any index is out of bounds, the array automatically grows.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
353 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
354 * @param array a pointer the array where to set the data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 * @param index the index of the element to set
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356 * @param elem the value to set
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357 * @return zero on success, non-zero if a reallocation was necessary but failed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358 * @see ucx_array_append()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359 * @see ucx_array_set_from()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
361 #define ucx_array_set(array, index, elem) ucx_array_setv(array, index, elem)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
362
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364 * For internal use.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
365 * Use ucx_array_set()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367 * @param array
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 * @param index
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
369 * @param ...
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370 * @return
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371 * @see ucx_array_set()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373 int ucx_array_setv(UcxArray *array, size_t index, ...);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
374
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
375 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
376 * Concatenates two arrays.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
377 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 * The contents of the second array are appended to the first array in one
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
379 * single operation. The second array is otherwise left untouched.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
381 * The first array may grow automatically. If this fails, both arrays remain
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
382 * unmodified.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
383 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
384 * @param array1 first array
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
385 * @param array2 second array
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
386 * @return zero on success, non-zero if reallocation was necessary but failed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
387 * or the element size does not match
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
388 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
389 int ucx_array_concat(UcxArray *array1, const UcxArray *array2);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
390
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
391 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392 * Returns a pointer to the array element at the specified index.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
393 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
394 * @param array the array to retrieve the element from
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
395 * @param index index of the element to return
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
396 * @return a pointer to the element at the specified index or <code>NULL</code>,
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
397 * if the index is greater than the array size
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
398 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
399 void *ucx_array_at(UcxArray const* array, size_t index);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
400
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
401 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
402 * Returns the index of an element containing the specified data.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
403 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
404 * This function uses a cmp_func() to compare the data of each list element
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
405 * with the specified data. If no cmp_func is provided, memcmp() is used.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
406 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
407 * If the array contains the data more than once, the index of the first
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
408 * occurrence is returned.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
409 * If the array does not contain the data, the size of array is returned.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
410 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
411 * @param array the array where to search for the data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
412 * @param elem the element data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
413 * @param cmpfnc the compare function
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
414 * @param data additional data for the compare function
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
415 * @return the index of the element containing the specified data or the size of
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
416 * the array, if the data is not found in this array
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
417 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
418 size_t ucx_array_find(UcxArray const *array, void *elem,
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
419 cmp_func cmpfnc, void *data);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
420
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
421 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
422 * Checks, if an array contains a specific element.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
423 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
424 * An element is found, if ucx_array_find() returns a value less than the size.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
425 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
426 * @param array the array where to search for the data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
427 * @param elem the element data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
428 * @param cmpfnc the compare function
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
429 * @param data additional data for the compare function
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
430 * @return 1, if and only if the array contains the specified element data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
431 * @see ucx_array_find()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
432 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
433 int ucx_array_contains(UcxArray const *array, void *elem,
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
434 cmp_func cmpfnc, void *data);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
435
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
436 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
437 * Sorts a UcxArray with the best available sort algorithm.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
438 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
439 * The qsort_r() function is used, if available (glibc, FreeBSD or MacOS).
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
440 * The order of arguments is automatically adjusted for the FreeBSD and MacOS
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
441 * version of qsort_r().
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
442 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
443 * If qsort_r() is not available, a merge sort algorithm is used, which is
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
444 * guaranteed to use no more additional memory than for exactly one element.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
445 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
446 * @param array the array to sort
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
447 * @param cmpfnc the function that shall be used to compare the element data
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
448 * @param data additional data for the cmp_func() or <code>NULL</code>
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
449 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
450 void ucx_array_sort(UcxArray* array, cmp_func cmpfnc, void *data);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
451
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
452 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
453 * Removes an element from the array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
454 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
455 * This is in general an expensive operation, because several elements may
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
456 * be moved. If the order of the elements is not relevant, use
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
457 * ucx_array_remove_fast() instead.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
458 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
459 * @param array pointer to the array from which the element shall be removed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
460 * @param index the index of the element to remove
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
461 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
462 void ucx_array_remove(UcxArray *array, size_t index);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
463
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
464 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
465 * Removes an element from the array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
466 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
467 * This is an O(1) operation, but does not maintain the order of the elements.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
468 * The last element in the array is moved to the location of the removed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
469 * element.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
470 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
471 * @param array pointer to the array from which the element shall be removed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
472 * @param index the index of the element to remove
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
473 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
474 void ucx_array_remove_fast(UcxArray *array, size_t index);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
475
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
476 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
477 * Shrinks the memory to exactly fit the contents.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
478 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
479 * After this operation, the capacity equals the size.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
480 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
481 * @param array a pointer to the array
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
482 * @return zero on success, non-zero if reallocation failed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
483 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
484 int ucx_array_shrink(UcxArray* array);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
485
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
486 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
487 * Sets the capacity of the array.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
488 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
489 * If the new capacity is smaller than the size of the array, the elements
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
490 * are removed and the size is adjusted accordingly.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
491 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
492 * @param array a pointer to the array
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
493 * @param capacity the new capacity
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
494 * @return zero on success, non-zero if reallocation failed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
495 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
496 int ucx_array_resize(UcxArray* array, size_t capacity);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
497
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
498 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
499 * Resizes the array only, if the capacity is insufficient.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
500 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
501 * If the requested capacity is smaller than the current capacity, this
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
502 * function does nothing.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
503 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
504 * @param array a pointer to the array
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
505 * @param capacity the guaranteed capacity
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
506 * @return zero on success, non-zero if reallocation failed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
507 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
508 int ucx_array_reserve(UcxArray* array, size_t capacity);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
509
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
510
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
511
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
512 #ifdef __cplusplus
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
513 }
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
514 #endif
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
515
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
516 #endif /* UCX_ARRAY_H */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
517

mercurial