src/cx/array_list.h

Sun, 13 Nov 2022 13:21:48 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 13 Nov 2022 13:21:48 +0100
changeset 607
2d99e978dc34
parent 606
314e9288af2f
child 608
2e93521145ac
permissions
-rw-r--r--

implement array list ctor and dtor

also lays out the "glue level" functions

606
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 /**
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 * \file array_list.h
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 * \brief Array list implementation.
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 * \details Also provides several low-level functions for custom array list implementations.
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 * \author Mike Becker
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 * \author Olaf Wintermann
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 * \version 3.0
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 * \copyright 2-Clause BSD License
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 */
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 #ifndef UCX_ARRAY_LIST_H
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 #define UCX_ARRAY_LIST_H
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 #include "cx/list.h"
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 #ifdef __cplusplus
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45 extern "C" {
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 #endif
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 /**
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 * Allocates an array list for storing elements with \p item_size bytes each.
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 *
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 * @param allocator the allocator for allocating the list memory
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 * @param comparator the comparator for the elements
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 * @param item_size the size of each element in bytes
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 * @param initial_capacity the initial number of elements the array can store
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 * @return the created list
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 */
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 CxList *cxArrayListCreate(
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 CxAllocator const *allocator,
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 CxListComparator comparator,
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 size_t item_size,
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 size_t initial_capacity
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 ) __attribute__((__nonnull__));
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 #ifdef __cplusplus
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 } /* extern "C" */
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 #endif
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68
314e9288af2f add array list tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 #endif /* UCX_ARRAY_LIST_H */

mercurial