Sun, 07 Sep 2025 17:08:26 +0200
implement a patch function that results in (almost) always calling the correct destructors
relates to #461
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2025 Mike Becker, Olaf Wintermann All rights reserved. |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | #include "cx/kv_list.h" |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
30 | #include "cx/hash_map.h" |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
31 | #include "cx/linked_list.h" |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
32 | |
1360
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
33 | #include <string.h> |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
34 | |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
35 | typedef struct cx_kv_list_s cx_kv_list; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
36 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
37 | struct cx_kv_list_map_s { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
38 | struct cx_hash_map_s map_base; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
39 | /** Back-reference to the list. */ |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
40 | cx_kv_list *list; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
41 | }; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
42 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
43 | /** The list aspect (must have the same layout as the normal linked list). */ |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
44 | struct cx_kv_list_list_s { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
45 | struct cx_list_s list_base; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
46 | void *begin; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
47 | void *end; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
48 | }; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
49 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
50 | struct cx_kv_list_s { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
51 | struct cx_kv_list_list_s list; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
52 | /** The lookup map - stores pointers to the nodes. */ |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
53 | struct cx_kv_list_map_s *map; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
54 | const cx_list_class *list_methods; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
55 | const cx_map_class *map_methods; |
1365
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
56 | cx_destructor_func list_destr; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
57 | cx_destructor_func2 list_destr2; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
58 | void *list_destr_data; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
59 | cx_destructor_func map_destr; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
60 | cx_destructor_func2 map_destr2; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
61 | void *map_destr_data; |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
62 | }; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
63 | |
1365
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
64 | static void cx_kv_list_destructor_wrapper_list(void *list_ptr, void *elem) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
65 | const cx_kv_list *kv_list = list_ptr; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
66 | // list destructor is already called with proper deref of the elem |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
67 | if (kv_list->list_destr) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
68 | kv_list->list_destr(elem); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
69 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
70 | if (kv_list->list_destr2) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
71 | kv_list->list_destr2(kv_list->list_destr_data, elem); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
72 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
73 | if (kv_list->map_destr) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
74 | kv_list->map_destr(elem); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
75 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
76 | if (kv_list->map_destr2) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
77 | kv_list->map_destr2(kv_list->map_destr_data, elem); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
78 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
79 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
80 | |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
81 | static void cx_kv_list_destructor_wrapper_map(void *list_ptr, void *node_data) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
82 | const cx_kv_list *kv_list = list_ptr; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
83 | // the elem called with a map destructor is a pointer to the node |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
84 | // we need to deref the elem accordingly |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
85 | void *elem = kv_list->list.list_base.collection.store_pointer ? *(void**)node_data : node_data; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
86 | if (kv_list->list_destr) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
87 | kv_list->list_destr(elem); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
88 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
89 | if (kv_list->list_destr2) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
90 | kv_list->list_destr2(kv_list->list_destr_data, elem); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
91 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
92 | if (kv_list->map_destr) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
93 | kv_list->map_destr(elem); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
94 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
95 | if (kv_list->map_destr2) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
96 | kv_list->map_destr2(kv_list->map_destr_data, elem); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
97 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
98 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
99 | |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
100 | static void cx_kv_list_update_destructors(cx_kv_list *list) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
101 | // we copy the destructors to our custom fields and register |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
102 | // an own destructor function which invokes all these |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
103 | if (list->list.list_base.collection.simple_destructor != NULL) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
104 | list->list_destr = list->list.list_base.collection.simple_destructor; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
105 | list->list.list_base.collection.simple_destructor = NULL; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
106 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
107 | if (list->list.list_base.collection.advanced_destructor != cx_kv_list_destructor_wrapper_list) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
108 | list->list_destr2 = list->list.list_base.collection.advanced_destructor; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
109 | list->list_destr_data = list->list.list_base.collection.destructor_data; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
110 | list->list.list_base.collection.advanced_destructor = cx_kv_list_destructor_wrapper_list; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
111 | list->list.list_base.collection.destructor_data = list; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
112 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
113 | if (list->map->map_base.base.collection.simple_destructor != NULL) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
114 | list->map_destr = list->map->map_base.base.collection.simple_destructor; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
115 | list->map->map_base.base.collection.simple_destructor = NULL; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
116 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
117 | if (list->map->map_base.base.collection.advanced_destructor != cx_kv_list_destructor_wrapper_map) { |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
118 | list->map_destr2 = list->map->map_base.base.collection.advanced_destructor; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
119 | list->map_destr_data = list->map->map_base.base.collection.destructor_data; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
120 | list->map->map_base.base.collection.advanced_destructor = cx_kv_list_destructor_wrapper_map; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
121 | list->map->map_base.base.collection.destructor_data = list; |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
122 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
123 | } |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
124 | |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
125 | static void cx_kvl_deallocate(struct cx_list_s *list) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
126 | cx_kv_list *kv_list = (cx_kv_list*)list; |
1365
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
127 | // patch the destructors |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
128 | cx_kv_list_update_destructors(kv_list); |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
129 | // free the map first |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
130 | kv_list->map_methods->deallocate(&kv_list->map->map_base.base); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
131 | kv_list->list_methods->deallocate(list); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
132 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
133 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
134 | static void *cx_kvl_insert_element( |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
135 | struct cx_list_s *list, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
136 | size_t index, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
137 | const void *data |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
138 | ) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
139 | cx_kv_list *kv_list = (cx_kv_list*)list; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
140 | // TODO: trick the base method by adding the required space for the key to the elem_size |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
141 | return kv_list->list_methods->insert_element(list, index, data); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
142 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
143 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
144 | static size_t cx_kvl_insert_array( |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
145 | struct cx_list_s *list, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
146 | size_t index, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
147 | const void *data, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
148 | size_t n |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
149 | ) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
150 | cx_kv_list *kv_list = (cx_kv_list*)list; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
151 | // TODO: trick the base method by adding the required space for the key to the elem_size |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
152 | return kv_list->list_methods->insert_array(list, index, data, n); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
153 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
154 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
155 | static size_t cx_kvl_insert_sorted( |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
156 | struct cx_list_s *list, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
157 | const void *sorted_data, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
158 | size_t n |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
159 | ) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
160 | cx_kv_list *kv_list = (cx_kv_list*)list; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
161 | // TODO: trick the base method by adding the required space for the key to the elem_size |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
162 | return kv_list->list_methods->insert_sorted(list, sorted_data, n); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
163 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
164 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
165 | static int cx_kvl_insert_iter( |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
166 | struct cx_iterator_s *iter, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
167 | const void *elem, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
168 | int prepend |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
169 | ) { |
1362
d886626a9526
add several fixme and todo comments regarding invoking destructors
Mike Becker <universe@uap-core.de>
parents:
1361
diff
changeset
|
170 | cx_kv_list *kv_list = iter->src_handle.m; |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
171 | // TODO: trick the base method by adding the required space for the key to the elem_size |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
172 | return kv_list->list_methods->insert_iter(iter, elem, prepend); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
173 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
174 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
175 | static size_t cx_kvl_remove( |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
176 | struct cx_list_s *list, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
177 | size_t index, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
178 | size_t num, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
179 | void *targetbuf |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
180 | ) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
181 | cx_kv_list *kv_list = (cx_kv_list*)list; |
1365
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
182 | // patch the destructors |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
183 | cx_kv_list_update_destructors(kv_list); |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
184 | // TODO: always use the target buffer to get the element first, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
185 | // then obtain the key, remove it from the map, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
186 | // and finally call any destructors manually |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
187 | return kv_list->list_methods->remove(list, index, num, targetbuf); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
188 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
189 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
190 | static void cx_kvl_clear(struct cx_list_s *list) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
191 | cx_kv_list *kv_list = (cx_kv_list*)list; |
1365
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
192 | // patch the destructors |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
193 | // but remove the wrapper from the map to avoid calling it twice |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
194 | cx_kv_list_update_destructors(kv_list); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
195 | cxDefineAdvancedDestructor(&kv_list->map->map_base.base, NULL, NULL); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
196 | // clear the list |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
197 | kv_list->list_methods->clear(list); |
1365
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
198 | // then clear the map |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
199 | cxMapClear(&kv_list->map->map_base.base); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
200 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
201 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
202 | static int cx_kvl_swap( |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
203 | struct cx_list_s *list, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
204 | size_t i, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
205 | size_t j |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
206 | ) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
207 | cx_kv_list *kv_list = (cx_kv_list*)list; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
208 | return kv_list->list_methods->swap(list, i, j); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
209 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
210 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
211 | static void *cx_kvl_at( |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
212 | const struct cx_list_s *list, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
213 | size_t index |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
214 | ) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
215 | const cx_kv_list *kv_list = (const cx_kv_list*)list; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
216 | return kv_list->list_methods->at(list, index); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
217 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
218 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
219 | static size_t cx_kvl_find_remove( |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
220 | struct cx_list_s *list, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
221 | const void *elem, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
222 | bool remove |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
223 | ) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
224 | cx_kv_list *kv_list = (cx_kv_list*)list; |
1365
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
225 | cx_kv_list_update_destructors(kv_list); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
226 | // TODO: implement removal of the key in the map |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
227 | return kv_list->list_methods->find_remove(list, elem, remove); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
228 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
229 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
230 | static void cx_kvl_sort(struct cx_list_s *list) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
231 | cx_kv_list *kv_list = (cx_kv_list*)list; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
232 | kv_list->list_methods->sort(list); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
233 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
234 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
235 | static void cx_kvl_reverse(struct cx_list_s *list) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
236 | cx_kv_list *kv_list = (cx_kv_list*)list; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
237 | kv_list->list_methods->reverse(list); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
238 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
239 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
240 | static struct cx_iterator_s cx_kvl_iterator( |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
241 | const struct cx_list_s *list, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
242 | size_t index, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
243 | bool backward |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
244 | ) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
245 | const cx_kv_list *kv_list = (const cx_kv_list*)list; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
246 | // TODO: cannot really forward, because mutating iterators must be able to remove the element |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
247 | return kv_list->list_methods->iterator(list, index, backward); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
248 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
249 | |
1358
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
250 | static void cx_kvl_map_deallocate(struct cx_map_s *map) { |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
251 | cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list; |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
252 | kv_list->map_methods->deallocate(map); |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
253 | kv_list->list_methods->deallocate(&kv_list->list.list_base); |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
254 | } |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
255 | |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
256 | static void cx_kvl_map_clear(struct cx_map_s *map) { |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
257 | cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list; |
1365
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
258 | cx_kv_list_update_destructors(kv_list); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
259 | // TODO: iterate through the map elements, unlink them from the list, and free them |
1358
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
260 | kv_list->map_methods->clear(map); |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
261 | } |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
262 | |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
263 | static void *cx_kvl_map_put(CxMap *map, CxHashKey key, void *value) { |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
264 | cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list; |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
265 | // insert the data into the list first (assume that insertion destroys the sorted property) |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
266 | kv_list->list.list_base.collection.sorted = false; |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
267 | // TODO: use the same trick as above to increase the element size temporarily to add the key to the data |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
268 | void *node_data = kv_list->list_methods->insert_element( |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
269 | &kv_list->list.list_base, kv_list->list.list_base.collection.size, value); |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
270 | if (node_data == NULL) return NULL; // LCOV_EXCL_LINE |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
271 | // then insert the key into the map, referring to the node data |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
272 | // TODO: check if we still get a correct pointer when the list is storing pointers |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
273 | return kv_list->map_methods->put(map, key, node_data); |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
274 | } |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
275 | |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
276 | void *cx_kvl_map_get(const CxMap *map, CxHashKey key) { |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
277 | cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list; |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
278 | return kv_list->map_methods->get(map, key); |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
279 | } |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
280 | |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
281 | int cx_kvl_map_remove(CxMap *map, CxHashKey key, void *targetbuf) { |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
282 | cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list; |
1365
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
283 | |
1360
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
284 | void *node_data; |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
285 | if (kv_list->map_methods->remove(map, key, &node_data)) { |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
286 | return 1; |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
287 | } |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
288 | // we cannot just call a list method (because we don't have the index) |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
289 | // and tbh. we also don't want to (because it's not performant when we |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
290 | // can have the node ptr directly instead) |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
291 | // therefore, we re-implement the logic ourselves |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
292 | |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
293 | // check if the outside caller want's us to return or to destroy the element |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
294 | if (targetbuf == NULL) { |
1365
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
295 | // patch the destructors and invoke them through the wrapper |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
296 | cx_kv_list_update_destructors(kv_list); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
297 | cx_invoke_advanced_destructor(&kv_list->list.list_base, node_data); |
1360
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
298 | } else { |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
299 | // copy the element to the target buffer |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
300 | memcpy(targetbuf, node_data, kv_list->list.list_base.collection.elem_size); |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
301 | } |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
302 | |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
303 | // calculate the address of the node |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
304 | void *node_ptr = (char*)node_data - 2*sizeof(void*); |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
305 | |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
306 | // unlink the node |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
307 | cx_linked_list_remove( |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
308 | &kv_list->list.begin, |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
309 | &kv_list->list.end, |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
310 | 0, |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
311 | sizeof(void*), |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
312 | node_ptr |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
313 | ); |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
314 | |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
315 | // decrement the list's size |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
316 | kv_list->list.list_base.collection.size--; |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
317 | |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
318 | // deallocate the node |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
319 | cxFree(kv_list->list.list_base.collection.allocator, node_ptr); |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
320 | |
8b29d732f97b
implement cx_kvl_map_remove()
Mike Becker <universe@uap-core.de>
parents:
1358
diff
changeset
|
321 | return 0; |
1358
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
322 | } |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
323 | |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
324 | CxMapIterator cx_kvl_map_iterator(const CxMap *map, enum cx_map_iterator_type type) { |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
325 | cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list; |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
326 | return kv_list->map_methods->iterator(map, type); |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
327 | } |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
328 | |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
329 | static cx_list_class cx_kv_list_class = { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
330 | cx_kvl_deallocate, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
331 | cx_kvl_insert_element, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
332 | cx_kvl_insert_array, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
333 | cx_kvl_insert_sorted, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
334 | cx_kvl_insert_iter, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
335 | cx_kvl_remove, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
336 | cx_kvl_clear, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
337 | cx_kvl_swap, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
338 | cx_kvl_at, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
339 | cx_kvl_find_remove, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
340 | cx_kvl_sort, |
1352
8428516137dd
make comparisons between kv_list and linked_list optimizable
Mike Becker <universe@uap-core.de>
parents:
1350
diff
changeset
|
341 | NULL, |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
342 | cx_kvl_reverse, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
343 | cx_kvl_iterator, |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
344 | }; |
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
345 | |
1358
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
346 | static cx_map_class cx_kv_map_class = { |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
347 | cx_kvl_map_deallocate, |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
348 | cx_kvl_map_clear, |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
349 | cx_kvl_map_put, |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
350 | cx_kvl_map_get, |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
351 | cx_kvl_map_remove, |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
352 | cx_kvl_map_iterator, |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
353 | }; |
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
354 | |
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
355 | CxList *cxKvListCreate( |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
356 | const CxAllocator *allocator, |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
357 | cx_compare_func comparator, |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
358 | size_t elem_size |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
359 | ) { |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
360 | if (allocator == NULL) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
361 | allocator = cxDefaultAllocator; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
362 | } |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
363 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
364 | // create a normal linked list and a normal hash map, first |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
365 | CxList *list = cxLinkedListCreate(allocator, comparator, elem_size); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
366 | if (list == NULL) return NULL; // LCOV_EXCL_LINE |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
367 | CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 0); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
368 | if (map == NULL) { // LCOV_EXCL_START |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
369 | cxListFree(list); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
370 | return NULL; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
371 | } // LCOV_EXCL_STOP |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
372 | |
1352
8428516137dd
make comparisons between kv_list and linked_list optimizable
Mike Becker <universe@uap-core.de>
parents:
1350
diff
changeset
|
373 | // patch the kv-list class with the compare function of the linked list |
8428516137dd
make comparisons between kv_list and linked_list optimizable
Mike Becker <universe@uap-core.de>
parents:
1350
diff
changeset
|
374 | // this allows cxListCompare() to optimize comparisons between linked lists and kv-list |
8428516137dd
make comparisons between kv_list and linked_list optimizable
Mike Becker <universe@uap-core.de>
parents:
1350
diff
changeset
|
375 | cx_kv_list_class.compare = list->cl->compare; |
8428516137dd
make comparisons between kv_list and linked_list optimizable
Mike Becker <universe@uap-core.de>
parents:
1350
diff
changeset
|
376 | |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
377 | // reallocate the map to add memory for the list back-reference |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
378 | struct cx_kv_list_map_s *kv_map = cxRealloc(allocator, map, sizeof(struct cx_kv_list_map_s)); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
379 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
380 | // reallocate the list to add memory for storing the metadata |
1358
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
381 | cx_kv_list *kv_list = cxRealloc(allocator, list, sizeof(struct cx_kv_list_s)); |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
382 | |
1365
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
383 | // zero the custom destructor information |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
384 | memset((char*)kv_list + offsetof(cx_kv_list, list_destr), 0, sizeof(void*)*6); |
e4135791687e
implement a patch function that results in (almost) always calling the correct destructors
Mike Becker <universe@uap-core.de>
parents:
1362
diff
changeset
|
385 | |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
386 | // if any of the reallocations failed, we bail out |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
387 | if (kv_map != NULL && kv_list != NULL) { |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
388 | map = (CxMap*) kv_map; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
389 | list = (CxList*) kv_list; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
390 | } else { // LCOV_EXCL_START |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
391 | cxListFree(list); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
392 | cxMapFree(map); |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
393 | return NULL; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
394 | } // LCOV_EXCL_STOP |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
395 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
396 | // combine the list and the map aspect |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
397 | kv_list->map = kv_map; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
398 | kv_map->list = kv_list; |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
399 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
400 | // remember the base methods and override them |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
401 | kv_list->map_methods = map->cl; |
1358
dda9c330e3e5
make test_kv_list_map_put() pass
Mike Becker <universe@uap-core.de>
parents:
1353
diff
changeset
|
402 | map->cl = &cx_kv_map_class; |
1353
5a13b9c1c57b
fix that the wrong vtable is patched when CX_STORE_POINTERS is used
Mike Becker <universe@uap-core.de>
parents:
1352
diff
changeset
|
403 | if (list->climpl == NULL) { |
5a13b9c1c57b
fix that the wrong vtable is patched when CX_STORE_POINTERS is used
Mike Becker <universe@uap-core.de>
parents:
1352
diff
changeset
|
404 | kv_list->list_methods = list->cl; |
5a13b9c1c57b
fix that the wrong vtable is patched when CX_STORE_POINTERS is used
Mike Becker <universe@uap-core.de>
parents:
1352
diff
changeset
|
405 | list->cl = &cx_kv_list_class; |
5a13b9c1c57b
fix that the wrong vtable is patched when CX_STORE_POINTERS is used
Mike Becker <universe@uap-core.de>
parents:
1352
diff
changeset
|
406 | } else { |
5a13b9c1c57b
fix that the wrong vtable is patched when CX_STORE_POINTERS is used
Mike Becker <universe@uap-core.de>
parents:
1352
diff
changeset
|
407 | kv_list->list_methods = list->climpl; |
5a13b9c1c57b
fix that the wrong vtable is patched when CX_STORE_POINTERS is used
Mike Becker <universe@uap-core.de>
parents:
1352
diff
changeset
|
408 | list->climpl = &cx_kv_list_class; |
5a13b9c1c57b
fix that the wrong vtable is patched when CX_STORE_POINTERS is used
Mike Becker <universe@uap-core.de>
parents:
1352
diff
changeset
|
409 | } |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
410 | |
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
411 | return list; |
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
412 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
413 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
414 | CxMap *cxKvListCreateAsMap( |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
415 | const CxAllocator *allocator, |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
416 | cx_compare_func comparator, |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
417 | size_t elem_size |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
418 | ) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
419 | CxList *list = cxKvListCreate(allocator, comparator, elem_size); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
420 | return list == NULL ? NULL : cxKvListAsMap(list); |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
421 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
422 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
423 | CxList *cxKvListAsList(CxMap *map) { |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
424 | return &((struct cx_kv_list_map_s*)map)->list->list.list_base; |
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
425 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
426 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
427 | CxMap *cxKvListAsMap(CxList *list) { |
1350
189756516eaa
implement kv-list to a point where it correctly behaves like a list
Mike Becker <universe@uap-core.de>
parents:
1348
diff
changeset
|
428 | return &((cx_kv_list*)list)->map->map_base.base; |
1348
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
429 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
430 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
431 | int cx_kv_list_set_key(CxList *list, size_t index, CxHashKey key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
432 | return -1; |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
433 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
434 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
435 | int cx_kv_list_remove_key(CxList *list, size_t index, CxHashKey key) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
436 | return -1; |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
437 | } |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
438 | |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
439 | int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value) { |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
440 | return -1; |
a1da355ed3b8
roll out the function stubs for the kv-list
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
441 | } |