xref: /haiku/headers/libs/zydis/Zycore/Vector.h (revision 1003e004e6c97eb60657a98928dd334e141c59ee)
1*1003e004SJérôme Duval /***************************************************************************************************
2*1003e004SJérôme Duval 
3*1003e004SJérôme Duval   Zyan Core Library (Zycore-C)
4*1003e004SJérôme Duval 
5*1003e004SJérôme Duval   Original Author : Florian Bernd
6*1003e004SJérôme Duval 
7*1003e004SJérôme Duval  * Permission is hereby granted, free of charge, to any person obtaining a copy
8*1003e004SJérôme Duval  * of this software and associated documentation files (the "Software"), to deal
9*1003e004SJérôme Duval  * in the Software without restriction, including without limitation the rights
10*1003e004SJérôme Duval  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11*1003e004SJérôme Duval  * copies of the Software, and to permit persons to whom the Software is
12*1003e004SJérôme Duval  * furnished to do so, subject to the following conditions:
13*1003e004SJérôme Duval  *
14*1003e004SJérôme Duval  * The above copyright notice and this permission notice shall be included in all
15*1003e004SJérôme Duval  * copies or substantial portions of the Software.
16*1003e004SJérôme Duval  *
17*1003e004SJérôme Duval  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18*1003e004SJérôme Duval  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19*1003e004SJérôme Duval  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20*1003e004SJérôme Duval  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21*1003e004SJérôme Duval  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22*1003e004SJérôme Duval  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23*1003e004SJérôme Duval  * SOFTWARE.
24*1003e004SJérôme Duval 
25*1003e004SJérôme Duval ***************************************************************************************************/
26*1003e004SJérôme Duval 
27*1003e004SJérôme Duval /**
28*1003e004SJérôme Duval  * @file
29*1003e004SJérôme Duval  * Implements the vector container class.
30*1003e004SJérôme Duval  */
31*1003e004SJérôme Duval 
32*1003e004SJérôme Duval #ifndef ZYCORE_VECTOR_H
33*1003e004SJérôme Duval #define ZYCORE_VECTOR_H
34*1003e004SJérôme Duval 
35*1003e004SJérôme Duval #include <Zycore/Allocator.h>
36*1003e004SJérôme Duval #include <Zycore/Comparison.h>
37*1003e004SJérôme Duval #include <Zycore/Object.h>
38*1003e004SJérôme Duval #include <Zycore/Status.h>
39*1003e004SJérôme Duval #include <Zycore/Types.h>
40*1003e004SJérôme Duval 
41*1003e004SJérôme Duval #ifdef __cplusplus
42*1003e004SJérôme Duval extern "C" {
43*1003e004SJérôme Duval #endif
44*1003e004SJérôme Duval 
45*1003e004SJérôme Duval /* ============================================================================================== */
46*1003e004SJérôme Duval /* Constants                                                                                      */
47*1003e004SJérôme Duval /* ============================================================================================== */
48*1003e004SJérôme Duval 
49*1003e004SJérôme Duval /**
50*1003e004SJérôme Duval  * The initial minimum capacity (number of elements) for all dynamically allocated vector
51*1003e004SJérôme Duval  * instances.
52*1003e004SJérôme Duval  */
53*1003e004SJérôme Duval #define ZYAN_VECTOR_MIN_CAPACITY                1
54*1003e004SJérôme Duval 
55*1003e004SJérôme Duval /**
56*1003e004SJérôme Duval  * The default growth factor for all vector instances.
57*1003e004SJérôme Duval  */
58*1003e004SJérôme Duval #define ZYAN_VECTOR_DEFAULT_GROWTH_FACTOR       2
59*1003e004SJérôme Duval 
60*1003e004SJérôme Duval /**
61*1003e004SJérôme Duval  * The default shrink threshold for all vector instances.
62*1003e004SJérôme Duval  */
63*1003e004SJérôme Duval #define ZYAN_VECTOR_DEFAULT_SHRINK_THRESHOLD    4
64*1003e004SJérôme Duval 
65*1003e004SJérôme Duval /* ============================================================================================== */
66*1003e004SJérôme Duval /* Enums and types                                                                                */
67*1003e004SJérôme Duval /* ============================================================================================== */
68*1003e004SJérôme Duval 
69*1003e004SJérôme Duval /**
70*1003e004SJérôme Duval  * Defines the `ZyanVector` struct.
71*1003e004SJérôme Duval  *
72*1003e004SJérôme Duval  * All fields in this struct should be considered as "private". Any changes may lead to unexpected
73*1003e004SJérôme Duval  * behavior.
74*1003e004SJérôme Duval  */
75*1003e004SJérôme Duval typedef struct ZyanVector_
76*1003e004SJérôme Duval {
77*1003e004SJérôme Duval     /**
78*1003e004SJérôme Duval      * The memory allocator.
79*1003e004SJérôme Duval      */
80*1003e004SJérôme Duval     ZyanAllocator* allocator;
81*1003e004SJérôme Duval     /**
82*1003e004SJérôme Duval      * The growth factor.
83*1003e004SJérôme Duval      */
84*1003e004SJérôme Duval     ZyanU8 growth_factor;
85*1003e004SJérôme Duval     /**
86*1003e004SJérôme Duval      * The shrink threshold.
87*1003e004SJérôme Duval      */
88*1003e004SJérôme Duval     ZyanU8 shrink_threshold;
89*1003e004SJérôme Duval     /**
90*1003e004SJérôme Duval      * The current number of elements in the vector.
91*1003e004SJérôme Duval      */
92*1003e004SJérôme Duval     ZyanUSize size;
93*1003e004SJérôme Duval     /**
94*1003e004SJérôme Duval      * The maximum capacity (number of elements).
95*1003e004SJérôme Duval      */
96*1003e004SJérôme Duval     ZyanUSize capacity;
97*1003e004SJérôme Duval     /**
98*1003e004SJérôme Duval      * The size of a single element in bytes.
99*1003e004SJérôme Duval      */
100*1003e004SJérôme Duval     ZyanUSize element_size;
101*1003e004SJérôme Duval     /**
102*1003e004SJérôme Duval      * The element destructor callback.
103*1003e004SJérôme Duval      */
104*1003e004SJérôme Duval     ZyanMemberProcedure destructor;
105*1003e004SJérôme Duval     /**
106*1003e004SJérôme Duval      * The data pointer.
107*1003e004SJérôme Duval      */
108*1003e004SJérôme Duval     void* data;
109*1003e004SJérôme Duval } ZyanVector;
110*1003e004SJérôme Duval 
111*1003e004SJérôme Duval /* ============================================================================================== */
112*1003e004SJérôme Duval /* Macros                                                                                         */
113*1003e004SJérôme Duval /* ============================================================================================== */
114*1003e004SJérôme Duval 
115*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
116*1003e004SJérôme Duval /* General                                                                                        */
117*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
118*1003e004SJérôme Duval 
119*1003e004SJérôme Duval /**
120*1003e004SJérôme Duval  * Defines an uninitialized `ZyanVector` instance.
121*1003e004SJérôme Duval  */
122*1003e004SJérôme Duval #define ZYAN_VECTOR_INITIALIZER \
123*1003e004SJérôme Duval     { \
124*1003e004SJérôme Duval         /* allocator        */ ZYAN_NULL, \
125*1003e004SJérôme Duval         /* growth_factor    */ 0, \
126*1003e004SJérôme Duval         /* shrink_threshold */ 0, \
127*1003e004SJérôme Duval         /* size             */ 0, \
128*1003e004SJérôme Duval         /* capacity         */ 0, \
129*1003e004SJérôme Duval         /* element_size     */ 0, \
130*1003e004SJérôme Duval         /* destructor       */ ZYAN_NULL, \
131*1003e004SJérôme Duval         /* data             */ ZYAN_NULL \
132*1003e004SJérôme Duval     }
133*1003e004SJérôme Duval 
134*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
135*1003e004SJérôme Duval /* Helper macros                                                                                  */
136*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
137*1003e004SJérôme Duval 
138*1003e004SJérôme Duval /**
139*1003e004SJérôme Duval  * Returns the value of the element at the given `index`.
140*1003e004SJérôme Duval  *
141*1003e004SJérôme Duval  * @param   type    The desired value type.
142*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance.
143*1003e004SJérôme Duval  * @param   index   The element index.
144*1003e004SJérôme Duval  *
145*1003e004SJérôme Duval  * @result  The value of the desired element in the vector.
146*1003e004SJérôme Duval  *
147*1003e004SJérôme Duval  * Note that this function is unsafe and might dereference a null-pointer.
148*1003e004SJérôme Duval  */
149*1003e004SJérôme Duval #ifdef __cplusplus
150*1003e004SJérôme Duval #define ZYAN_VECTOR_GET(type, vector, index) \
151*1003e004SJérôme Duval     (*reinterpret_cast<const type*>(ZyanVectorGet(vector, index)))
152*1003e004SJérôme Duval #else
153*1003e004SJérôme Duval #define ZYAN_VECTOR_GET(type, vector, index) \
154*1003e004SJérôme Duval     (*(const type*)ZyanVectorGet(vector, index))
155*1003e004SJérôme Duval #endif
156*1003e004SJérôme Duval 
157*1003e004SJérôme Duval /**
158*1003e004SJérôme Duval  * Loops through all elements of the vector.
159*1003e004SJérôme Duval  *
160*1003e004SJérôme Duval  * @param   type        The desired value type.
161*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
162*1003e004SJérôme Duval  * @param   item_name   The name of the iterator item.
163*1003e004SJérôme Duval  * @param   body        The body to execute for each item in the vector.
164*1003e004SJérôme Duval  */
165*1003e004SJérôme Duval #define ZYAN_VECTOR_FOREACH(type, vector, item_name, body) \
166*1003e004SJérôme Duval     { \
167*1003e004SJérôme Duval         const ZyanUSize ZYAN_MACRO_CONCAT_EXPAND(size_d50d3303, item_name) = (vector)->size; \
168*1003e004SJérôme Duval         for (ZyanUSize ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name) = 0; \
169*1003e004SJérôme Duval             ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name) < \
170*1003e004SJérôme Duval             ZYAN_MACRO_CONCAT_EXPAND(size_d50d3303, item_name); \
171*1003e004SJérôme Duval             ++ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name)) \
172*1003e004SJérôme Duval         { \
173*1003e004SJérôme Duval             const type item_name = ZYAN_VECTOR_GET(type, vector, \
174*1003e004SJérôme Duval                 ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name)); \
175*1003e004SJérôme Duval             body \
176*1003e004SJérôme Duval         } \
177*1003e004SJérôme Duval     }
178*1003e004SJérôme Duval 
179*1003e004SJérôme Duval /**
180*1003e004SJérôme Duval  * Loops through all elements of the vector.
181*1003e004SJérôme Duval  *
182*1003e004SJérôme Duval  * @param   type        The desired value type.
183*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
184*1003e004SJérôme Duval  * @param   item_name   The name of the iterator item.
185*1003e004SJérôme Duval  * @param   body        The body to execute for each item in the vector.
186*1003e004SJérôme Duval  */
187*1003e004SJérôme Duval #define ZYAN_VECTOR_FOREACH_MUTABLE(type, vector, item_name, body) \
188*1003e004SJérôme Duval     { \
189*1003e004SJérôme Duval         const ZyanUSize ZYAN_MACRO_CONCAT_EXPAND(size_d50d3303, item_name) = (vector)->size; \
190*1003e004SJérôme Duval         for (ZyanUSize ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name) = 0; \
191*1003e004SJérôme Duval             ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name) < \
192*1003e004SJérôme Duval             ZYAN_MACRO_CONCAT_EXPAND(size_d50d3303, item_name); \
193*1003e004SJérôme Duval             ++ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name)) \
194*1003e004SJérôme Duval         { \
195*1003e004SJérôme Duval             type* const item_name = ZyanVectorGetMutable(vector, \
196*1003e004SJérôme Duval                 ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name)); \
197*1003e004SJérôme Duval             body \
198*1003e004SJérôme Duval         } \
199*1003e004SJérôme Duval     }
200*1003e004SJérôme Duval 
201*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
202*1003e004SJérôme Duval 
203*1003e004SJérôme Duval /* ============================================================================================== */
204*1003e004SJérôme Duval /* Exported functions                                                                             */
205*1003e004SJérôme Duval /* ============================================================================================== */
206*1003e004SJérôme Duval 
207*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
208*1003e004SJérôme Duval /* Constructor and destructor                                                                     */
209*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
210*1003e004SJérôme Duval 
211*1003e004SJérôme Duval #ifndef ZYAN_NO_LIBC
212*1003e004SJérôme Duval 
213*1003e004SJérôme Duval /**
214*1003e004SJérôme Duval  * Initializes the given `ZyanVector` instance.
215*1003e004SJérôme Duval  *
216*1003e004SJérôme Duval  * @param   vector          A pointer to the `ZyanVector` instance.
217*1003e004SJérôme Duval  * @param   element_size    The size of a single element in bytes.
218*1003e004SJérôme Duval  * @param   capacity        The initial capacity (number of elements).
219*1003e004SJérôme Duval  * @param   destructor      A destructor callback that is invoked every time an item is deleted, or
220*1003e004SJérôme Duval  *                          `ZYAN_NULL` if not needed.
221*1003e004SJérôme Duval  *
222*1003e004SJérôme Duval  * @return  A zyan status code.
223*1003e004SJérôme Duval  *
224*1003e004SJérôme Duval  * The memory for the vector elements is dynamically allocated by the default allocator using the
225*1003e004SJérôme Duval  * default growth factor and the default shrink threshold.
226*1003e004SJérôme Duval  *
227*1003e004SJérôme Duval  * Finalization with `ZyanVectorDestroy` is required for all instances created by this function.
228*1003e004SJérôme Duval  */
229*1003e004SJérôme Duval ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanVectorInit(ZyanVector* vector,
230*1003e004SJérôme Duval     ZyanUSize element_size, ZyanUSize capacity, ZyanMemberProcedure destructor);
231*1003e004SJérôme Duval 
232*1003e004SJérôme Duval #endif // ZYAN_NO_LIBC
233*1003e004SJérôme Duval 
234*1003e004SJérôme Duval /**
235*1003e004SJérôme Duval  * Initializes the given `ZyanVector` instance and sets a custom `allocator` and memory
236*1003e004SJérôme Duval  * allocation/deallocation parameters.
237*1003e004SJérôme Duval  *
238*1003e004SJérôme Duval  * @param   vector              A pointer to the `ZyanVector` instance.
239*1003e004SJérôme Duval  * @param   element_size        The size of a single element in bytes.
240*1003e004SJérôme Duval  * @param   capacity            The initial capacity (number of elements).
241*1003e004SJérôme Duval  * @param   destructor          A destructor callback that is invoked every time an item is deleted,
242*1003e004SJérôme Duval  *                              or `ZYAN_NULL` if not needed.
243*1003e004SJérôme Duval  * @param   allocator           A pointer to a `ZyanAllocator` instance.
244*1003e004SJérôme Duval  * @param   growth_factor       The growth factor.
245*1003e004SJérôme Duval  * @param   shrink_threshold    The shrink threshold.
246*1003e004SJérôme Duval  *
247*1003e004SJérôme Duval  * @return  A zyan status code.
248*1003e004SJérôme Duval  *
249*1003e004SJérôme Duval  * A growth factor of `1` disables overallocation and a shrink threshold of `0` disables
250*1003e004SJérôme Duval  * dynamic shrinking.
251*1003e004SJérôme Duval  *
252*1003e004SJérôme Duval  * Finalization with `ZyanVectorDestroy` is required for all instances created by this function.
253*1003e004SJérôme Duval  */
254*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorInitEx(ZyanVector* vector, ZyanUSize element_size,
255*1003e004SJérôme Duval     ZyanUSize capacity, ZyanMemberProcedure destructor, ZyanAllocator* allocator,
256*1003e004SJérôme Duval     ZyanU8 growth_factor, ZyanU8 shrink_threshold);
257*1003e004SJérôme Duval 
258*1003e004SJérôme Duval /**
259*1003e004SJérôme Duval  * Initializes the given `ZyanVector` instance and configures it to use a custom user
260*1003e004SJérôme Duval  * defined buffer with a fixed size.
261*1003e004SJérôme Duval  *
262*1003e004SJérôme Duval  * @param   vector          A pointer to the `ZyanVector` instance.
263*1003e004SJérôme Duval  * @param   element_size    The size of a single element in bytes.
264*1003e004SJérôme Duval  * @param   buffer          A pointer to the buffer that is used as storage for the elements.
265*1003e004SJérôme Duval  * @param   capacity        The maximum capacity (number of elements) of the buffer.
266*1003e004SJérôme Duval  * @param   destructor      A destructor callback that is invoked every time an item is deleted, or
267*1003e004SJérôme Duval  *                          `ZYAN_NULL` if not needed.
268*1003e004SJérôme Duval  *
269*1003e004SJérôme Duval  * @return  A zyan status code.
270*1003e004SJérôme Duval  *
271*1003e004SJérôme Duval  * Finalization is not required for instances created by this function.
272*1003e004SJérôme Duval  */
273*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorInitCustomBuffer(ZyanVector* vector, ZyanUSize element_size,
274*1003e004SJérôme Duval     void* buffer, ZyanUSize capacity, ZyanMemberProcedure destructor);
275*1003e004SJérôme Duval 
276*1003e004SJérôme Duval /**
277*1003e004SJérôme Duval  * Destroys the given `ZyanVector` instance.
278*1003e004SJérôme Duval  *
279*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance..
280*1003e004SJérôme Duval  *
281*1003e004SJérôme Duval  * @return  A zyan status code.
282*1003e004SJérôme Duval  */
283*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorDestroy(ZyanVector* vector);
284*1003e004SJérôme Duval 
285*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
286*1003e004SJérôme Duval /* Duplication                                                                                    */
287*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
288*1003e004SJérôme Duval 
289*1003e004SJérôme Duval #ifndef ZYAN_NO_LIBC
290*1003e004SJérôme Duval 
291*1003e004SJérôme Duval /**
292*1003e004SJérôme Duval  * Initializes a new `ZyanVector` instance by duplicating an existing vector.
293*1003e004SJérôme Duval  *
294*1003e004SJérôme Duval  * @param   destination A pointer to the (uninitialized) destination `ZyanVector` instance.
295*1003e004SJérôme Duval  * @param   source      A pointer to the source vector.
296*1003e004SJérôme Duval  * @param   capacity    The initial capacity (number of elements).
297*1003e004SJérôme Duval  *
298*1003e004SJérôme Duval  *                      This value is automatically adjusted to the size of the source vector, if
299*1003e004SJérôme Duval  *                      a smaller value was passed.
300*1003e004SJérôme Duval  *
301*1003e004SJérôme Duval  * @return  A zyan status code.
302*1003e004SJérôme Duval  *
303*1003e004SJérôme Duval  * The memory for the vector is dynamically allocated by the default allocator using the default
304*1003e004SJérôme Duval  * growth factor and the default shrink threshold.
305*1003e004SJérôme Duval  *
306*1003e004SJérôme Duval  * Finalization with `ZyanVectorDestroy` is required for all instances created by this function.
307*1003e004SJérôme Duval  */
308*1003e004SJérôme Duval ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanVectorDuplicate(ZyanVector* destination,
309*1003e004SJérôme Duval     const ZyanVector* source, ZyanUSize capacity);
310*1003e004SJérôme Duval 
311*1003e004SJérôme Duval #endif // ZYAN_NO_LIBC
312*1003e004SJérôme Duval 
313*1003e004SJérôme Duval /**
314*1003e004SJérôme Duval  * Initializes a new `ZyanVector` instance by duplicating an existing vector and sets a
315*1003e004SJérôme Duval  * custom `allocator` and memory allocation/deallocation parameters.
316*1003e004SJérôme Duval  *
317*1003e004SJérôme Duval  * @param   destination         A pointer to the (uninitialized) destination `ZyanVector` instance.
318*1003e004SJérôme Duval  * @param   source              A pointer to the source vector.
319*1003e004SJérôme Duval  * @param   capacity            The initial capacity (number of elements).
320*1003e004SJérôme Duval 
321*1003e004SJérôme Duval  *                              This value is automatically adjusted to the size of the source
322*1003e004SJérôme Duval  *                              vector, if a smaller value was passed.
323*1003e004SJérôme Duval  * @param   allocator           A pointer to a `ZyanAllocator` instance.
324*1003e004SJérôme Duval  * @param   growth_factor       The growth factor.
325*1003e004SJérôme Duval  * @param   shrink_threshold    The shrink threshold.
326*1003e004SJérôme Duval  *
327*1003e004SJérôme Duval  * @return  A zyan status code.
328*1003e004SJérôme Duval  *
329*1003e004SJérôme Duval  * A growth factor of `1` disables overallocation and a shrink threshold of `0` disables
330*1003e004SJérôme Duval  * dynamic shrinking.
331*1003e004SJérôme Duval  *
332*1003e004SJérôme Duval  * Finalization with `ZyanVectorDestroy` is required for all instances created by this function.
333*1003e004SJérôme Duval  */
334*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorDuplicateEx(ZyanVector* destination, const ZyanVector* source,
335*1003e004SJérôme Duval     ZyanUSize capacity, ZyanAllocator* allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold);
336*1003e004SJérôme Duval 
337*1003e004SJérôme Duval /**
338*1003e004SJérôme Duval  * Initializes a new `ZyanVector` instance by duplicating an existing vector and
339*1003e004SJérôme Duval  * configures it to use a custom user defined buffer with a fixed size.
340*1003e004SJérôme Duval  *
341*1003e004SJérôme Duval  * @param   destination A pointer to the (uninitialized) destination `ZyanVector` instance.
342*1003e004SJérôme Duval  * @param   source      A pointer to the source vector.
343*1003e004SJérôme Duval  * @param   buffer      A pointer to the buffer that is used as storage for the elements.
344*1003e004SJérôme Duval  * @param   capacity    The maximum capacity (number of elements) of the buffer.
345*1003e004SJérôme Duval 
346*1003e004SJérôme Duval  *                      This function will fail, if the capacity of the buffer is less than the
347*1003e004SJérôme Duval  *                      size of the source vector.
348*1003e004SJérôme Duval  *
349*1003e004SJérôme Duval  * @return  A zyan status code.
350*1003e004SJérôme Duval  *
351*1003e004SJérôme Duval  * Finalization is not required for instances created by this function.
352*1003e004SJérôme Duval  */
353*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorDuplicateCustomBuffer(ZyanVector* destination,
354*1003e004SJérôme Duval     const ZyanVector* source, void* buffer, ZyanUSize capacity);
355*1003e004SJérôme Duval 
356*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
357*1003e004SJérôme Duval /* Element access                                                                                 */
358*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
359*1003e004SJérôme Duval 
360*1003e004SJérôme Duval /**
361*1003e004SJérôme Duval  * Returns a constant pointer to the element at the given `index`.
362*1003e004SJérôme Duval  *
363*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
364*1003e004SJérôme Duval  * @param   index       The element index.
365*1003e004SJérôme Duval  *
366*1003e004SJérôme Duval  * @return  A constant pointer to the desired element in the vector or `ZYAN_NULL`, if an error
367*1003e004SJérôme Duval  *          occurred.
368*1003e004SJérôme Duval  *
369*1003e004SJérôme Duval  * Note that the returned pointer might get invalid when the vector is resized by either a manual
370*1003e004SJérôme Duval  * call to the memory-management functions or implicitly by inserting or removing elements.
371*1003e004SJérôme Duval  *
372*1003e004SJérôme Duval  * Take a look at `ZyanVectorGetPointer` instead, if you need a function that returns a zyan status
373*1003e004SJérôme Duval  * code.
374*1003e004SJérôme Duval  */
375*1003e004SJérôme Duval ZYCORE_EXPORT const void* ZyanVectorGet(const ZyanVector* vector, ZyanUSize index);
376*1003e004SJérôme Duval 
377*1003e004SJérôme Duval /**
378*1003e004SJérôme Duval  * Returns a mutable pointer to the element at the given `index`.
379*1003e004SJérôme Duval  *
380*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
381*1003e004SJérôme Duval  * @param   index       The element index.
382*1003e004SJérôme Duval  *
383*1003e004SJérôme Duval  * @return  A mutable pointer to the desired element in the vector or `ZYAN_NULL`, if an error
384*1003e004SJérôme Duval  *          occurred.
385*1003e004SJérôme Duval  *
386*1003e004SJérôme Duval  * Note that the returned pointer might get invalid when the vector is resized by either a manual
387*1003e004SJérôme Duval  * call to the memory-management functions or implicitly by inserting or removing elements.
388*1003e004SJérôme Duval  *
389*1003e004SJérôme Duval  * Take a look at `ZyanVectorGetPointerMutable` instead, if you need a function that returns a
390*1003e004SJérôme Duval  * zyan status code.
391*1003e004SJérôme Duval  */
392*1003e004SJérôme Duval ZYCORE_EXPORT void* ZyanVectorGetMutable(const ZyanVector* vector, ZyanUSize index);
393*1003e004SJérôme Duval 
394*1003e004SJérôme Duval /**
395*1003e004SJérôme Duval  * Returns a constant pointer to the element at the given `index`.
396*1003e004SJérôme Duval  *
397*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance.
398*1003e004SJérôme Duval  * @param   index   The element index.
399*1003e004SJérôme Duval  * @param   value   Receives a constant pointer to the desired element in the vector.
400*1003e004SJérôme Duval  *
401*1003e004SJérôme Duval  * Note that the returned pointer might get invalid when the vector is resized by either a manual
402*1003e004SJérôme Duval  * call to the memory-management functions or implicitly by inserting or removing elements.
403*1003e004SJérôme Duval  *
404*1003e004SJérôme Duval  * @return  A zyan status code.
405*1003e004SJérôme Duval  */
406*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorGetPointer(const ZyanVector* vector, ZyanUSize index,
407*1003e004SJérôme Duval     const void** value);
408*1003e004SJérôme Duval 
409*1003e004SJérôme Duval /**
410*1003e004SJérôme Duval  * Returns a mutable pointer to the element at the given `index`.
411*1003e004SJérôme Duval  *
412*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance.
413*1003e004SJérôme Duval  * @param   index   The element index.
414*1003e004SJérôme Duval  * @param   value Receives a mutable pointer to the desired element in the vector.
415*1003e004SJérôme Duval  *
416*1003e004SJérôme Duval  * Note that the returned pointer might get invalid when the vector is resized by either a manual
417*1003e004SJérôme Duval  * call to the memory-management functions or implicitly by inserting or removing elements.
418*1003e004SJérôme Duval  *
419*1003e004SJérôme Duval  * @return  A zyan status code.
420*1003e004SJérôme Duval  */
421*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorGetPointerMutable(const ZyanVector* vector, ZyanUSize index,
422*1003e004SJérôme Duval     void** value);
423*1003e004SJérôme Duval 
424*1003e004SJérôme Duval /**
425*1003e004SJérôme Duval  * Assigns a new value to the element at the given `index`.
426*1003e004SJérôme Duval  *
427*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance.
428*1003e004SJérôme Duval  * @param   index   The value index.
429*1003e004SJérôme Duval  * @param   value   The value to assign.
430*1003e004SJérôme Duval  *
431*1003e004SJérôme Duval  * @return  A zyan status code.
432*1003e004SJérôme Duval  */
433*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorSet(ZyanVector* vector, ZyanUSize index,
434*1003e004SJérôme Duval     const void* value);
435*1003e004SJérôme Duval 
436*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
437*1003e004SJérôme Duval /* Insertion                                                                                      */
438*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
439*1003e004SJérôme Duval 
440*1003e004SJérôme Duval /**
441*1003e004SJérôme Duval  * Adds a new `element` to the end of the vector.
442*1003e004SJérôme Duval  *
443*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance.
444*1003e004SJérôme Duval  * @param   element A pointer to the element to add.
445*1003e004SJérôme Duval  *
446*1003e004SJérôme Duval  * @return  A zyan status code.
447*1003e004SJérôme Duval  */
448*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorPushBack(ZyanVector* vector, const void* element);
449*1003e004SJérôme Duval 
450*1003e004SJérôme Duval /**
451*1003e004SJérôme Duval  * Inserts an `element` at the given `index` of the vector.
452*1003e004SJérôme Duval  *
453*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance.
454*1003e004SJérôme Duval  * @param   index   The insert index.
455*1003e004SJérôme Duval  * @param   element A pointer to the element to insert.
456*1003e004SJérôme Duval  *
457*1003e004SJérôme Duval  * @return  A zyan status code.
458*1003e004SJérôme Duval  */
459*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorInsert(ZyanVector* vector, ZyanUSize index,
460*1003e004SJérôme Duval     const void* element);
461*1003e004SJérôme Duval 
462*1003e004SJérôme Duval /**
463*1003e004SJérôme Duval  * Inserts multiple `elements` at the given `index` of the vector.
464*1003e004SJérôme Duval  *
465*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
466*1003e004SJérôme Duval  * @param   index       The insert index.
467*1003e004SJérôme Duval  * @param   elements    A pointer to the first element.
468*1003e004SJérôme Duval  * @param   count       The number of elements to insert.
469*1003e004SJérôme Duval  *
470*1003e004SJérôme Duval  * @return  A zyan status code.
471*1003e004SJérôme Duval  */
472*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorInsertRange(ZyanVector* vector, ZyanUSize index,
473*1003e004SJérôme Duval     const void* elements, ZyanUSize count);
474*1003e004SJérôme Duval 
475*1003e004SJérôme Duval /**
476*1003e004SJérôme Duval  * Constructs an `element` in-place at the end of the vector.
477*1003e004SJérôme Duval  *
478*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
479*1003e004SJérôme Duval  * @param   element     Receives a pointer to the new element.
480*1003e004SJérôme Duval  * @param   constructor The constructor callback or `ZYAN_NULL`. The new element will be in
481*1003e004SJérôme Duval  *                      undefined state, if no constructor was passed.
482*1003e004SJérôme Duval  *
483*1003e004SJérôme Duval  * @return  A zyan status code.
484*1003e004SJérôme Duval  */
485*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorEmplace(ZyanVector* vector, void** element,
486*1003e004SJérôme Duval     ZyanMemberFunction constructor);
487*1003e004SJérôme Duval 
488*1003e004SJérôme Duval /**
489*1003e004SJérôme Duval  * Constructs an `element` in-place and inserts it at the given `index` of the vector.
490*1003e004SJérôme Duval  *
491*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
492*1003e004SJérôme Duval  * @param   index       The insert index.
493*1003e004SJérôme Duval  * @param   element     Receives a pointer to the new element.
494*1003e004SJérôme Duval  * @param   constructor The constructor callback or `ZYAN_NULL`. The new element will be in
495*1003e004SJérôme Duval  *                      undefined state, if no constructor was passed.
496*1003e004SJérôme Duval  *
497*1003e004SJérôme Duval  * @return  A zyan status code.
498*1003e004SJérôme Duval  */
499*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorEmplaceEx(ZyanVector* vector, ZyanUSize index,
500*1003e004SJérôme Duval     void** element, ZyanMemberFunction constructor);
501*1003e004SJérôme Duval 
502*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
503*1003e004SJérôme Duval /* Utils                                                                                          */
504*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
505*1003e004SJérôme Duval 
506*1003e004SJérôme Duval /**
507*1003e004SJérôme Duval  * Swaps the element at `index_first` with the element at `index_second`.
508*1003e004SJérôme Duval  *
509*1003e004SJérôme Duval  * @param   vector          A pointer to the `ZyanVector` instance.
510*1003e004SJérôme Duval  * @param   index_first     The index of the first element.
511*1003e004SJérôme Duval  * @param   index_second    The index of the second element.
512*1003e004SJérôme Duval  *
513*1003e004SJérôme Duval  * @return  A zyan status code.
514*1003e004SJérôme Duval  *
515*1003e004SJérôme Duval  * This function requires the vector to have spare capacity for one temporary element. Call
516*1003e004SJérôme Duval  * `ZyanVectorReserve` before this function to increase capacity, if needed.
517*1003e004SJérôme Duval  */
518*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorSwapElements(ZyanVector* vector, ZyanUSize index_first,
519*1003e004SJérôme Duval     ZyanUSize index_second);
520*1003e004SJérôme Duval 
521*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
522*1003e004SJérôme Duval /* Deletion                                                                                       */
523*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
524*1003e004SJérôme Duval 
525*1003e004SJérôme Duval /**
526*1003e004SJérôme Duval  * Deletes the element at the given `index` of the vector.
527*1003e004SJérôme Duval  *
528*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance.
529*1003e004SJérôme Duval  * @param   index   The element index.
530*1003e004SJérôme Duval  *
531*1003e004SJérôme Duval  * @return  A zyan status code.
532*1003e004SJérôme Duval  */
533*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorDelete(ZyanVector* vector, ZyanUSize index);
534*1003e004SJérôme Duval 
535*1003e004SJérôme Duval /**
536*1003e004SJérôme Duval  * Deletes multiple elements from the given vector, starting at `index`.
537*1003e004SJérôme Duval  *
538*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance.
539*1003e004SJérôme Duval  * @param   index   The index of the first element to delete.
540*1003e004SJérôme Duval  * @param   count   The number of elements to delete.
541*1003e004SJérôme Duval  *
542*1003e004SJérôme Duval  * @return  A zyan status code.
543*1003e004SJérôme Duval  */
544*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorDeleteRange(ZyanVector* vector, ZyanUSize index,
545*1003e004SJérôme Duval     ZyanUSize count);
546*1003e004SJérôme Duval 
547*1003e004SJérôme Duval /**
548*1003e004SJérôme Duval  * Removes the last element of the vector.
549*1003e004SJérôme Duval  *
550*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance.
551*1003e004SJérôme Duval  *
552*1003e004SJérôme Duval  * @return  A zyan status code.
553*1003e004SJérôme Duval  */
554*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorPopBack(ZyanVector* vector);
555*1003e004SJérôme Duval 
556*1003e004SJérôme Duval /**
557*1003e004SJérôme Duval  * Erases all elements of the given vector.
558*1003e004SJérôme Duval  *
559*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance.
560*1003e004SJérôme Duval  *
561*1003e004SJérôme Duval  * @return  A zyan status code.
562*1003e004SJérôme Duval  */
563*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorClear(ZyanVector* vector);
564*1003e004SJérôme Duval 
565*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
566*1003e004SJérôme Duval /* Searching                                                                                      */
567*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
568*1003e004SJérôme Duval 
569*1003e004SJérôme Duval /**
570*1003e004SJérôme Duval  * Sequentially searches for the first occurrence of `element` in the given vector.
571*1003e004SJérôme Duval  *
572*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
573*1003e004SJérôme Duval  * @param   element     A pointer to the element to search for.
574*1003e004SJérôme Duval  * @param   found_index A pointer to a variable that receives the index of the found element.
575*1003e004SJérôme Duval  * @param   comparison  The comparison function to use.
576*1003e004SJérôme Duval  *
577*1003e004SJérôme Duval  * @return  `ZYAN_STATUS_TRUE` if the element was found, `ZYAN_STATUS_FALSE` if not or a generic
578*1003e004SJérôme Duval  *          zyan status code if an error occurred.
579*1003e004SJérôme Duval  *
580*1003e004SJérôme Duval  * The `found_index` is set to `-1`, if the element was not found.
581*1003e004SJérôme Duval  */
582*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorFind(const ZyanVector* vector, const void* element,
583*1003e004SJérôme Duval     ZyanISize* found_index, ZyanEqualityComparison comparison);
584*1003e004SJérôme Duval 
585*1003e004SJérôme Duval /**
586*1003e004SJérôme Duval  * Sequentially searches for the first occurrence of `element` in the given vector.
587*1003e004SJérôme Duval  *
588*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
589*1003e004SJérôme Duval  * @param   element     A pointer to the element to search for.
590*1003e004SJérôme Duval  * @param   found_index A pointer to a variable that receives the index of the found element.
591*1003e004SJérôme Duval  * @param   comparison  The comparison function to use.
592*1003e004SJérôme Duval  * @param   index       The start index.
593*1003e004SJérôme Duval  * @param   count       The maximum number of elements to iterate, beginning from the start `index`.
594*1003e004SJérôme Duval  *
595*1003e004SJérôme Duval  * @return  `ZYAN_STATUS_TRUE` if the element was found, `ZYAN_STATUS_FALSE` if not or a generic
596*1003e004SJérôme Duval  *          zyan status code if an error occurred.
597*1003e004SJérôme Duval  *
598*1003e004SJérôme Duval  * The `found_index` is set to `-1`, if the element was not found.
599*1003e004SJérôme Duval  */
600*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorFindEx(const ZyanVector* vector, const void* element,
601*1003e004SJérôme Duval     ZyanISize* found_index, ZyanEqualityComparison comparison, ZyanUSize index, ZyanUSize count);
602*1003e004SJérôme Duval 
603*1003e004SJérôme Duval /**
604*1003e004SJérôme Duval  * Searches for the first occurrence of `element` in the given vector using a binary-
605*1003e004SJérôme Duval  * search algorithm.
606*1003e004SJérôme Duval  *
607*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
608*1003e004SJérôme Duval  * @param   element     A pointer to the element to search for.
609*1003e004SJérôme Duval  * @param   found_index A pointer to a variable that receives the index of the found element.
610*1003e004SJérôme Duval  * @param   comparison  The comparison function to use.
611*1003e004SJérôme Duval  *
612*1003e004SJérôme Duval  * @return  `ZYAN_STATUS_TRUE` if the element was found, `ZYAN_STATUS_FALSE` if not or a generic
613*1003e004SJérôme Duval  *          zyan status code if an error occurred.
614*1003e004SJérôme Duval  *
615*1003e004SJérôme Duval  * If found, `found_index` contains the zero-based index of `element`. If not found, `found_index`
616*1003e004SJérôme Duval  * contains the index of the first entry larger than `element`.
617*1003e004SJérôme Duval  *
618*1003e004SJérôme Duval  * This function requires all elements in the vector to be strictly ordered (sorted).
619*1003e004SJérôme Duval  */
620*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorBinarySearch(const ZyanVector* vector, const void* element,
621*1003e004SJérôme Duval     ZyanUSize* found_index, ZyanComparison comparison);
622*1003e004SJérôme Duval 
623*1003e004SJérôme Duval /**
624*1003e004SJérôme Duval  * Searches for the first occurrence of `element` in the given vector using a binary-
625*1003e004SJérôme Duval  * search algorithm.
626*1003e004SJérôme Duval  *
627*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
628*1003e004SJérôme Duval  * @param   element     A pointer to the element to search for.
629*1003e004SJérôme Duval  * @param   found_index A pointer to a variable that receives the index of the found element.
630*1003e004SJérôme Duval  * @param   comparison  The comparison function to use.
631*1003e004SJérôme Duval  * @param   index       The start index.
632*1003e004SJérôme Duval  * @param   count       The maximum number of elements to iterate, beginning from the start `index`.
633*1003e004SJérôme Duval  *
634*1003e004SJérôme Duval  * @return  `ZYAN_STATUS_TRUE` if the element was found, `ZYAN_STATUS_FALSE` if not or a generic
635*1003e004SJérôme Duval  *          zyan status code if an error occurred.
636*1003e004SJérôme Duval  *
637*1003e004SJérôme Duval  * If found, `found_index` contains the zero-based index of `element`. If not found, `found_index`
638*1003e004SJérôme Duval  * contains the index of the first entry larger than `element`.
639*1003e004SJérôme Duval  *
640*1003e004SJérôme Duval  * This function requires all elements in the vector to be strictly ordered (sorted).
641*1003e004SJérôme Duval  */
642*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorBinarySearchEx(const ZyanVector* vector, const void* element,
643*1003e004SJérôme Duval     ZyanUSize* found_index, ZyanComparison comparison, ZyanUSize index, ZyanUSize count);
644*1003e004SJérôme Duval 
645*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
646*1003e004SJérôme Duval /* Memory management                                                                              */
647*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
648*1003e004SJérôme Duval 
649*1003e004SJérôme Duval /**
650*1003e004SJérôme Duval  * Resizes the given `ZyanVector` instance.
651*1003e004SJérôme Duval  *
652*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance.
653*1003e004SJérôme Duval  * @param   size    The new size of the vector.
654*1003e004SJérôme Duval  *
655*1003e004SJérôme Duval  * @return  A zyan status code.
656*1003e004SJérôme Duval  */
657*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorResize(ZyanVector* vector, ZyanUSize size);
658*1003e004SJérôme Duval 
659*1003e004SJérôme Duval /**
660*1003e004SJérôme Duval  * Resizes the given `ZyanVector` instance.
661*1003e004SJérôme Duval  *
662*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
663*1003e004SJérôme Duval  * @param   size        The new size of the vector.
664*1003e004SJérôme Duval  * @param   initializer A pointer to a value to be used as initializer for new items.
665*1003e004SJérôme Duval  *
666*1003e004SJérôme Duval  * @return  A zyan status code.
667*1003e004SJérôme Duval  */
668*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorResizeEx(ZyanVector* vector, ZyanUSize size,
669*1003e004SJérôme Duval     const void* initializer);
670*1003e004SJérôme Duval 
671*1003e004SJérôme Duval /**
672*1003e004SJérôme Duval  * Changes the capacity of the given `ZyanVector` instance.
673*1003e004SJérôme Duval  *
674*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
675*1003e004SJérôme Duval  * @param   capacity    The new minimum capacity of the vector.
676*1003e004SJérôme Duval  *
677*1003e004SJérôme Duval  * @return  A zyan status code.
678*1003e004SJérôme Duval  */
679*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorReserve(ZyanVector* vector, ZyanUSize capacity);
680*1003e004SJérôme Duval 
681*1003e004SJérôme Duval /**
682*1003e004SJérôme Duval  * Shrinks the capacity of the given vector to match it's size.
683*1003e004SJérôme Duval  *
684*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance.
685*1003e004SJérôme Duval  *
686*1003e004SJérôme Duval  * @return  A zyan status code.
687*1003e004SJérôme Duval  */
688*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorShrinkToFit(ZyanVector* vector);
689*1003e004SJérôme Duval 
690*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
691*1003e004SJérôme Duval /* Information                                                                                    */
692*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
693*1003e004SJérôme Duval 
694*1003e004SJérôme Duval /**
695*1003e004SJérôme Duval  * Returns the current capacity of the vector.
696*1003e004SJérôme Duval  *
697*1003e004SJérôme Duval  * @param   vector      A pointer to the `ZyanVector` instance.
698*1003e004SJérôme Duval  * @param   capacity    Receives the size of the vector.
699*1003e004SJérôme Duval  *
700*1003e004SJérôme Duval  * @return  A zyan status code.
701*1003e004SJérôme Duval  */
702*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorGetCapacity(const ZyanVector* vector, ZyanUSize* capacity);
703*1003e004SJérôme Duval 
704*1003e004SJérôme Duval /**
705*1003e004SJérôme Duval  * Returns the current size of the vector.
706*1003e004SJérôme Duval  *
707*1003e004SJérôme Duval  * @param   vector  A pointer to the `ZyanVector` instance.
708*1003e004SJérôme Duval  * @param   size    Receives the size of the vector.
709*1003e004SJérôme Duval  *
710*1003e004SJérôme Duval  * @return  A zyan status code.
711*1003e004SJérôme Duval  */
712*1003e004SJérôme Duval ZYCORE_EXPORT ZyanStatus ZyanVectorGetSize(const ZyanVector* vector, ZyanUSize* size);
713*1003e004SJérôme Duval 
714*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */
715*1003e004SJérôme Duval 
716*1003e004SJérôme Duval /* ============================================================================================== */
717*1003e004SJérôme Duval 
718*1003e004SJérôme Duval #ifdef __cplusplus
719*1003e004SJérôme Duval }
720*1003e004SJérôme Duval #endif
721*1003e004SJérôme Duval 
722*1003e004SJérôme Duval #endif /* ZYCORE_VECTOR_H */
723