Mon, 03 Nov 2025 19:55:04 +0100
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
| 
706
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
1 | /* | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
3 | * | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
4 | * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved. | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
5 | * | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
6 | * Redistribution and use in source and binary forms, with or without | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
7 | * modification, are permitted provided that the following conditions are met: | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
8 | * | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
9 | * 1. Redistributions of source code must retain the above copyright | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
10 | * notice, this list of conditions and the following disclaimer. | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
11 | * | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
12 | * 2. Redistributions in binary form must reproduce the above copyright | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
13 | * notice, this list of conditions and the following disclaimer in the | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
14 | * documentation and/or other materials provided with the distribution. | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
15 | * | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
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 | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
26 | * POSSIBILITY OF SUCH DAMAGE. | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
27 | */ | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
28 | |
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
29 | #include "cx/map.h" | 
| 
709
 
1e8ba59e7911
simplify map class structure
 
Mike Becker <universe@uap-core.de> 
parents: 
706 
diff
changeset
 | 
30 | #include <string.h> | 
| 
706
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
31 | |
| 
1445
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
32 | #include "cx/list.h" | 
| 
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
33 | |
| 
706
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
34 | // <editor-fold desc="empty map implementation"> | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
35 | |
| 
985
 
68754c7de906
major refactoring of attributes
 
Mike Becker <universe@uap-core.de> 
parents: 
890 
diff
changeset
 | 
36 | static void cx_empty_map_noop(cx_attr_unused CxMap *map) { | 
| 
706
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
37 | // this is a noop, but MUST be implemented | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
38 | } | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
39 | |
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
40 | static void *cx_empty_map_get( | 
| 
985
 
68754c7de906
major refactoring of attributes
 
Mike Becker <universe@uap-core.de> 
parents: 
890 
diff
changeset
 | 
41 | cx_attr_unused const CxMap *map, | 
| 
 
68754c7de906
major refactoring of attributes
 
Mike Becker <universe@uap-core.de> 
parents: 
890 
diff
changeset
 | 
42 | cx_attr_unused CxHashKey key | 
| 
706
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
43 | ) { | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
44 | return NULL; | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
45 | } | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
46 | |
| 
985
 
68754c7de906
major refactoring of attributes
 
Mike Becker <universe@uap-core.de> 
parents: 
890 
diff
changeset
 | 
47 | static bool cx_empty_map_iter_valid(cx_attr_unused const void *iter) { | 
| 
706
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
48 | return false; | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
49 | } | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
50 | |
| 
1115
 
6db21dee4929
create specialized map iterators - fixes #550
 
Mike Becker <universe@uap-core.de> 
parents: 
1109 
diff
changeset
 | 
51 | static CxMapIterator cx_empty_map_iterator( | 
| 
890
 
54565fd74e74
move all const keywords to the west - fixes #426
 
Mike Becker <universe@uap-core.de> 
parents: 
854 
diff
changeset
 | 
52 | const struct cx_map_s *map, | 
| 
985
 
68754c7de906
major refactoring of attributes
 
Mike Becker <universe@uap-core.de> 
parents: 
890 
diff
changeset
 | 
53 | cx_attr_unused enum cx_map_iterator_type type | 
| 
709
 
1e8ba59e7911
simplify map class structure
 
Mike Becker <universe@uap-core.de> 
parents: 
706 
diff
changeset
 | 
54 | ) { | 
| 
1115
 
6db21dee4929
create specialized map iterators - fixes #550
 
Mike Becker <universe@uap-core.de> 
parents: 
1109 
diff
changeset
 | 
55 | CxMapIterator iter = {0}; | 
| 
1429
 
6e0c3a8a914a
remove the concept of "mutating iterators" - resolves #579
 
Mike Becker <universe@uap-core.de> 
parents: 
1426 
diff
changeset
 | 
56 | iter.map = (CxMap*) map; | 
| 
854
 
fe0d69d72bcd
fix members inherited by macro or include are not documented
 
Mike Becker <universe@uap-core.de> 
parents: 
853 
diff
changeset
 | 
57 | iter.base.valid = cx_empty_map_iter_valid; | 
| 
706
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
58 | return iter; | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
59 | } | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
60 | |
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
61 | static struct cx_map_class_s cx_empty_map_class = { | 
| 
709
 
1e8ba59e7911
simplify map class structure
 
Mike Becker <universe@uap-core.de> 
parents: 
706 
diff
changeset
 | 
62 | cx_empty_map_noop, | 
| 
 
1e8ba59e7911
simplify map class structure
 
Mike Becker <universe@uap-core.de> 
parents: 
706 
diff
changeset
 | 
63 | cx_empty_map_noop, | 
| 
 
1e8ba59e7911
simplify map class structure
 
Mike Becker <universe@uap-core.de> 
parents: 
706 
diff
changeset
 | 
64 | NULL, | 
| 
 
1e8ba59e7911
simplify map class structure
 
Mike Becker <universe@uap-core.de> 
parents: 
706 
diff
changeset
 | 
65 | cx_empty_map_get, | 
| 
 
1e8ba59e7911
simplify map class structure
 
Mike Becker <universe@uap-core.de> 
parents: 
706 
diff
changeset
 | 
66 | NULL, | 
| 
 
1e8ba59e7911
simplify map class structure
 
Mike Becker <universe@uap-core.de> 
parents: 
706 
diff
changeset
 | 
67 | cx_empty_map_iterator | 
| 
706
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
68 | }; | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
69 | |
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
70 | CxMap cx_empty_map = { | 
| 
1163
 
68ff0839bc6a
optimize cx_arl_find_remove for sorted arrays - fixes #547
 
Mike Becker <universe@uap-core.de> 
parents: 
1115 
diff
changeset
 | 
71 | { | 
| 
 
68ff0839bc6a
optimize cx_arl_find_remove for sorted arrays - fixes #547
 
Mike Becker <universe@uap-core.de> 
parents: 
1115 
diff
changeset
 | 
72 | NULL, | 
| 
 
68ff0839bc6a
optimize cx_arl_find_remove for sorted arrays - fixes #547
 
Mike Becker <universe@uap-core.de> 
parents: 
1115 
diff
changeset
 | 
73 | NULL, | 
| 
 
68ff0839bc6a
optimize cx_arl_find_remove for sorted arrays - fixes #547
 
Mike Becker <universe@uap-core.de> 
parents: 
1115 
diff
changeset
 | 
74 | 0, | 
| 
 
68ff0839bc6a
optimize cx_arl_find_remove for sorted arrays - fixes #547
 
Mike Becker <universe@uap-core.de> 
parents: 
1115 
diff
changeset
 | 
75 | 0, | 
| 
 
68ff0839bc6a
optimize cx_arl_find_remove for sorted arrays - fixes #547
 
Mike Becker <universe@uap-core.de> 
parents: 
1115 
diff
changeset
 | 
76 | NULL, | 
| 
 
68ff0839bc6a
optimize cx_arl_find_remove for sorted arrays - fixes #547
 
Mike Becker <universe@uap-core.de> 
parents: 
1115 
diff
changeset
 | 
77 | NULL, | 
| 
 
68ff0839bc6a
optimize cx_arl_find_remove for sorted arrays - fixes #547
 
Mike Becker <universe@uap-core.de> 
parents: 
1115 
diff
changeset
 | 
78 | NULL, | 
| 
 
68ff0839bc6a
optimize cx_arl_find_remove for sorted arrays - fixes #547
 
Mike Becker <universe@uap-core.de> 
parents: 
1115 
diff
changeset
 | 
79 | false, | 
| 
 
68ff0839bc6a
optimize cx_arl_find_remove for sorted arrays - fixes #547
 
Mike Becker <universe@uap-core.de> 
parents: 
1115 
diff
changeset
 | 
80 | true | 
| 
 
68ff0839bc6a
optimize cx_arl_find_remove for sorted arrays - fixes #547
 
Mike Becker <universe@uap-core.de> 
parents: 
1115 
diff
changeset
 | 
81 | }, | 
| 
 
68ff0839bc6a
optimize cx_arl_find_remove for sorted arrays - fixes #547
 
Mike Becker <universe@uap-core.de> 
parents: 
1115 
diff
changeset
 | 
82 | &cx_empty_map_class | 
| 
706
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
83 | }; | 
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
84 | |
| 
709
 
1e8ba59e7911
simplify map class structure
 
Mike Becker <universe@uap-core.de> 
parents: 
706 
diff
changeset
 | 
85 | CxMap *const cxEmptyMap = &cx_empty_map; | 
| 
706
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
86 | |
| 
 
8c6edaccaef1
add empty map implementation - fixes #259
 
Mike Becker <universe@uap-core.de> 
parents:  
diff
changeset
 | 
87 | // </editor-fold> | 
| 
709
 
1e8ba59e7911
simplify map class structure
 
Mike Becker <universe@uap-core.de> 
parents: 
706 
diff
changeset
 | 
88 | |
| 
1426
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
89 | void cxMapClear(CxMap *map) { | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
90 | map->cl->clear(map); | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
91 | } | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
92 | |
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
93 | size_t cxMapSize(const CxMap *map) { | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
94 | return map->collection.size; | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
95 | } | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
96 | |
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
97 | CxMapIterator cxMapIteratorValues(const CxMap *map) { | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
98 | if (map == NULL) map = cxEmptyMap; | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
99 | return map->cl->iterator(map, CX_MAP_ITERATOR_VALUES); | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
100 | } | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
101 | |
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
102 | CxMapIterator cxMapIteratorKeys(const CxMap *map) { | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
103 | if (map == NULL) map = cxEmptyMap; | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
104 | return map->cl->iterator(map, CX_MAP_ITERATOR_KEYS); | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
105 | } | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
106 | |
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
107 | CxMapIterator cxMapIterator(const CxMap *map) { | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
108 | if (map == NULL) map = cxEmptyMap; | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
109 | return map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS); | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
110 | } | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
111 | |
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
112 | int cx_map_put(CxMap *map, CxHashKey key, void *value) { | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
113 | return map->cl->put(map, key, value) == NULL; | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
114 | } | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
115 | |
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
116 | void *cx_map_emplace(CxMap *map, CxHashKey key) { | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
117 | return map->cl->put(map, key, NULL); | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
118 | } | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
119 | |
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
120 | void *cx_map_get(const CxMap *map, CxHashKey key) { | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
121 | return map->cl->get(map, key); | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
122 | } | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
123 | |
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
124 | int cx_map_remove(CxMap *map, CxHashKey key, void *targetbuf) { | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
125 | return map->cl->remove(map, key, targetbuf); | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
126 | } | 
| 
 
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
 
Mike Becker <universe@uap-core.de> 
parents: 
1345 
diff
changeset
 | 
127 | |
| 
1109
 
89ec23988b88
free functions should not be inline in release mode - relates to #541
 
Mike Becker <universe@uap-core.de> 
parents: 
985 
diff
changeset
 | 
128 | void cxMapFree(CxMap *map) { | 
| 
 
89ec23988b88
free functions should not be inline in release mode - relates to #541
 
Mike Becker <universe@uap-core.de> 
parents: 
985 
diff
changeset
 | 
129 | if (map == NULL) return; | 
| 
 
89ec23988b88
free functions should not be inline in release mode - relates to #541
 
Mike Becker <universe@uap-core.de> 
parents: 
985 
diff
changeset
 | 
130 | map->cl->deallocate(map); | 
| 
 
89ec23988b88
free functions should not be inline in release mode - relates to #541
 
Mike Becker <universe@uap-core.de> 
parents: 
985 
diff
changeset
 | 
131 | } | 
| 
1437
 
dde4903c0fd7
untested draft of cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1429 
diff
changeset
 | 
132 | |
| 
1438
 
2ca9e03ceeec
add destruction of uninitialized entries on allocation failure to cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1437 
diff
changeset
 | 
133 | static void cx_map_remove_uninitialized_entry(CxMap *map, CxHashKey key) { | 
| 
 
2ca9e03ceeec
add destruction of uninitialized entries on allocation failure to cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1437 
diff
changeset
 | 
134 | cx_destructor_func destr_bak = map->collection.simple_destructor; | 
| 
 
2ca9e03ceeec
add destruction of uninitialized entries on allocation failure to cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1437 
diff
changeset
 | 
135 | cx_destructor_func2 destr2_bak = map->collection.advanced_destructor; | 
| 
 
2ca9e03ceeec
add destruction of uninitialized entries on allocation failure to cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1437 
diff
changeset
 | 
136 | map->collection.simple_destructor = NULL; | 
| 
 
2ca9e03ceeec
add destruction of uninitialized entries on allocation failure to cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1437 
diff
changeset
 | 
137 | map->collection.advanced_destructor = NULL; | 
| 
 
2ca9e03ceeec
add destruction of uninitialized entries on allocation failure to cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1437 
diff
changeset
 | 
138 | cxMapRemove(map, key); | 
| 
 
2ca9e03ceeec
add destruction of uninitialized entries on allocation failure to cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1437 
diff
changeset
 | 
139 | map->collection.simple_destructor = destr_bak; | 
| 
 
2ca9e03ceeec
add destruction of uninitialized entries on allocation failure to cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1437 
diff
changeset
 | 
140 | map->collection.advanced_destructor = destr2_bak; | 
| 
 
2ca9e03ceeec
add destruction of uninitialized entries on allocation failure to cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1437 
diff
changeset
 | 
141 | } | 
| 
 
2ca9e03ceeec
add destruction of uninitialized entries on allocation failure to cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1437 
diff
changeset
 | 
142 | |
| 
1444
 
dd9dcbb39c2f
make clone functions return int instead of size_t
 
Mike Becker <universe@uap-core.de> 
parents: 
1438 
diff
changeset
 | 
143 | int cxMapClone(CxMap *dst, const CxMap *src, cx_clone_func clone_func, | 
| 
1437
 
dde4903c0fd7
untested draft of cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1429 
diff
changeset
 | 
144 | const CxAllocator *clone_allocator, void *data) { | 
| 
1446
 
5732947cbcc2
default NULL allocator to cxDefaultAllocator
 
Mike Becker <universe@uap-core.de> 
parents: 
1445 
diff
changeset
 | 
145 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | 
| 
1437
 
dde4903c0fd7
untested draft of cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1429 
diff
changeset
 | 
146 | CxMapIterator src_iter = cxMapIterator(src); | 
| 
1449
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
147 | for (size_t i = 0; i < cxMapSize(src); i++) { | 
| 
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
148 | const CxMapEntry *entry = cxIteratorCurrent(src_iter); | 
| 
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
149 | void **dst_mem = cxMapEmplace(dst, *(entry->key)); | 
| 
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
150 | if (dst_mem == NULL) { | 
| 
1450
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
151 | return 1; // LCOV_EXCL_LINE | 
| 
1449
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
152 | } | 
| 
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
153 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | 
| 
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
154 | void *dst_ptr = clone_func(target, entry->value, clone_allocator, data); | 
| 
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
155 | if (dst_ptr == NULL) { | 
| 
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
156 | cx_map_remove_uninitialized_entry(dst, *(entry->key)); | 
| 
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
157 | return 1; | 
| 
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
158 | } | 
| 
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
159 | if (cxCollectionStoresPointers(dst)) { | 
| 
1437
 
dde4903c0fd7
untested draft of cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1429 
diff
changeset
 | 
160 | *dst_mem = dst_ptr; | 
| 
 
dde4903c0fd7
untested draft of cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1429 
diff
changeset
 | 
161 | } | 
| 
1449
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
162 | cxIteratorNext(src_iter); | 
| 
1437
 
dde4903c0fd7
untested draft of cxMapClone() - relates to #743
 
Mike Becker <universe@uap-core.de> 
parents: 
1429 
diff
changeset
 | 
163 | } | 
| 
1444
 
dd9dcbb39c2f
make clone functions return int instead of size_t
 
Mike Becker <universe@uap-core.de> 
parents: 
1438 
diff
changeset
 | 
164 | return 0; | 
| 
 
dd9dcbb39c2f
make clone functions return int instead of size_t
 
Mike Becker <universe@uap-core.de> 
parents: 
1438 
diff
changeset
 | 
165 | } | 
| 
1445
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
166 | |
| 
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
167 | int cxMapDifference(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend, | 
| 
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
168 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { | 
| 
1446
 
5732947cbcc2
default NULL allocator to cxDefaultAllocator
 
Mike Becker <universe@uap-core.de> 
parents: 
1445 
diff
changeset
 | 
169 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | 
| 
 
5732947cbcc2
default NULL allocator to cxDefaultAllocator
 
Mike Becker <universe@uap-core.de> 
parents: 
1445 
diff
changeset
 | 
170 | |
| 
1445
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
171 | CxMapIterator src_iter = cxMapIterator(minuend); | 
| 
1449
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
172 | cx_foreach(const CxMapEntry *, entry, src_iter) { | 
| 
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
173 | if (cxMapContains(subtrahend, *entry->key)) { | 
| 
1450
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
174 | continue; | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
175 | } | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
176 | void** dst_mem = cxMapEmplace(dst, *entry->key); | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
177 | if (dst_mem == NULL) { | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
178 | return 1; // LCOV_EXCL_LINE | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
179 | } | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
180 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
181 | void* dst_ptr = clone_func(target, entry->value, clone_allocator, data); | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
182 | if (dst_ptr == NULL) { | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
183 | cx_map_remove_uninitialized_entry(dst, *(entry->key)); | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
184 | return 1; | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
185 | } | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
186 | if (cxCollectionStoresPointers(dst)) { | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
187 | *dst_mem = dst_ptr; | 
| 
1445
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
188 | } | 
| 
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
189 | } | 
| 
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
190 | return 0; | 
| 
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
191 | } | 
| 
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
192 | |
| 
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
193 | int cxMapListDifference(CxMap *dst, const CxMap *src, const CxList *keys, | 
| 
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
194 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { | 
| 
1450
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
195 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
196 | |
| 
1445
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
197 | CxMapIterator src_iter = cxMapIterator(src); | 
| 
1449
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
198 | cx_foreach(const CxMapEntry *, entry, src_iter) { | 
| 
 
bbca398783ed
simplify clone implementations
 
Mike Becker <universe@uap-core.de> 
parents: 
1446 
diff
changeset
 | 
199 | if (cxListContains(keys, entry->key)) { | 
| 
1450
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
200 | continue; | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
201 | } | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
202 | void** dst_mem = cxMapEmplace(dst, *entry->key); | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
203 | if (dst_mem == NULL) { | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
204 | return 1; // LCOV_EXCL_LINE | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
205 | } | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
206 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
207 | void* dst_ptr = clone_func(target, entry->value, clone_allocator, data); | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
208 | if (dst_ptr == NULL) { | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
209 | cx_map_remove_uninitialized_entry(dst, *(entry->key)); | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
210 | return 1; | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
211 | } | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
212 | if (cxCollectionStoresPointers(dst)) { | 
| 
 
09a73312d5ec
add more test coverage for new map functions and fixes some issues
 
Mike Becker <universe@uap-core.de> 
parents: 
1449 
diff
changeset
 | 
213 | *dst_mem = dst_ptr; | 
| 
1445
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
214 | } | 
| 
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
215 | } | 
| 
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
216 | return 0; | 
| 
 
e8089a590b71
add implementations for map difference
 
Mike Becker <universe@uap-core.de> 
parents: 
1444 
diff
changeset
 | 
217 | } | 
| 
1467
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
218 | |
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
219 | int cxMapIntersection(CxMap *dst, const CxMap *src, const CxMap *other, | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
220 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
221 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
222 | |
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
223 | CxMapIterator src_iter = cxMapIterator(src); | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
224 | cx_foreach(const CxMapEntry *, entry, src_iter) { | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
225 | if (!cxMapContains(other, *entry->key)) { | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
226 | continue; | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
227 | } | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
228 | void** dst_mem = cxMapEmplace(dst, *entry->key); | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
229 | if (dst_mem == NULL) { | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
230 | return 1; // LCOV_EXCL_LINE | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
231 | } | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
232 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
233 | void* dst_ptr = clone_func(target, entry->value, clone_allocator, data); | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
234 | if (dst_ptr == NULL) { | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
235 | cx_map_remove_uninitialized_entry(dst, *(entry->key)); | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
236 | return 1; | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
237 | } | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
238 | if (cxCollectionStoresPointers(dst)) { | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
239 | *dst_mem = dst_ptr; | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
240 | } | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
241 | } | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
242 | return 0; | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
243 | } | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
244 | |
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
245 | int cxMapListIntersection(CxMap *dst, const CxMap *src, const CxList *keys, | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
246 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
247 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
248 | |
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
249 | CxMapIterator src_iter = cxMapIterator(src); | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
250 | cx_foreach(const CxMapEntry *, entry, src_iter) { | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
251 | if (!cxListContains(keys, entry->key)) { | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
252 | continue; | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
253 | } | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
254 | void** dst_mem = cxMapEmplace(dst, *entry->key); | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
255 | if (dst_mem == NULL) { | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
256 | return 1; // LCOV_EXCL_LINE | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
257 | } | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
258 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
259 | void* dst_ptr = clone_func(target, entry->value, clone_allocator, data); | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
260 | if (dst_ptr == NULL) { | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
261 | cx_map_remove_uninitialized_entry(dst, *(entry->key)); | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
262 | return 1; | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
263 | } | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
264 | if (cxCollectionStoresPointers(dst)) { | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
265 | *dst_mem = dst_ptr; | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
266 | } | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
267 | } | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
268 | return 0; | 
| 
 
bb6f04c35310
implements cxMapIntersection() and cxMapListIntersection() - resolves #555
 
Mike Becker <universe@uap-core.de> 
parents: 
1466 
diff
changeset
 | 
269 | } |