Tue, 18 Apr 2023 19:15:50 +0200
tweak rehash test to achieve missing coverage
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
d7f0b5a9a985
#189 declare basic map functions
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 |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | * \file map.h |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
30 | * \brief Interface for map implementations. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | * \author Mike Becker |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
32 | * \author Olaf Wintermann |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
33 | * \version 3.0 |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
34 | * \copyright 2-Clause BSD License |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
37 | #ifndef UCX_MAP_H |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | #define UCX_MAP_H |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
39 | |
681
502105523db7
fix common.h include problems - fixes #255
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
40 | #include "common.h" |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
669
diff
changeset
|
41 | #include "collection.h" |
563
69a83fad8a35
improve hash key handling
Mike Becker <universe@uap-core.de>
parents:
558
diff
changeset
|
42 | #include "hash_key.h" |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
43 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
44 | #ifdef __cplusplus |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
45 | extern "C" { |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
46 | #endif |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
47 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
48 | /** Type for the UCX map. */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
49 | typedef struct cx_map_s CxMap; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
50 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | /** Type for a map entry. */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | typedef struct cx_map_entry_s CxMapEntry; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
54 | /** Type for map class definitions. */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
55 | typedef struct cx_map_class_s cx_map_class; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
56 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
57 | /** Structure for the UCX map. */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | struct cx_map_s { |
685
2dd841e364af
add base collection members to map interface
Mike Becker <universe@uap-core.de>
parents:
681
diff
changeset
|
59 | CX_COLLECTION_MEMBERS |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
60 | /** The map class definition. */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
61 | cx_map_class *cl; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
62 | }; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
63 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
64 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
65 | * The class definition for arbitrary maps. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
66 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
67 | struct cx_map_class_s { |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
68 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
69 | * Deallocates the entire memory. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
70 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
71 | __attribute__((__nonnull__)) |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
72 | void (*destructor)(struct cx_map_s *map); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
73 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
74 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
75 | * Removes all elements. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
76 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
77 | __attribute__((__nonnull__)) |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
78 | void (*clear)(struct cx_map_s *map); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
79 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
80 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
81 | * Add or overwrite an element. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
82 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
83 | __attribute__((__nonnull__)) |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
84 | int (*put)( |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
85 | CxMap *map, |
563
69a83fad8a35
improve hash key handling
Mike Becker <universe@uap-core.de>
parents:
558
diff
changeset
|
86 | CxHashKey key, |
550
89b2a83728b1
#189 basic map implementation
Mike Becker <universe@uap-core.de>
parents:
549
diff
changeset
|
87 | void *value |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | ); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
89 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
90 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
91 | * Returns an element. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
92 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
93 | __attribute__((__nonnull__, __warn_unused_result__)) |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
94 | void *(*get)( |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
95 | CxMap const *map, |
563
69a83fad8a35
improve hash key handling
Mike Becker <universe@uap-core.de>
parents:
558
diff
changeset
|
96 | CxHashKey key |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
97 | ); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
98 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
99 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
100 | * Removes an element. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
101 | */ |
659
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
102 | __attribute__((__nonnull__)) |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
103 | void *(*remove)( |
550
89b2a83728b1
#189 basic map implementation
Mike Becker <universe@uap-core.de>
parents:
549
diff
changeset
|
104 | CxMap *map, |
686
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
105 | CxHashKey key, |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
106 | bool destroy |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | ); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
108 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
109 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
110 | * Iterator over the key/value pairs. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
111 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
112 | __attribute__((__nonnull__, __warn_unused_result__)) |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
113 | CxIterator (*iterator)(CxMap const *map); |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
114 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
115 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
116 | * Iterator over the keys. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
117 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
118 | __attribute__((__nonnull__, __warn_unused_result__)) |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
119 | CxIterator (*iterator_keys)(CxMap const *map); |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
120 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
121 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
122 | * Iterator over the values. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
123 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
124 | __attribute__((__nonnull__, __warn_unused_result__)) |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
125 | CxIterator (*iterator_values)(CxMap const *map); |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
126 | |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
127 | /** |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
128 | * Mutating iterator over the key/value pairs. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
129 | */ |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
130 | __attribute__((__nonnull__, __warn_unused_result__)) |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
131 | CxMutIterator (*mut_iterator)(CxMap *map); |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
132 | |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
133 | /** |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
134 | * Mutating iterator over the keys. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
135 | */ |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
136 | __attribute__((__nonnull__, __warn_unused_result__)) |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
137 | CxMutIterator (*mut_iterator_keys)(CxMap *map); |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
138 | |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
139 | /** |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
140 | * Mutating iterator over the values. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
141 | */ |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
142 | __attribute__((__nonnull__, __warn_unused_result__)) |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
143 | CxMutIterator (*mut_iterator_values)(CxMap *map); |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
144 | }; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
145 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
146 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
147 | * A map entry. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
148 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
149 | struct cx_map_entry_s { |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
150 | /** |
551
2946e13c89a4
#189 implement map iterators
Mike Becker <universe@uap-core.de>
parents:
550
diff
changeset
|
151 | * A pointer to the key. |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
152 | */ |
563
69a83fad8a35
improve hash key handling
Mike Becker <universe@uap-core.de>
parents:
558
diff
changeset
|
153 | CxHashKey const *key; |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
154 | /** |
551
2946e13c89a4
#189 implement map iterators
Mike Becker <universe@uap-core.de>
parents:
550
diff
changeset
|
155 | * A pointer to the value. |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
156 | */ |
551
2946e13c89a4
#189 implement map iterators
Mike Becker <universe@uap-core.de>
parents:
550
diff
changeset
|
157 | void *value; |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
158 | }; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
159 | |
658
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
160 | /** |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
161 | * Advises the map to store copies of the objects (default mode of operation). |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
162 | * |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
163 | * Retrieving objects from this map will yield pointers to the copies stored |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
164 | * within this list. |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
165 | * |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
166 | * @param map the map |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
167 | * @see cxMapStorePointers() |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
168 | */ |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
169 | __attribute__((__nonnull__)) |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
170 | static inline void cxMapStoreObjects(CxMap *map) { |
685
2dd841e364af
add base collection members to map interface
Mike Becker <universe@uap-core.de>
parents:
681
diff
changeset
|
171 | map->store_pointer = false; |
658
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
172 | } |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
173 | |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
174 | /** |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
175 | * Advises the map to only store pointers to the objects. |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
176 | * |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
177 | * Retrieving objects from this list will yield the original pointers stored. |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
178 | * |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
179 | * @note This function forcibly sets the element size to the size of a pointer. |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
180 | * Invoking this function on a non-empty map that already stores copies of |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
181 | * objects is undefined. |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
182 | * |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
183 | * @param map the map |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
184 | * @see cxMapStoreObjects() |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
185 | */ |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
186 | __attribute__((__nonnull__)) |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
187 | static inline void cxMapStorePointers(CxMap *map) { |
685
2dd841e364af
add base collection members to map interface
Mike Becker <universe@uap-core.de>
parents:
681
diff
changeset
|
188 | map->store_pointer = true; |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
669
diff
changeset
|
189 | map->item_size = sizeof(void *); |
658
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
190 | } |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
191 | |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
192 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
193 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
194 | * Deallocates the memory of the specified map. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
195 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
196 | * @param map the map to be destroyed |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
197 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
198 | __attribute__((__nonnull__)) |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
199 | static inline void cxMapDestroy(CxMap *map) { |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
200 | map->cl->destructor(map); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
201 | } |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
202 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
203 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
204 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
205 | * Clears a map by removing all elements. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
206 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
207 | * @param map the map to be cleared |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
208 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
209 | __attribute__((__nonnull__)) |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
210 | static inline void cxMapClear(CxMap *map) { |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
211 | map->cl->clear(map); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
212 | } |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
213 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
214 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
215 | * Puts a key/value-pair into the map. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
216 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
217 | * @param map the map |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
218 | * @param key the key |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
219 | * @param value the value |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
220 | * @return 0 on success, non-zero value on failure |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
221 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
222 | __attribute__((__nonnull__)) |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
223 | static inline int cxMapPut( |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
224 | CxMap *map, |
563
69a83fad8a35
improve hash key handling
Mike Becker <universe@uap-core.de>
parents:
558
diff
changeset
|
225 | CxHashKey key, |
550
89b2a83728b1
#189 basic map implementation
Mike Becker <universe@uap-core.de>
parents:
549
diff
changeset
|
226 | void *value |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
227 | ) { |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
228 | return map->cl->put(map, key, value); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
229 | } |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
230 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
231 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
232 | * Retrieves a value by using a key. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
233 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
234 | * @param map the map |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
235 | * @param key the key |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
236 | * @return the value |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
237 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
238 | __attribute__((__nonnull__, __warn_unused_result__)) |
553
8f7d3e7b5b93
fix missing static inline for map functions
Mike Becker <universe@uap-core.de>
parents:
551
diff
changeset
|
239 | static inline void *cxMapGet( |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
240 | CxMap const *map, |
563
69a83fad8a35
improve hash key handling
Mike Becker <universe@uap-core.de>
parents:
558
diff
changeset
|
241 | CxHashKey key |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
242 | ) { |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
243 | return map->cl->get(map, key); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
244 | } |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
245 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
246 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
247 | * Removes a key/value-pair from the map by using the key. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
248 | * |
686
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
249 | * Always invokes the destructor function, if any, on the removed element. |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
250 | * If this map is storing pointers and you just want to retrieve the pointer |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
251 | * without invoking the destructor, use cxMapRemoveAndGet(). |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
252 | * If you just want to detach the element from the map without invoking the |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
253 | * destructor or returning the element, use cxMapDetach(). |
659
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
254 | * |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
255 | * @param map the map |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
256 | * @param key the key |
659
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
257 | * @see cxMapRemoveAndGet() |
686
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
258 | * @see cxMapDetach() |
659
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
259 | */ |
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
260 | __attribute__((__nonnull__)) |
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
261 | static inline void cxMapRemove( |
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
262 | CxMap *map, |
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
263 | CxHashKey key |
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
264 | ) { |
686
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
265 | (void) map->cl->remove(map, key, true); |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
266 | } |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
267 | |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
268 | /** |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
269 | * Detaches a key/value-pair from the map by using the key |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
270 | * without invoking the destructor. |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
271 | * |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
272 | * In general, you should only use this function if the map does not own |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
273 | * the data and there is a valid reference to the data somewhere else |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
274 | * in the program. In all other cases it is prefarable to use |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
275 | * cxMapRemove() or cxMapRemoveAndGet(). |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
276 | * |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
277 | * @param map the map |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
278 | * @param key the key |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
279 | * @see cxMapRemove() |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
280 | * @see cxMapRemoveAndGet() |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
281 | */ |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
282 | __attribute__((__nonnull__)) |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
283 | static inline void cxMapDetach( |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
284 | CxMap *map, |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
285 | CxHashKey key |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
286 | ) { |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
287 | (void) map->cl->remove(map, key, false); |
659
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
288 | } |
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
289 | |
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
290 | /** |
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
291 | * Removes a key/value-pair from the map by using the key. |
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
292 | * |
686
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
293 | * This function can be used when the map is storing pointers, |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
294 | * in order to retrieve the pointer from the map without invoking |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
295 | * any destructor function. Sometimes you do not want the pointer |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
296 | * to be returned - in that case (instead of suppressing the "unused |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
297 | * result" warning) you can use cxMapDetach(). |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
298 | * |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
299 | * If this map is not storing pointers, this function behaves like |
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
300 | * cxMapRemove() and returns \c NULL. |
659
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
301 | * |
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
302 | * @param map the map |
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
303 | * @param key the key |
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
304 | * @return the stored pointer or \c NULL if either the key is not present |
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
305 | * in the map or the map is not storing pointers |
658
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
306 | * @see cxMapStorePointers() |
686
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
307 | * @see cxMapDetach() |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
308 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
309 | __attribute__((__nonnull__, __warn_unused_result__)) |
659
4a06fd63909a
split cxMapRemove() to cxMapRemoveAndGet()
Mike Becker <universe@uap-core.de>
parents:
658
diff
changeset
|
310 | static inline void *cxMapRemoveAndGet( |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
311 | CxMap *map, |
563
69a83fad8a35
improve hash key handling
Mike Becker <universe@uap-core.de>
parents:
558
diff
changeset
|
312 | CxHashKey key |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
313 | ) { |
686
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
314 | return map->cl->remove(map, key, !map->store_pointer); |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
315 | } |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
316 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
317 | // TODO: set-like map operations (union, intersect, difference) |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
318 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
319 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
320 | * Creates a value iterator for a map. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
321 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
322 | * \note An iterator iterates over all elements successively. Therefore the order |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
323 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
324 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
325 | * @param map the map to create the iterator for |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
326 | * @return an iterator for the currently stored values |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
327 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
328 | __attribute__((__nonnull__, __warn_unused_result__)) |
551
2946e13c89a4
#189 implement map iterators
Mike Becker <universe@uap-core.de>
parents:
550
diff
changeset
|
329 | static inline CxIterator cxMapIteratorValues(CxMap *map) { |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
330 | return map->cl->iterator_values(map); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
331 | } |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
332 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
333 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
334 | * Creates a key iterator for a map. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
335 | * |
564
5d8ad7a0ff71
fix obsolete documentation
Mike Becker <universe@uap-core.de>
parents:
563
diff
changeset
|
336 | * The elements of the iterator are keys of type CxHashKey. |
555
d79fbd028e26
fix documentation for map iterators
Mike Becker <universe@uap-core.de>
parents:
553
diff
changeset
|
337 | * |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
338 | * \note An iterator iterates over all elements successively. Therefore the order |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
339 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
340 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
341 | * @param map the map to create the iterator for |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
342 | * @return an iterator for the currently stored keys |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
343 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
344 | __attribute__((__nonnull__, __warn_unused_result__)) |
551
2946e13c89a4
#189 implement map iterators
Mike Becker <universe@uap-core.de>
parents:
550
diff
changeset
|
345 | static inline CxIterator cxMapIteratorKeys(CxMap *map) { |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
346 | return map->cl->iterator_keys(map); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
347 | } |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
348 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
349 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
350 | * Creates an iterator for a map. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
351 | * |
555
d79fbd028e26
fix documentation for map iterators
Mike Becker <universe@uap-core.de>
parents:
553
diff
changeset
|
352 | * The elements of the iterator are key/value pairs of type CxMapEntry. |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
353 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
354 | * \note An iterator iterates over all elements successively. Therefore the order |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
355 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
356 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
357 | * @param map the map to create the iterator for |
555
d79fbd028e26
fix documentation for map iterators
Mike Becker <universe@uap-core.de>
parents:
553
diff
changeset
|
358 | * @return an iterator for the currently stored entries |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
359 | * @see cxMapIteratorKeys() |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
360 | * @see cxMapIteratorValues() |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
361 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
362 | __attribute__((__nonnull__, __warn_unused_result__)) |
551
2946e13c89a4
#189 implement map iterators
Mike Becker <universe@uap-core.de>
parents:
550
diff
changeset
|
363 | static inline CxIterator cxMapIterator(CxMap *map) { |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
364 | return map->cl->iterator(map); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
365 | } |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
366 | |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
367 | |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
368 | /** |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
369 | * Creates a mutating iterator over the values of a map. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
370 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
371 | * \note An iterator iterates over all elements successively. Therefore the order |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
372 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
373 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
374 | * @param map the map to create the iterator for |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
375 | * @return an iterator for the currently stored values |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
376 | */ |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
377 | __attribute__((__nonnull__, __warn_unused_result__)) |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
378 | static inline CxMutIterator cxMapMutIteratorValues(CxMap *map) { |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
379 | return map->cl->mut_iterator_values(map); |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
380 | } |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
381 | |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
382 | /** |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
383 | * Creates a mutating iterator over the keys of a map. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
384 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
385 | * The elements of the iterator are keys of type CxHashKey. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
386 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
387 | * \note An iterator iterates over all elements successively. Therefore the order |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
388 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
389 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
390 | * @param map the map to create the iterator for |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
391 | * @return an iterator for the currently stored keys |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
392 | */ |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
393 | __attribute__((__nonnull__, __warn_unused_result__)) |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
394 | static inline CxMutIterator cxMapMutIteratorKeys(CxMap *map) { |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
395 | return map->cl->mut_iterator_keys(map); |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
396 | } |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
397 | |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
398 | /** |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
399 | * Creates a mutating iterator for a map. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
400 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
401 | * The elements of the iterator are key/value pairs of type CxMapEntry. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
402 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
403 | * \note An iterator iterates over all elements successively. Therefore the order |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
404 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
405 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
406 | * @param map the map to create the iterator for |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
407 | * @return an iterator for the currently stored entries |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
408 | * @see cxMapMutIteratorKeys() |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
409 | * @see cxMapMutIteratorValues() |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
410 | */ |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
411 | __attribute__((__nonnull__, __warn_unused_result__)) |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
412 | static inline CxMutIterator cxMapMutIterator(CxMap *map) { |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
413 | return map->cl->mut_iterator(map); |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
414 | } |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
415 | |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
416 | #ifdef __cplusplus |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
417 | } |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
418 | #endif |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
419 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
420 | #endif // UCX_MAP_H |