ucx
UAP Common Extensions
Loading...
Searching...
No Matches
array_list.h
Go to the documentation of this file.
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
39#ifndef UCX_ARRAY_LIST_H
40#define UCX_ARRAY_LIST_H
41
42#include "list.h"
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
66 void *(*realloc)(
67 void *array,
68 size_t capacity,
69 size_t elem_size,
70 struct cx_array_reallocator_s *alloc
71 );
72
76 void *ptr1;
80 void *ptr2;
84 size_t int1;
88 size_t int2;
89};
90
95 CX_ARRAY_COPY_SUCCESS,
96 CX_ARRAY_COPY_REALLOC_NOT_SUPPORTED,
97 CX_ARRAY_COPY_REALLOC_FAILED,
98};
99
126 void **target,
127 size_t *size,
128 size_t *capacity,
129 size_t index,
130 void const *src,
131 size_t elem_size,
132 size_t elem_count,
133 struct cx_array_reallocator_s *reallocator
134) __attribute__((__nonnull__(1, 2, 5)));
135
136
146 void *arr,
147 size_t elem_size,
148 size_t idx1,
149 size_t idx2
150) __attribute__((__nonnull__));
151
167 CxAllocator const *allocator,
168 cx_compare_func comparator,
169 size_t item_size,
170 size_t initial_capacity
171);
172
187#define cxArrayListCreateSimple(item_size, initial_capacity) \
188 cxArrayListCreate(NULL, NULL, item_size, initial_capacity)
189
190#ifdef __cplusplus
191} // extern "C"
192#endif
193
194#endif // UCX_ARRAY_LIST_H
CxList * cxArrayListCreate(CxAllocator const *allocator, cx_compare_func comparator, size_t item_size, size_t initial_capacity)
Allocates an array list for storing elements with item_size bytes each.
cx_array_copy_result
Return codes for cx_array_copy().
Definition: array_list.h:94
enum cx_array_copy_result cx_array_copy(void **target, size_t *size, size_t *capacity, size_t index, void const *src, size_t elem_size, size_t elem_count, struct cx_array_reallocator_s *reallocator)
Copies elements from one array to another.
void cx_array_swap(void *arr, size_t elem_size, size_t idx1, size_t idx2)
Swaps two array elements.
int(* cx_compare_func)(void const *left, void const *right)
A comparator function comparing two collection elements.
Definition: collection.h:55
#define __attribute__(x)
Removes GNU C attributes where they are not supported.
Definition: common.h:127
Interface for list implementations.
Structure holding the data for an allocator.
Definition: allocator.h:86
Defines a reallocation mechanism for arrays.
Definition: array_list.h:51
void * ptr1
Custom data pointer.
Definition: array_list.h:76
size_t int1
Custom data integer.
Definition: array_list.h:84
size_t int2
Custom data integer.
Definition: array_list.h:88
void * ptr2
Custom data pointer.
Definition: array_list.h:80
Structure for holding the base data of a list.
Definition: list.h:55