Wed, 10 Dec 2025 18:36:02 +0100
implement json child object serialization
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
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 |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "cx/list.h" |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <string.h> |
| 22 | 32 | #include <assert.h> |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | // <editor-fold desc="Store Pointers Functionality"> |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | static _Thread_local cx_compare_func cx_pl_cmpfunc_impl; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | static int cx_pl_cmpfunc( |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
39 | const void *l, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
40 | const void *r |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | ) { |
| 22 | 42 | // l and r are guaranteed to be non-NULL pointing to the list's memory |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | void *const *lptr = l; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | void *const *rptr = r; |
| 22 | 45 | const void *left = *lptr; |
| 46 | const void *right = *rptr; | |
| 47 | if (left == NULL) { | |
| 48 | // NULL is smaller than any value except NULL | |
| 49 | return right == NULL ? 0 : -1; | |
| 50 | } else if (right == NULL) { | |
| 51 | // any value is larger than NULL | |
| 52 | return 1; | |
| 53 | } | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | return cx_pl_cmpfunc_impl(left, right); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
57 | static void cx_pl_hack_cmpfunc(const struct cx_list_s *list) { |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | // cast away const - this is the hacky thing |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | struct cx_collection_s *l = (struct cx_collection_s*) &list->collection; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | cx_pl_cmpfunc_impl = l->cmpfunc; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | l->cmpfunc = cx_pl_cmpfunc; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
64 | static void cx_pl_unhack_cmpfunc(const struct cx_list_s *list) { |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | // cast away const - this is the hacky thing |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | struct cx_collection_s *l = (struct cx_collection_s*) &list->collection; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | l->cmpfunc = cx_pl_cmpfunc_impl; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | static void cx_pl_destructor(struct cx_list_s *list) { |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
71 | list->climpl->deallocate(list); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | |
| 21 | 74 | static void *cx_pl_insert_element( |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | struct cx_list_s *list, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | size_t index, |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
77 | const void *element |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | ) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | return list->climpl->insert_element(list, index, &element); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | static size_t cx_pl_insert_array( |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | struct cx_list_s *list, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | size_t index, |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
85 | const void *array, |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | size_t n |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | ) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | return list->climpl->insert_array(list, index, array, n); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
91 | static size_t cx_pl_insert_sorted( |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
92 | struct cx_list_s *list, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
93 | const void *array, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
94 | size_t n |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
95 | ) { |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
96 | cx_pl_hack_cmpfunc(list); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
97 | size_t result = list->climpl->insert_sorted(list, array, n); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
98 | cx_pl_unhack_cmpfunc(list); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
99 | return result; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
100 | } |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
101 | |
| 22 | 102 | static size_t cx_pl_insert_unique( |
| 103 | struct cx_list_s *list, | |
| 104 | const void *array, | |
| 105 | size_t n | |
| 106 | ) { | |
| 107 | cx_pl_hack_cmpfunc(list); | |
| 108 | size_t result = list->climpl->insert_unique(list, array, n); | |
| 109 | cx_pl_unhack_cmpfunc(list); | |
| 110 | return result; | |
| 111 | } | |
| 112 | ||
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | static int cx_pl_insert_iter( |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | struct cx_iterator_s *iter, |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
115 | const void *elem, |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | int prepend |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | ) { |
| 22 | 118 | struct cx_list_s *list = iter->src_handle; |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | return list->climpl->insert_iter(iter, &elem, prepend); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
122 | static size_t cx_pl_remove( |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | struct cx_list_s *list, |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
124 | size_t index, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
125 | size_t num, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
126 | void *targetbuf |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | ) { |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
128 | return list->climpl->remove(list, index, num, targetbuf); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | static void cx_pl_clear(struct cx_list_s *list) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | list->climpl->clear(list); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | static int cx_pl_swap( |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | struct cx_list_s *list, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | size_t i, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | size_t j |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | ) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | return list->climpl->swap(list, i, j); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | static void *cx_pl_at( |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
144 | const struct cx_list_s *list, |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | size_t index |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | ) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | void **ptr = list->climpl->at(list, index); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | return ptr == NULL ? NULL : *ptr; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | |
| 16 | 151 | static size_t cx_pl_find_remove( |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | struct cx_list_s *list, |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
153 | const void *elem, |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | bool remove |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | ) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | cx_pl_hack_cmpfunc(list); |
| 16 | 157 | size_t ret = list->climpl->find_remove(list, &elem, remove); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | cx_pl_unhack_cmpfunc(list); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | return ret; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | static void cx_pl_sort(struct cx_list_s *list) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | cx_pl_hack_cmpfunc(list); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | list->climpl->sort(list); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | cx_pl_unhack_cmpfunc(list); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | static int cx_pl_compare( |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
169 | const struct cx_list_s *list, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
170 | const struct cx_list_s *other |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | ) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | cx_pl_hack_cmpfunc(list); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | int ret = list->climpl->compare(list, other); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | cx_pl_unhack_cmpfunc(list); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | return ret; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | static void cx_pl_reverse(struct cx_list_s *list) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | list->climpl->reverse(list); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
182 | static void *cx_pl_iter_current(const void *it) { |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
183 | const struct cx_iterator_s *iter = it; |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | void **ptr = iter->base.current_impl(it); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | return ptr == NULL ? NULL : *ptr; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | |
| 22 | 188 | static int cx_pl_change_capacity(struct cx_list_s *list, size_t cap) { |
| 189 | if (list->climpl->change_capacity == NULL) { | |
| 190 | return 0; | |
| 191 | } else { | |
| 192 | return list->climpl->change_capacity(list, cap); | |
| 193 | } | |
| 194 | } | |
| 195 | ||
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | static struct cx_iterator_s cx_pl_iterator( |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
197 | const struct cx_list_s *list, |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | size_t index, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | bool backwards |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | ) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | struct cx_iterator_s iter = list->climpl->iterator(list, index, backwards); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | iter.base.current_impl = iter.base.current; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | iter.base.current = cx_pl_iter_current; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | return iter; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | static cx_list_class cx_pointer_list_class = { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | cx_pl_destructor, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | cx_pl_insert_element, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | cx_pl_insert_array, |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
211 | cx_pl_insert_sorted, |
| 22 | 212 | cx_pl_insert_unique, |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | cx_pl_insert_iter, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | cx_pl_remove, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | cx_pl_clear, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | cx_pl_swap, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | cx_pl_at, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | cx_pl_find_remove, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | cx_pl_sort, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | cx_pl_compare, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | cx_pl_reverse, |
| 22 | 222 | cx_pl_change_capacity, |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | cx_pl_iterator, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | }; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | // </editor-fold> |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | // <editor-fold desc="empty list implementation"> |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
229 | static void cx_emptyl_noop(cx_attr_unused CxList *list) { |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | // this is a noop, but MUST be implemented |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | static void *cx_emptyl_at( |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
234 | cx_attr_unused const struct cx_list_s *list, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
235 | cx_attr_unused size_t index |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | ) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | return NULL; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | |
| 16 | 240 | static size_t cx_emptyl_find_remove( |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
241 | cx_attr_unused struct cx_list_s *list, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
242 | cx_attr_unused const void *elem, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
243 | cx_attr_unused bool remove |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | ) { |
| 16 | 245 | return 0; |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
248 | static bool cx_emptyl_iter_valid(cx_attr_unused const void *iter) { |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | return false; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | static CxIterator cx_emptyl_iterator( |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
253 | const struct cx_list_s *list, |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | size_t index, |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
255 | cx_attr_unused bool backwards |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | ) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | CxIterator iter = {0}; |
| 22 | 258 | iter.src_handle = (void*) list; |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | iter.index = index; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | iter.base.valid = cx_emptyl_iter_valid; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | return iter; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | static cx_list_class cx_empty_list_class = { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | cx_emptyl_noop, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | NULL, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | NULL, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | NULL, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | NULL, |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
270 | NULL, |
| 22 | 271 | NULL, |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | cx_emptyl_noop, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | NULL, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | cx_emptyl_at, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | cx_emptyl_find_remove, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | cx_emptyl_noop, |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
277 | NULL, |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | cx_emptyl_noop, |
| 22 | 279 | NULL, |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | cx_emptyl_iterator, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | }; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | CxList cx_empty_list = { |
| 16 | 284 | { |
| 285 | NULL, | |
| 286 | NULL, | |
| 287 | 0, | |
| 288 | 0, | |
| 289 | NULL, | |
| 290 | NULL, | |
| 291 | NULL, | |
| 292 | false, | |
| 293 | true, | |
| 294 | }, | |
| 295 | &cx_empty_list_class, | |
| 296 | NULL | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297 | }; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299 | CxList *const cxEmptyList = &cx_empty_list; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | // </editor-fold> |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
303 | #define invoke_list_func(name, list, ...) \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
304 | ((list)->climpl == NULL ? (list)->cl->name : (list)->climpl->name) \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
305 | (list, __VA_ARGS__) |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
306 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
307 | size_t cx_list_default_insert_array( |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
308 | struct cx_list_s *list, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
309 | size_t index, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
310 | const void *data, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
311 | size_t n |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
312 | ) { |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
313 | const char *src = data; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
314 | size_t i = 0; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
315 | for (; i < n; i++) { |
| 21 | 316 | if (NULL == invoke_list_func( |
| 22 | 317 | insert_element, list, index + i, src) |
| 318 | ) { | |
| 319 | return i; // LCOV_EXCL_LINE | |
| 320 | } | |
| 321 | if (src != NULL) { | |
| 322 | src += list->collection.elem_size; | |
| 323 | } | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
324 | } |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
325 | return i; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
326 | } |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
327 | |
| 22 | 328 | static size_t cx_list_default_insert_sorted_impl( |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
329 | struct cx_list_s *list, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
330 | const void *sorted_data, |
| 22 | 331 | size_t n, |
| 332 | bool allow_duplicates | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
333 | ) { |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
334 | // corner case |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
335 | if (n == 0) return 0; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
336 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
337 | size_t elem_size = list->collection.elem_size; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
338 | cx_compare_func cmp = list->collection.cmpfunc; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
339 | const char *src = sorted_data; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
340 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
341 | // track indices and number of inserted items |
| 22 | 342 | size_t di = 0, si = 0, processed = 0; |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
343 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
344 | // search the list for insertion points |
| 22 | 345 | while (di < list->collection.size) { |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
346 | const void *list_elm = invoke_list_func(at, list, di); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
347 | |
| 22 | 348 | // compare the current list element with the first source element |
| 349 | // if less, skip the list elements | |
| 350 | // if equal, skip the list elements and optionally the source elements | |
| 351 | { | |
| 352 | int d = cmp(list_elm, src); | |
| 353 | if (d <= 0) { | |
| 354 | if (!allow_duplicates && d == 0) { | |
| 355 | src += elem_size; | |
| 356 | si++; | |
| 357 | processed++; // we also count duplicates for the return value | |
| 358 | while (si < n && cmp(list_elm, src) == 0) { | |
| 359 | src += elem_size; | |
| 360 | si++; | |
| 361 | processed++; | |
| 362 | } | |
| 363 | if (processed == n) { | |
| 364 | return processed; | |
| 365 | } | |
| 366 | } | |
| 367 | di++; | |
| 368 | continue; | |
| 369 | } | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
370 | } |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
371 | |
| 22 | 372 | // determine the number of consecutive elements that can be inserted |
| 373 | size_t ins = 1, skip = 0; | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
374 | const char *next = src; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
375 | while (++si < n) { |
| 22 | 376 | if (!allow_duplicates) { |
| 377 | // skip duplicates within the source | |
| 378 | if (cmp(next, next + elem_size) == 0) { | |
| 379 | next += elem_size; | |
| 380 | skip++; | |
| 381 | continue; | |
| 382 | } else { | |
| 383 | if (skip > 0) { | |
| 384 | // if we had to skip something, we must wait for the next run | |
| 385 | next += elem_size; | |
| 386 | break; | |
| 387 | } | |
| 388 | } | |
| 389 | } | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
390 | next += elem_size; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
391 | // once we become larger than the list elem, break |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
392 | if (cmp(list_elm, next) <= 0) { |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
393 | break; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
394 | } |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
395 | // otherwise, we can insert one more |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
396 | ins++; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
397 | } |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
398 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
399 | // insert the elements at location si |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
400 | if (ins == 1) { |
| 22 | 401 | if (NULL == invoke_list_func(insert_element, list, di, src)) { |
| 402 | return processed; // LCOV_EXCL_LINE | |
| 403 | } | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
404 | } else { |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
405 | size_t r = invoke_list_func(insert_array, list, di, src, ins); |
| 22 | 406 | if (r < ins) { |
| 407 | return processed + r; // LCOV_EXCL_LINE | |
| 408 | } | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
409 | } |
| 22 | 410 | processed += ins + skip; |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
411 | di += ins; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
412 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
413 | // everything inserted? |
| 22 | 414 | if (processed == n) { |
| 415 | return processed; | |
| 416 | } | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
417 | src = next; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
418 | } |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
419 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
420 | // insert remaining items |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
421 | if (si < n) { |
| 22 | 422 | if (allow_duplicates) { |
| 423 | processed += invoke_list_func(insert_array, list, di, src, n - si); | |
| 424 | } else { | |
| 425 | const void *last = di == 0 ? NULL : invoke_list_func(at, list, di - 1); | |
| 426 | for (; si < n; si++) { | |
| 427 | // skip duplicates within the source | |
| 428 | if (last == NULL || cmp(last, src) != 0) { | |
| 429 | if (NULL == invoke_list_func(insert_element, list, di, src)) { | |
| 430 | return processed; // LCOV_EXCL_LINE | |
| 431 | } | |
| 432 | last = src; | |
| 433 | di++; | |
| 434 | } | |
| 435 | processed++; | |
| 436 | src += elem_size; | |
| 437 | } | |
| 438 | } | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
439 | } |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
440 | |
| 22 | 441 | return processed; |
| 442 | } | |
| 443 | ||
| 444 | size_t cx_list_default_insert_sorted( | |
| 445 | struct cx_list_s *list, | |
| 446 | const void *sorted_data, | |
| 447 | size_t n | |
| 448 | ) { | |
| 449 | return cx_list_default_insert_sorted_impl(list, sorted_data, n, true); | |
| 450 | } | |
| 451 | ||
| 452 | size_t cx_list_default_insert_unique( | |
| 453 | struct cx_list_s *list, | |
| 454 | const void *sorted_data, | |
| 455 | size_t n | |
| 456 | ) { | |
| 457 | return cx_list_default_insert_sorted_impl(list, sorted_data, n, false); | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
458 | } |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
459 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
460 | void cx_list_default_sort(struct cx_list_s *list) { |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
461 | size_t elem_size = list->collection.elem_size; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
462 | size_t list_size = list->collection.size; |
| 21 | 463 | void *tmp = cxMallocDefault(elem_size * list_size); |
| 22 | 464 | if (tmp == NULL) abort(); // LCOV_EXCL_LINE |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
465 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
466 | // copy elements from source array |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
467 | char *loc = tmp; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
468 | for (size_t i = 0; i < list_size; i++) { |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
469 | void *src = invoke_list_func(at, list, i); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
470 | memcpy(loc, src, elem_size); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
471 | loc += elem_size; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
472 | } |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
473 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
474 | // qsort |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
475 | qsort(tmp, list_size, elem_size, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
476 | list->collection.cmpfunc); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
477 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
478 | // copy elements back |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
479 | loc = tmp; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
480 | for (size_t i = 0; i < list_size; i++) { |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
481 | void *dest = invoke_list_func(at, list, i); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
482 | memcpy(dest, loc, elem_size); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
483 | loc += elem_size; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
484 | } |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
485 | |
| 21 | 486 | cxFreeDefault(tmp); |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
487 | } |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
488 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
489 | int cx_list_default_swap(struct cx_list_s *list, size_t i, size_t j) { |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
490 | if (i == j) return 0; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
491 | if (i >= list->collection.size) return 1; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
492 | if (j >= list->collection.size) return 1; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
493 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
494 | size_t elem_size = list->collection.elem_size; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
495 | |
| 21 | 496 | void *tmp = cxMallocDefault(elem_size); |
| 22 | 497 | if (tmp == NULL) return 1; // LCOV_EXCL_LINE |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
498 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
499 | void *ip = invoke_list_func(at, list, i); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
500 | void *jp = invoke_list_func(at, list, j); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
501 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
502 | memcpy(tmp, ip, elem_size); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
503 | memcpy(ip, jp, elem_size); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
504 | memcpy(jp, tmp, elem_size); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
505 | |
| 21 | 506 | cxFreeDefault(tmp); |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
507 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
508 | return 0; |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
509 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
510 | |
| 16 | 511 | void cx_list_init( |
| 512 | struct cx_list_s *list, | |
| 513 | struct cx_list_class_s *cl, | |
| 514 | const struct cx_allocator_s *allocator, | |
| 515 | cx_compare_func comparator, | |
| 516 | size_t elem_size | |
| 517 | ) { | |
| 518 | list->cl = cl; | |
| 519 | list->collection.allocator = allocator; | |
| 520 | list->collection.cmpfunc = comparator; | |
| 521 | if (elem_size > 0) { | |
| 522 | list->collection.elem_size = elem_size; | |
| 523 | } else { | |
| 524 | list->collection.elem_size = sizeof(void *); | |
| 525 | if (list->collection.cmpfunc == NULL) { | |
| 526 | list->collection.cmpfunc = cx_cmp_ptr; | |
| 527 | } | |
| 528 | list->collection.store_pointer = true; | |
| 529 | list->climpl = list->cl; | |
| 530 | list->cl = &cx_pointer_list_class; | |
| 531 | } | |
| 532 | } | |
| 533 | ||
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
534 | int cxListCompare( |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
535 | const CxList *list, |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
536 | const CxList *other |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
537 | ) { |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
538 | bool cannot_optimize = false; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
539 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
540 | // if one is storing pointers but the other is not |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
541 | cannot_optimize |= list->collection.store_pointer ^ other->collection.store_pointer; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
542 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
543 | // if one class is wrapped but the other is not |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
544 | cannot_optimize |= (list->climpl == NULL) ^ (other->climpl == NULL); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
545 | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
546 | // if the compare functions do not match or both are NULL |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
547 | if (!cannot_optimize) { |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
548 | cx_compare_func list_cmp = (cx_compare_func) (list->climpl != NULL ? |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
549 | list->climpl->compare : list->cl->compare); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
550 | cx_compare_func other_cmp = (cx_compare_func) (other->climpl != NULL ? |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
551 | other->climpl->compare : other->cl->compare); |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
552 | cannot_optimize |= list_cmp != other_cmp; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
553 | cannot_optimize |= list_cmp == NULL; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
554 | } |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
555 | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
556 | if (cannot_optimize) { |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
557 | // lists are definitely different - cannot use internal compare function |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
558 | if (list->collection.size == other->collection.size) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
559 | CxIterator left = list->cl->iterator(list, 0, false); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
560 | CxIterator right = other->cl->iterator(other, 0, false); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
561 | for (size_t i = 0; i < list->collection.size; i++) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
562 | void *leftValue = cxIteratorCurrent(left); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
563 | void *rightValue = cxIteratorCurrent(right); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
564 | int d = list->collection.cmpfunc(leftValue, rightValue); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
565 | if (d != 0) { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
566 | return d; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
567 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
568 | cxIteratorNext(left); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
569 | cxIteratorNext(right); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
570 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
571 | return 0; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
572 | } else { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
573 | return list->collection.size < other->collection.size ? -1 : 1; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
574 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
575 | } else { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
576 | // lists are compatible |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
577 | return list->cl->compare(list, other); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
578 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
579 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
580 | |
| 22 | 581 | size_t cxListSize(const CxList *list) { |
| 582 | return list->collection.size; | |
| 583 | } | |
| 584 | ||
| 585 | int cxListAdd(CxList *list, const void *elem) { | |
| 586 | list->collection.sorted = false; | |
| 587 | return list->cl->insert_element(list, list->collection.size, elem) == NULL; | |
| 588 | } | |
| 589 | ||
| 590 | size_t cxListAddArray(CxList *list, const void *array, size_t n) { | |
| 591 | list->collection.sorted = false; | |
| 592 | return list->cl->insert_array(list, list->collection.size, array, n); | |
| 593 | } | |
| 594 | ||
| 595 | int cxListInsert(CxList *list, size_t index, const void *elem) { | |
| 596 | list->collection.sorted = false; | |
| 597 | return list->cl->insert_element(list, index, elem) == NULL; | |
| 598 | } | |
| 599 | ||
| 600 | void *cxListEmplaceAt(CxList *list, size_t index) { | |
| 601 | list->collection.sorted = false; | |
| 602 | return list->cl->insert_element(list, index, NULL); | |
| 603 | } | |
| 604 | ||
| 605 | void *cxListEmplace(CxList *list) { | |
| 606 | list->collection.sorted = false; | |
| 607 | return list->cl->insert_element(list, list->collection.size, NULL); | |
| 608 | } | |
| 609 | ||
| 610 | static bool cx_list_emplace_iterator_valid(const void *it) { | |
| 611 | const CxIterator *iter = it; | |
| 612 | return iter->index < iter->elem_count; | |
| 613 | } | |
| 614 | ||
| 615 | CxIterator cxListEmplaceArrayAt(CxList *list, size_t index, size_t n) { | |
| 616 | list->collection.sorted = false; | |
| 617 | size_t c = list->cl->insert_array(list, index, NULL, n); | |
| 618 | CxIterator iter = list->cl->iterator(list, index, false); | |
| 619 | // tweak the fields of this iterator | |
| 620 | iter.elem_count = c; | |
| 621 | iter.index = 0; | |
| 622 | // replace the valid function to abort iteration when c is reached | |
| 623 | iter.base.valid = cx_list_emplace_iterator_valid; | |
| 624 | // if we are storing pointers, we want to return the pure pointers. | |
| 625 | // therefore, we must unwrap the "current" method | |
| 626 | if (list->collection.store_pointer) { | |
| 627 | iter.base.current = iter.base.current_impl; | |
| 628 | } | |
| 629 | return iter; | |
| 630 | } | |
| 631 | ||
| 632 | CxIterator cxListEmplaceArray(CxList *list, size_t n) { | |
| 633 | return cxListEmplaceArrayAt(list, list->collection.size, n); | |
| 634 | } | |
| 635 | ||
| 636 | int cxListInsertSorted(CxList *list, const void *elem) { | |
| 637 | assert(cxCollectionSorted(list)); | |
| 638 | list->collection.sorted = true; | |
| 639 | const void *data = list->collection.store_pointer ? &elem : elem; | |
| 640 | return list->cl->insert_sorted(list, data, 1) == 0; | |
| 641 | } | |
| 642 | ||
| 643 | int cxListInsertUnique(CxList *list, const void *elem) { | |
| 644 | if (cxCollectionSorted(list)) { | |
| 645 | list->collection.sorted = true; | |
| 646 | const void *data = list->collection.store_pointer ? &elem : elem; | |
| 647 | return list->cl->insert_unique(list, data, 1) == 0; | |
| 648 | } else { | |
| 649 | if (cxListContains(list, elem)) { | |
| 650 | return 0; | |
| 651 | } else { | |
| 652 | return cxListAdd(list, elem); | |
| 653 | } | |
| 654 | } | |
| 655 | } | |
| 656 | ||
| 657 | size_t cxListInsertArray(CxList *list, size_t index, const void *array, size_t n) { | |
| 658 | list->collection.sorted = false; | |
| 659 | return list->cl->insert_array(list, index, array, n); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
660 | } |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
661 | |
| 22 | 662 | size_t cxListInsertSortedArray(CxList *list, const void *array, size_t n) { |
| 663 | assert(cxCollectionSorted(list)); | |
| 664 | list->collection.sorted = true; | |
| 665 | return list->cl->insert_sorted(list, array, n); | |
| 666 | } | |
| 667 | ||
| 668 | size_t cxListInsertUniqueArray(CxList *list, const void *array, size_t n) { | |
| 669 | if (cxCollectionSorted(list)) { | |
| 670 | list->collection.sorted = true; | |
| 671 | return list->cl->insert_unique(list, array, n); | |
| 672 | } else { | |
| 673 | const char *source = array; | |
| 674 | for (size_t i = 0 ; i < n; i++) { | |
| 675 | // note: this also checks elements added in a previous iteration | |
| 676 | const void *data = list->collection.store_pointer ? | |
| 677 | *((const void**)source) : source; | |
| 678 | if (!cxListContains(list, data)) { | |
| 679 | if (cxListAdd(list, data)) { | |
| 680 | return i; // LCOV_EXCL_LINE | |
| 681 | } | |
| 682 | } | |
| 683 | source += list->collection.elem_size; | |
| 684 | } | |
| 685 | return n; | |
| 686 | } | |
| 687 | } | |
| 688 | ||
| 689 | int cxListInsertAfter(CxIterator *iter, const void *elem) { | |
| 690 | CxList* list = (CxList*)iter->src_handle; | |
| 691 | list->collection.sorted = false; | |
| 692 | return list->cl->insert_iter(iter, elem, 0); | |
| 693 | } | |
| 694 | ||
| 695 | int cxListInsertBefore(CxIterator *iter, const void *elem) { | |
| 696 | CxList* list = (CxList*)iter->src_handle; | |
| 697 | list->collection.sorted = false; | |
| 698 | return list->cl->insert_iter(iter, elem, 1); | |
| 699 | } | |
| 700 | ||
| 701 | int cxListRemove(CxList *list, size_t index) { | |
| 702 | return list->cl->remove(list, index, 1, NULL) == 0; | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
703 | } |
| 16 | 704 | |
| 22 | 705 | int cxListRemoveAndGet(CxList *list, size_t index, void *targetbuf) { |
| 706 | return list->cl->remove(list, index, 1, targetbuf) == 0; | |
| 707 | } | |
| 708 | ||
| 709 | int cxListRemoveAndGetFirst(CxList *list, void *targetbuf) { | |
| 710 | return list->cl->remove(list, 0, 1, targetbuf) == 0; | |
| 711 | } | |
| 712 | ||
| 713 | int cxListRemoveAndGetLast(CxList *list, void *targetbuf) { | |
| 714 | // note: index may wrap - member function will catch that | |
| 715 | return list->cl->remove(list, list->collection.size - 1, 1, targetbuf) == 0; | |
| 716 | } | |
| 717 | ||
| 718 | size_t cxListRemoveArray(CxList *list, size_t index, size_t num) { | |
| 719 | return list->cl->remove(list, index, num, NULL); | |
| 720 | } | |
| 721 | ||
| 722 | size_t cxListRemoveArrayAndGet(CxList *list, size_t index, size_t num, void *targetbuf) { | |
| 723 | return list->cl->remove(list, index, num, targetbuf); | |
| 16 | 724 | } |
| 21 | 725 | |
| 22 | 726 | void cxListClear(CxList *list) { |
| 727 | list->cl->clear(list); | |
| 728 | list->collection.sorted = true; // empty lists are always sorted | |
| 729 | } | |
| 730 | ||
| 731 | int cxListSwap(CxList *list, size_t i, size_t j) { | |
| 732 | list->collection.sorted = false; | |
| 733 | return list->cl->swap(list, i, j); | |
| 734 | } | |
| 735 | ||
| 736 | void *cxListAt(const CxList *list, size_t index) { | |
| 737 | return list->cl->at(list, index); | |
| 738 | } | |
| 739 | ||
| 740 | void *cxListFirst(const CxList *list) { | |
| 741 | return list->cl->at(list, 0); | |
| 742 | } | |
| 743 | ||
| 744 | void *cxListLast(const CxList *list) { | |
| 745 | return list->cl->at(list, list->collection.size - 1); | |
| 746 | } | |
| 747 | ||
| 748 | int cxListSet(CxList *list, size_t index, const void *elem) { | |
| 21 | 749 | if (index >= list->collection.size) { |
| 750 | return 1; | |
| 751 | } | |
| 752 | ||
| 753 | if (list->collection.store_pointer) { | |
| 754 | // For pointer collections, always use climpl | |
| 755 | void **target = list->climpl->at(list, index); | |
| 756 | *target = (void *)elem; | |
| 757 | } else { | |
| 758 | void *target = list->cl->at(list, index); | |
| 759 | memcpy(target, elem, list->collection.elem_size); | |
| 760 | } | |
| 761 | ||
| 762 | return 0; | |
| 763 | } | |
| 22 | 764 | |
| 765 | CxIterator cxListIteratorAt(const CxList *list, size_t index) { | |
| 766 | if (list == NULL) list = cxEmptyList; | |
| 767 | return list->cl->iterator(list, index, false); | |
| 768 | } | |
| 769 | ||
| 770 | CxIterator cxListBackwardsIteratorAt(const CxList *list, size_t index) { | |
| 771 | if (list == NULL) list = cxEmptyList; | |
| 772 | return list->cl->iterator(list, index, true); | |
| 773 | } | |
| 774 | ||
| 775 | CxIterator cxListIterator(const CxList *list) { | |
| 776 | if (list == NULL) list = cxEmptyList; | |
| 777 | return list->cl->iterator(list, 0, false); | |
| 778 | } | |
| 779 | ||
| 780 | CxIterator cxListBackwardsIterator(const CxList *list) { | |
| 781 | if (list == NULL) list = cxEmptyList; | |
| 782 | return list->cl->iterator(list, list->collection.size - 1, true); | |
| 783 | } | |
| 784 | ||
| 785 | size_t cxListFind(const CxList *list, const void *elem) { | |
| 786 | return list->cl->find_remove((CxList*)list, elem, false); | |
| 787 | } | |
| 788 | ||
| 789 | bool cxListContains(const CxList* list, const void* elem) { | |
| 790 | return list->cl->find_remove((CxList*)list, elem, false) < list->collection.size; | |
| 791 | } | |
| 792 | ||
| 793 | bool cxListIndexValid(const CxList *list, size_t index) { | |
| 794 | return index < list->collection.size; | |
| 795 | } | |
| 796 | ||
| 797 | size_t cxListFindRemove(CxList *list, const void *elem) { | |
| 798 | return list->cl->find_remove(list, elem, true); | |
| 799 | } | |
| 800 | ||
| 801 | void cxListSort(CxList *list) { | |
| 802 | if (list->collection.sorted) return; | |
| 803 | list->cl->sort(list); | |
| 804 | list->collection.sorted = true; | |
| 805 | } | |
| 806 | ||
| 807 | void cxListReverse(CxList *list) { | |
| 808 | // still sorted, but not according to the cmp_func | |
| 809 | list->collection.sorted = false; | |
| 810 | list->cl->reverse(list); | |
| 811 | } | |
| 812 | ||
| 813 | void cxListFree(CxList *list) { | |
| 814 | if (list == NULL) return; | |
| 815 | list->cl->deallocate(list); | |
| 816 | } | |
| 817 | ||
| 818 | static void cx_list_pop_uninitialized_elements(CxList *list, size_t n) { | |
| 819 | cx_destructor_func destr_bak = list->collection.simple_destructor; | |
| 820 | cx_destructor_func2 destr2_bak = list->collection.advanced_destructor; | |
| 821 | list->collection.simple_destructor = NULL; | |
| 822 | list->collection.advanced_destructor = NULL; | |
| 823 | if (n == 1) { | |
| 824 | cxListRemove(list, list->collection.size - 1); | |
| 825 | } else { | |
| 826 | cxListRemoveArray(list,list->collection.size - n, n); | |
| 827 | } | |
| 828 | list->collection.simple_destructor = destr_bak; | |
| 829 | list->collection.advanced_destructor = destr2_bak; | |
| 830 | } | |
| 831 | ||
| 832 | static void* cx_list_simple_clone_func(void *dst, const void *src, const CxAllocator *al, void *data) { | |
| 833 | size_t elem_size = *(size_t*)data; | |
| 834 | if (dst == NULL) dst = cxMalloc(al, elem_size); | |
| 835 | if (dst != NULL) memcpy(dst, src, elem_size); | |
| 836 | return dst; | |
| 837 | } | |
| 838 | ||
| 839 | #define use_simple_clone_func(list) cx_list_simple_clone_func, NULL, (void*)&((list)->collection.elem_size) | |
| 840 | ||
| 841 | int cxListClone(CxList *dst, const CxList *src, cx_clone_func clone_func, | |
| 842 | const CxAllocator *clone_allocator, void *data) { | |
| 843 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | |
| 844 | ||
| 845 | // remember the original size | |
| 846 | size_t orig_size = dst->collection.size; | |
| 847 | ||
| 848 | // first, try to allocate the memory in the new list | |
| 849 | CxIterator empl_iter = cxListEmplaceArray(dst, src->collection.size); | |
| 850 | ||
| 851 | // get an iterator over the source elements | |
| 852 | CxIterator src_iter = cxListIterator(src); | |
| 853 | ||
| 854 | // now clone the elements | |
| 855 | size_t cloned = empl_iter.elem_count; | |
| 856 | for (size_t i = 0 ; i < empl_iter.elem_count; i++) { | |
| 857 | void *src_elem = cxIteratorCurrent(src_iter); | |
| 858 | void **dest_memory = cxIteratorCurrent(empl_iter); | |
| 859 | void *target = cxCollectionStoresPointers(dst) ? NULL : dest_memory; | |
| 860 | void *dest_ptr = clone_func(target, src_elem, clone_allocator, data); | |
| 861 | if (dest_ptr == NULL) { | |
| 862 | cloned = i; | |
| 863 | break; | |
| 864 | } | |
| 865 | if (cxCollectionStoresPointers(dst)) { | |
| 866 | *dest_memory = dest_ptr; | |
| 867 | } | |
| 868 | cxIteratorNext(src_iter); | |
| 869 | cxIteratorNext(empl_iter); | |
| 870 | } | |
| 871 | ||
| 872 | // if we could not clone everything, free the allocated memory | |
| 873 | // (disable the destructors!) | |
| 874 | if (cloned < src->collection.size) { | |
| 875 | cx_list_pop_uninitialized_elements(dst, | |
| 876 | dst->collection.size - cloned - orig_size); | |
| 877 | return 1; | |
| 878 | } | |
| 879 | ||
| 880 | // set the sorted flag when we know it's sorted | |
| 881 | if (orig_size == 0 && src->collection.sorted) { | |
| 882 | dst->collection.sorted = true; | |
| 883 | } | |
| 884 | ||
| 885 | return 0; | |
| 886 | } | |
| 887 | ||
| 888 | int cxListDifference(CxList *dst, | |
| 889 | const CxList *minuend, const CxList *subtrahend, | |
| 890 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { | |
| 891 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | |
| 892 | ||
| 893 | // optimize for sorted collections | |
| 894 | if (cxCollectionSorted(minuend) && cxCollectionSorted(subtrahend)) { | |
| 895 | bool dst_was_empty = cxCollectionSize(dst) == 0; | |
| 896 | ||
| 897 | CxIterator min_iter = cxListIterator(minuend); | |
| 898 | CxIterator sub_iter = cxListIterator(subtrahend); | |
| 899 | while (cxIteratorValid(min_iter)) { | |
| 900 | void *min_elem = cxIteratorCurrent(min_iter); | |
| 901 | void *sub_elem; | |
| 902 | int d; | |
| 903 | if (cxIteratorValid(sub_iter)) { | |
| 904 | sub_elem = cxIteratorCurrent(sub_iter); | |
| 905 | cx_compare_func cmp = subtrahend->collection.cmpfunc; | |
| 906 | d = cmp(sub_elem, min_elem); | |
| 907 | } else { | |
| 908 | // no more elements in the subtrahend, | |
| 909 | // i.e., the min_elem is larger than any elem of the subtrahend | |
| 910 | d = 1; | |
| 911 | } | |
| 912 | if (d == 0) { | |
| 913 | // is contained, so skip it | |
| 914 | cxIteratorNext(min_iter); | |
| 915 | } else if (d < 0) { | |
| 916 | // subtrahend is smaller than minuend, | |
| 917 | // check the next element | |
| 918 | cxIteratorNext(sub_iter); | |
| 919 | } else { | |
| 920 | // subtrahend is larger than the dst element, | |
| 921 | // clone the minuend and advance | |
| 922 | void **dst_mem = cxListEmplace(dst); | |
| 923 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | |
| 924 | void* dst_ptr = clone_func(target, min_elem, clone_allocator, data); | |
| 925 | if (dst_ptr == NULL) { | |
| 926 | cx_list_pop_uninitialized_elements(dst, 1); | |
| 927 | return 1; | |
| 928 | } | |
| 929 | if (cxCollectionStoresPointers(dst)) { | |
| 930 | *dst_mem = dst_ptr; | |
| 931 | } | |
| 932 | cxIteratorNext(min_iter); | |
| 933 | } | |
| 934 | } | |
| 935 | ||
| 936 | // if dst was empty, it is now guaranteed to be sorted | |
| 937 | dst->collection.sorted = dst_was_empty; | |
| 938 | } else { | |
| 939 | CxIterator min_iter = cxListIterator(minuend); | |
| 940 | cx_foreach(void *, elem, min_iter) { | |
| 941 | if (cxListContains(subtrahend, elem)) { | |
| 942 | continue; | |
| 943 | } | |
| 944 | void **dst_mem = cxListEmplace(dst); | |
| 945 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | |
| 946 | void* dst_ptr = clone_func(target, elem, clone_allocator, data); | |
| 947 | if (dst_ptr == NULL) { | |
| 948 | cx_list_pop_uninitialized_elements(dst, 1); | |
| 949 | return 1; | |
| 950 | } | |
| 951 | if (cxCollectionStoresPointers(dst)) { | |
| 952 | *dst_mem = dst_ptr; | |
| 953 | } | |
| 954 | } | |
| 955 | } | |
| 956 | ||
| 957 | return 0; | |
| 958 | } | |
| 959 | ||
| 960 | int cxListIntersection(CxList *dst, | |
| 961 | const CxList *src, const CxList *other, | |
| 962 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { | |
| 963 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | |
| 964 | ||
| 965 | // optimize for sorted collections | |
| 966 | if (cxCollectionSorted(src) && cxCollectionSorted(other)) { | |
| 967 | bool dst_was_empty = cxCollectionSize(dst) == 0; | |
| 968 | ||
| 969 | CxIterator src_iter = cxListIterator(src); | |
| 970 | CxIterator other_iter = cxListIterator(other); | |
| 971 | while (cxIteratorValid(src_iter) && cxIteratorValid(other_iter)) { | |
| 972 | void *src_elem = cxIteratorCurrent(src_iter); | |
| 973 | void *other_elem = cxIteratorCurrent(other_iter); | |
| 974 | int d = src->collection.cmpfunc(src_elem, other_elem); | |
| 975 | if (d == 0) { | |
| 976 | // is contained, clone it | |
| 977 | void **dst_mem = cxListEmplace(dst); | |
| 978 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | |
| 979 | void* dst_ptr = clone_func(target, src_elem, clone_allocator, data); | |
| 980 | if (dst_ptr == NULL) { | |
| 981 | cx_list_pop_uninitialized_elements(dst, 1); | |
| 982 | return 1; | |
| 983 | } | |
| 984 | if (cxCollectionStoresPointers(dst)) { | |
| 985 | *dst_mem = dst_ptr; | |
| 986 | } | |
| 987 | cxIteratorNext(src_iter); | |
| 988 | } else if (d < 0) { | |
| 989 | // the other element is larger, skip the source element | |
| 990 | cxIteratorNext(src_iter); | |
| 991 | } else { | |
| 992 | // the source element is larger, try to find it in the other list | |
| 993 | cxIteratorNext(other_iter); | |
| 994 | } | |
| 995 | } | |
| 996 | ||
| 997 | // if dst was empty, it is now guaranteed to be sorted | |
| 998 | dst->collection.sorted = dst_was_empty; | |
| 999 | } else { | |
| 1000 | CxIterator src_iter = cxListIterator(src); | |
| 1001 | cx_foreach(void *, elem, src_iter) { | |
| 1002 | if (!cxListContains(other, elem)) { | |
| 1003 | continue; | |
| 1004 | } | |
| 1005 | void **dst_mem = cxListEmplace(dst); | |
| 1006 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | |
| 1007 | void* dst_ptr = clone_func(target, elem, clone_allocator, data); | |
| 1008 | if (dst_ptr == NULL) { | |
| 1009 | cx_list_pop_uninitialized_elements(dst, 1); | |
| 1010 | return 1; | |
| 1011 | } | |
| 1012 | if (cxCollectionStoresPointers(dst)) { | |
| 1013 | *dst_mem = dst_ptr; | |
| 1014 | } | |
| 1015 | } | |
| 1016 | } | |
| 1017 | ||
| 1018 | return 0; | |
| 1019 | } | |
| 1020 | ||
| 1021 | int cxListUnion(CxList *dst, | |
| 1022 | const CxList *src, const CxList *other, | |
| 1023 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { | |
| 1024 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | |
| 1025 | ||
| 1026 | // optimize for sorted collections | |
| 1027 | if (cxCollectionSorted(src) && cxCollectionSorted(other)) { | |
| 1028 | bool dst_was_empty = cxCollectionSize(dst) == 0; | |
| 1029 | ||
| 1030 | CxIterator src_iter = cxListIterator(src); | |
| 1031 | CxIterator other_iter = cxListIterator(other); | |
| 1032 | while (cxIteratorValid(src_iter) || cxIteratorValid(other_iter)) { | |
| 23 | 1033 | void *src_elem = NULL, *other_elem = NULL; |
| 22 | 1034 | int d; |
| 1035 | if (!cxIteratorValid(src_iter)) { | |
| 1036 | other_elem = cxIteratorCurrent(other_iter); | |
| 1037 | d = 1; | |
| 1038 | } else if (!cxIteratorValid(other_iter)) { | |
| 1039 | src_elem = cxIteratorCurrent(src_iter); | |
| 1040 | d = -1; | |
| 1041 | } else { | |
| 1042 | src_elem = cxIteratorCurrent(src_iter); | |
| 1043 | other_elem = cxIteratorCurrent(other_iter); | |
| 1044 | d = src->collection.cmpfunc(src_elem, other_elem); | |
| 1045 | } | |
| 1046 | void *clone_from; | |
| 1047 | if (d < 0) { | |
| 1048 | // source element is smaller clone it | |
| 1049 | clone_from = src_elem; | |
| 1050 | cxIteratorNext(src_iter); | |
| 1051 | } else if (d == 0) { | |
| 1052 | // both elements are equal, clone from the source, skip other | |
| 1053 | clone_from = src_elem; | |
| 1054 | cxIteratorNext(src_iter); | |
| 1055 | cxIteratorNext(other_iter); | |
| 1056 | } else { | |
| 1057 | // the other element is smaller, clone it | |
| 1058 | clone_from = other_elem; | |
| 1059 | cxIteratorNext(other_iter); | |
| 1060 | } | |
| 1061 | void **dst_mem = cxListEmplace(dst); | |
| 1062 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | |
| 1063 | void* dst_ptr = clone_func(target, clone_from, clone_allocator, data); | |
| 1064 | if (dst_ptr == NULL) { | |
| 1065 | cx_list_pop_uninitialized_elements(dst, 1); | |
| 1066 | return 1; | |
| 1067 | } | |
| 1068 | if (cxCollectionStoresPointers(dst)) { | |
| 1069 | *dst_mem = dst_ptr; | |
| 1070 | } | |
| 1071 | } | |
| 1072 | ||
| 1073 | // if dst was empty, it is now guaranteed to be sorted | |
| 1074 | dst->collection.sorted = dst_was_empty; | |
| 1075 | } else { | |
| 1076 | if (cxListClone(dst, src, clone_func, clone_allocator, data)) { | |
| 1077 | return 1; | |
| 1078 | } | |
| 1079 | CxIterator other_iter = cxListIterator(other); | |
| 1080 | cx_foreach(void *, elem, other_iter) { | |
| 1081 | if (cxListContains(src, elem)) { | |
| 1082 | continue; | |
| 1083 | } | |
| 1084 | void **dst_mem = cxListEmplace(dst); | |
| 1085 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | |
| 1086 | void* dst_ptr = clone_func(target, elem, clone_allocator, data); | |
| 1087 | if (dst_ptr == NULL) { | |
| 1088 | cx_list_pop_uninitialized_elements(dst, 1); | |
| 1089 | return 1; | |
| 1090 | } | |
| 1091 | if (cxCollectionStoresPointers(dst)) { | |
| 1092 | *dst_mem = dst_ptr; | |
| 1093 | } | |
| 1094 | } | |
| 1095 | } | |
| 1096 | ||
| 1097 | return 0; | |
| 1098 | } | |
| 1099 | ||
| 1100 | int cxListCloneSimple(CxList *dst, const CxList *src) { | |
| 1101 | return cxListClone(dst, src, use_simple_clone_func(src)); | |
| 1102 | } | |
| 1103 | ||
| 1104 | int cxListDifferenceSimple(CxList *dst, const CxList *minuend, const CxList *subtrahend) { | |
| 1105 | return cxListDifference(dst, minuend, subtrahend, use_simple_clone_func(minuend)); | |
| 1106 | } | |
| 1107 | ||
| 1108 | int cxListIntersectionSimple(CxList *dst, const CxList *src, const CxList *other) { | |
| 1109 | return cxListIntersection(dst, src, other, use_simple_clone_func(src)); | |
| 1110 | } | |
| 1111 | ||
| 1112 | int cxListUnionSimple(CxList *dst, const CxList *src, const CxList *other) { | |
| 1113 | return cxListUnion(dst, src, other, use_simple_clone_func(src)); | |
| 1114 | } | |
| 1115 | ||
| 1116 | int cxListReserve(CxList *list, size_t capacity) { | |
| 1117 | if (list->cl->change_capacity == NULL) { | |
| 1118 | return 0; | |
| 1119 | } | |
| 1120 | if (capacity <= cxCollectionSize(list)) { | |
| 1121 | return 0; | |
| 1122 | } | |
| 1123 | return list->cl->change_capacity(list, capacity); | |
| 1124 | } | |
| 1125 | ||
| 1126 | int cxListShrink(CxList *list) { | |
| 1127 | if (list->cl->change_capacity == NULL) { | |
| 1128 | return 0; | |
| 1129 | } | |
| 1130 | return list->cl->change_capacity(list, cxCollectionSize(list)); | |
| 1131 | } |