src/array.c

Thu, 04 Jul 2019 21:31:45 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 04 Jul 2019 21:31:45 +0200
branch
feature/array
changeset 335
872ae61c8945
parent 334
bc81faa9afda
child 336
6d7aa8a1a3b3
permissions
-rw-r--r--

fixes inappropriate size datatype in list merge sort

103
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
1 /*
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
3 *
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
4 * Copyright 2019 Mike Becker, Olaf Wintermann All rights reserved.
103
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
5 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
6 * Redistribution and use in source and binary forms, with or without
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
7 * modification, are permitted provided that the following conditions are met:
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
8 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
10 * notice, this list of conditions and the following disclaimer.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
11 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
14 * documentation and/or other materials provided with the distribution.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
15 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
27 */
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
28
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
29 #include "ucx/array.h"
4
dbc31727b38e added dlist specification
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30
125
fca8efb122de changed suffix for allocator aware functions + added allocator aware functions for UcxList
Mike Becker <universe@uap-core.de>
parents: 123
diff changeset
31
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
32 UcxArray ucx_array_new(size_t capacity, size_t elemsize) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
33 return ucx_array_new_a(capacity, elemsize, ucx_default_allocator());
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 13
diff changeset
34 }
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 13
diff changeset
35
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
36 UcxArray ucx_array_new_a(size_t capacity, size_t elemsize,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
37 UcxAllocator* allocator) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
38 UcxArray array;
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 13
diff changeset
39
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
40 return array;
125
fca8efb122de changed suffix for allocator aware functions + added allocator aware functions for UcxList
Mike Becker <universe@uap-core.de>
parents: 123
diff changeset
41 }
fca8efb122de changed suffix for allocator aware functions + added allocator aware functions for UcxList
Mike Becker <universe@uap-core.de>
parents: 123
diff changeset
42
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
43 UcxArray ucx_array_clone(UcxArray array) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
44 UcxArray clone;
7
68091406d1cf added dlist to makefile, implemented first functions, discarded some fails
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
45
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
46 return clone;
7
68091406d1cf added dlist to makefile, implemented first functions, discarded some fails
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
47 }
68091406d1cf added dlist to makefile, implemented first functions, discarded some fails
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
48
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
49 int ucx_array_equals(UcxArray array1, UcxArray array2,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
50 cmp_func cmpfnc, void* data) {
7
68091406d1cf added dlist to makefile, implemented first functions, discarded some fails
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
51
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
52 return 1;
7
68091406d1cf added dlist to makefile, implemented first functions, discarded some fails
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
53 }
68091406d1cf added dlist to makefile, implemented first functions, discarded some fails
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
54
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
55 void ucx_array_free(UcxArray *array) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
56
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
57 }
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
58
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
59 int ucx_array_append(UcxArray *array, void *data) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
60 return 1;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
61 }
8
9cd2b2460db0 completed dlist
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
62
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
63 int ucx_array_prepend(UcxArray *array, void *data) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
64 return 1;
7
68091406d1cf added dlist to makefile, implemented first functions, discarded some fails
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
65 }
68091406d1cf added dlist to makefile, implemented first functions, discarded some fails
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
66
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
67 int ucx_array_concat(UcxArray *array1, const UcxArray *array2) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
68 return 1;
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
69 }
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
70
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
71 void *ucx_array_at(UcxArray array, size_t index) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
72 return NULL;
7
68091406d1cf added dlist to makefile, implemented first functions, discarded some fails
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
73 }
68091406d1cf added dlist to makefile, implemented first functions, discarded some fails
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
74
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
75 size_t ucx_array_find(UcxArray array, void *elem, cmp_func cmpfnc, void *data) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
76
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
77 return 0;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
78 }
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
79
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
80 int ucx_array_contains(UcxArray array, void *elem, cmp_func cmpfnc, void *data) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
81 return ucx_array_find(array, elem, cmpfnc, data) != array.size;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
82 }
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
83
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
84 int ucx_array_sort(UcxArray array, cmp_func cmpfnc, void *data) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
85 return 1;
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
86 }
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
87
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
88 void ucx_array_remove(UcxArray *array, size_t index) {
172
7084e8e8433c refactoring of list tests + some bug fixes
Mike Becker <universe@uap-core.de>
parents: 161
diff changeset
89
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
90 }
37
ec296899d12f replaced qsort with natural merge sort
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
91
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
92 void ucx_array_remove_fast(UcxArray *array, size_t index) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
93
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
94 }
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
95
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
96 int ucx_array_shrink(UcxArray* array) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
97 return 1;
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
98 }
22
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
99
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
100 int ucx_array_resize(UcxArray* array, size_t capacity) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
101 return 1;
125
fca8efb122de changed suffix for allocator aware functions + added allocator aware functions for UcxList
Mike Becker <universe@uap-core.de>
parents: 123
diff changeset
102 }
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
103
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
104 int ucx_array_reserve(UcxArray* array, size_t capacity) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
105 return 1;
22
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
106 }
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
107

mercurial