Coverage Report

Created: 2025-11-11 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openvswitch/include/openvswitch/hmap.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015, 2016 Nicira, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at:
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef HMAP_H
18
#define HMAP_H 1
19
20
#include <stdbool.h>
21
#include <stdlib.h>
22
#include "openvswitch/util.h"
23
24
#ifdef  __cplusplus
25
extern "C" {
26
#endif
27
28
/* A hash map node, to be embedded inside the data structure being mapped. */
29
struct hmap_node {
30
    size_t hash;                /* Hash value. */
31
    struct hmap_node *next;     /* Next in linked list. */
32
};
33
34
/* Returns the hash value embedded in 'node'. */
35
static inline size_t hmap_node_hash(const struct hmap_node *node)
36
0
{
37
0
    return node->hash;
38
0
}
Unexecuted instantiation: json_parser_target.c:hmap_node_hash
Unexecuted instantiation: json.c:hmap_node_hash
Unexecuted instantiation: jsonrpc.c:hmap_node_hash
Unexecuted instantiation: poll-loop.c:hmap_node_hash
Unexecuted instantiation: seq.c:hmap_node_hash
Unexecuted instantiation: shash.c:hmap_node_hash
Unexecuted instantiation: timeval.c:hmap_node_hash
Unexecuted instantiation: unixctl.c:hmap_node_hash
Unexecuted instantiation: stream-ssl.c:hmap_node_hash
Unexecuted instantiation: cooperative-multitasking.c:hmap_node_hash
Unexecuted instantiation: fatal-signal.c:hmap_node_hash
Unexecuted instantiation: hmap.c:hmap_node_hash
Unexecuted instantiation: packets.c:hmap_node_hash
Unexecuted instantiation: sset.c:hmap_node_hash
Unexecuted instantiation: dp-packet.c:hmap_node_hash
Unexecuted instantiation: lockfile.c:hmap_node_hash
39
40
0
#define HMAP_NODE_NULL ((struct hmap_node *) 1)
41
0
#define HMAP_NODE_NULL_INITIALIZER { 0, HMAP_NODE_NULL }
42
43
/* Returns true if 'node' has been set to null by hmap_node_nullify() and has
44
 * not been un-nullified by being inserted into an hmap. */
45
static inline bool
46
hmap_node_is_null(const struct hmap_node *node)
47
0
{
48
0
    return node->next == HMAP_NODE_NULL;
49
0
}
Unexecuted instantiation: json_parser_target.c:hmap_node_is_null
Unexecuted instantiation: json.c:hmap_node_is_null
Unexecuted instantiation: jsonrpc.c:hmap_node_is_null
Unexecuted instantiation: poll-loop.c:hmap_node_is_null
Unexecuted instantiation: seq.c:hmap_node_is_null
Unexecuted instantiation: shash.c:hmap_node_is_null
Unexecuted instantiation: timeval.c:hmap_node_is_null
Unexecuted instantiation: unixctl.c:hmap_node_is_null
Unexecuted instantiation: stream-ssl.c:hmap_node_is_null
Unexecuted instantiation: cooperative-multitasking.c:hmap_node_is_null
Unexecuted instantiation: fatal-signal.c:hmap_node_is_null
Unexecuted instantiation: hmap.c:hmap_node_is_null
Unexecuted instantiation: packets.c:hmap_node_is_null
Unexecuted instantiation: sset.c:hmap_node_is_null
Unexecuted instantiation: dp-packet.c:hmap_node_is_null
Unexecuted instantiation: lockfile.c:hmap_node_is_null
50
51
/* Marks 'node' with a distinctive value that can be tested with
52
 * hmap_node_is_null().  */
53
static inline void
54
hmap_node_nullify(struct hmap_node *node)
55
0
{
56
0
    node->next = HMAP_NODE_NULL;
57
0
}
Unexecuted instantiation: json_parser_target.c:hmap_node_nullify
Unexecuted instantiation: json.c:hmap_node_nullify
Unexecuted instantiation: jsonrpc.c:hmap_node_nullify
Unexecuted instantiation: poll-loop.c:hmap_node_nullify
Unexecuted instantiation: seq.c:hmap_node_nullify
Unexecuted instantiation: shash.c:hmap_node_nullify
Unexecuted instantiation: timeval.c:hmap_node_nullify
Unexecuted instantiation: unixctl.c:hmap_node_nullify
Unexecuted instantiation: stream-ssl.c:hmap_node_nullify
Unexecuted instantiation: cooperative-multitasking.c:hmap_node_nullify
Unexecuted instantiation: fatal-signal.c:hmap_node_nullify
Unexecuted instantiation: hmap.c:hmap_node_nullify
Unexecuted instantiation: packets.c:hmap_node_nullify
Unexecuted instantiation: sset.c:hmap_node_nullify
Unexecuted instantiation: dp-packet.c:hmap_node_nullify
Unexecuted instantiation: lockfile.c:hmap_node_nullify
58
59
/* A hash map. */
60
struct hmap {
61
    struct hmap_node **buckets; /* Must point to 'one' iff 'mask' == 0. */
62
    struct hmap_node *one;
63
    size_t mask;
64
    size_t n;
65
};
66
67
/* Initializer for an empty hash map. */
68
#define HMAP_INITIALIZER(HMAP) \
69
0
    { (struct hmap_node **const) &(HMAP)->one, NULL, 0, 0 }
70
71
/* Initializer for an immutable struct hmap 'HMAP' that contains 'N' nodes
72
 * linked together starting at 'NODE'.  The hmap only has a single chain of
73
 * hmap_nodes, so 'N' should be small. */
74
#define HMAP_CONST(HMAP, N, NODE) {                                 \
75
        CONST_CAST(struct hmap_node **, &(HMAP)->one), NODE, 0, N }
76
77
/* Initialization. */
78
void hmap_init(struct hmap *);
79
void hmap_destroy(struct hmap *);
80
void hmap_clear(struct hmap *);
81
void hmap_swap(struct hmap *a, struct hmap *b);
82
void hmap_moved(struct hmap *hmap);
83
static inline size_t hmap_count(const struct hmap *);
84
static inline bool hmap_is_empty(const struct hmap *);
85
86
/* Adjusting capacity. */
87
void hmap_expand_at(struct hmap *, const char *where);
88
#define hmap_expand(HMAP) hmap_expand_at(HMAP, OVS_SOURCE_LOCATOR)
89
90
void hmap_shrink_at(struct hmap *, const char *where);
91
#define hmap_shrink(HMAP) hmap_shrink_at(HMAP, OVS_SOURCE_LOCATOR)
92
93
void hmap_reserve_at(struct hmap *, size_t capacity, const char *where);
94
#define hmap_reserve(HMAP, CAPACITY) \
95
0
    hmap_reserve_at(HMAP, CAPACITY, OVS_SOURCE_LOCATOR)
96
97
/* Insertion and deletion. */
98
static inline void hmap_insert_at(struct hmap *, struct hmap_node *,
99
                                  size_t hash, const char *where);
100
#define hmap_insert(HMAP, NODE, HASH) \
101
30.3k
    hmap_insert_at(HMAP, NODE, HASH, OVS_SOURCE_LOCATOR)
102
103
static inline void hmap_insert_fast(struct hmap *,
104
                                    struct hmap_node *, size_t hash);
105
static inline void hmap_remove(struct hmap *, struct hmap_node *);
106
107
void hmap_node_moved(struct hmap *, struct hmap_node *, struct hmap_node *);
108
static inline void hmap_replace(struct hmap *, const struct hmap_node *old,
109
                                struct hmap_node *new_node);
110
111
struct hmap_node *hmap_random_node(const struct hmap *);
112
113
/* Search.
114
 *
115
 * HMAP_FOR_EACH_WITH_HASH iterates NODE over all of the nodes in HMAP that
116
 * have hash value equal to HASH.  HMAP_FOR_EACH_IN_BUCKET iterates NODE over
117
 * all of the nodes in HMAP that would fall in the same bucket as HASH.  MEMBER
118
 * must be the name of the 'struct hmap_node' member within NODE.
119
 *
120
 * These macros may be used interchangeably to search for a particular value in
121
 * an hmap, see, e.g. shash_find() for an example.  Usually, using
122
 * HMAP_FOR_EACH_WITH_HASH provides an optimization, because comparing a hash
123
 * value is usually cheaper than comparing an entire hash map key.  But for
124
 * simple hash map keys, it makes sense to use HMAP_FOR_EACH_IN_BUCKET because
125
 * it avoids doing two comparisons when a single simple comparison suffices.
126
 *
127
 * The loop should not change NODE to point to a different node or insert or
128
 * delete nodes in HMAP (unless it "break"s out of the loop to terminate
129
 * iteration).
130
 *
131
 * HASH is only evaluated once.
132
 *
133
 * When the loop terminates normally, meaning the iteration has completed
134
 * without using 'break', NODE will be NULL.  This is true for all of the
135
 * HMAP_FOR_EACH_*() macros.
136
 */
137
#define HMAP_FOR_EACH_WITH_HASH(NODE, MEMBER, HASH, HMAP)                     \
138
35.9k
    for (INIT_MULTIVAR(NODE, MEMBER, hmap_first_with_hash(HMAP, HASH),        \
139
35.9k
                       struct hmap_node);                                     \
140
36.8k
         CONDITION_MULTIVAR(NODE, MEMBER, ITER_VAR(NODE) != NULL);            \
141
35.9k
         UPDATE_MULTIVAR(NODE, hmap_next_with_hash(ITER_VAR(NODE))))
142
143
#define HMAP_FOR_EACH_IN_BUCKET(NODE, MEMBER, HASH, HMAP)                     \
144
0
    for (INIT_MULTIVAR(NODE, MEMBER, hmap_first_in_bucket(HMAP, HASH),        \
145
0
                       struct hmap_node);                                     \
146
0
         CONDITION_MULTIVAR(NODE, MEMBER, ITER_VAR(NODE) != NULL);            \
147
0
         UPDATE_MULTIVAR(NODE, hmap_next_in_bucket(ITER_VAR(NODE))))
148
149
static inline struct hmap_node *hmap_first_with_hash(const struct hmap *,
150
                                                     size_t hash);
151
static inline struct hmap_node *hmap_next_with_hash(const struct hmap_node *);
152
static inline struct hmap_node *hmap_first_in_bucket(const struct hmap *,
153
                                                     size_t hash);
154
static inline struct hmap_node *hmap_next_in_bucket(const struct hmap_node *);
155
156
bool hmap_contains(const struct hmap *, const struct hmap_node *);
157
158
/* Iteration.
159
 *
160
 * The *_INIT variants of these macros additionally evaluate the expressions
161
 * supplied following the HMAP argument once during the loop initialization.
162
 * This makes it possible for data structures that wrap around hmaps to insert
163
 * additional initialization into their iteration macros without having to
164
 * completely rewrite them.  In particular, it can be a good idea to insert
165
 * BUILD_ASSERT_TYPE checks for map and node types that wrap hmap, since
166
 * otherwise it is possible for clients to accidentally confuse two derived
167
 * data structures that happen to use the same member names for struct hmap and
168
 * struct hmap_node. */
169
170
/* Iterates through every node in HMAP. */
171
#define HMAP_FOR_EACH(NODE, MEMBER, HMAP) \
172
0
    HMAP_FOR_EACH_INIT(NODE, MEMBER, HMAP, (void) 0)
173
#define HMAP_FOR_EACH_INIT(NODE, MEMBER, HMAP, ...)                           \
174
9.47k
    for (INIT_MULTIVAR_EXP(NODE, MEMBER, hmap_first(HMAP), struct hmap_node,  \
175
9.47k
                           __VA_ARGS__);                                      \
176
35.3k
         CONDITION_MULTIVAR(NODE, MEMBER, ITER_VAR(NODE) != NULL);            \
177
25.8k
         UPDATE_MULTIVAR(NODE, hmap_next(HMAP, ITER_VAR(NODE))))
178
179
/* Safe when NODE may be freed (not needed when NODE may be removed from the
180
 * hash map but its members remain accessible and intact). */
181
#define HMAP_FOR_EACH_SAFE_LONG(NODE, NEXT, MEMBER, HMAP) \
182
    HMAP_FOR_EACH_SAFE_LONG_INIT (NODE, NEXT, MEMBER, HMAP, (void) NEXT)
183
184
#define HMAP_FOR_EACH_SAFE_LONG_INIT(NODE, NEXT, MEMBER, HMAP, ...)           \
185
    for (INIT_MULTIVAR_SAFE_LONG_EXP(NODE, NEXT, MEMBER, hmap_first(HMAP),    \
186
                                     struct hmap_node, __VA_ARGS__);          \
187
         CONDITION_MULTIVAR_SAFE_LONG(NODE, NEXT, MEMBER,                     \
188
                                      ITER_VAR(NODE) != NULL,                 \
189
                            ITER_VAR(NEXT) = hmap_next(HMAP, ITER_VAR(NODE)), \
190
                                      ITER_VAR(NEXT) != NULL);                \
191
         UPDATE_MULTIVAR_SAFE_LONG(NODE, NEXT))
192
193
/* Short versions of HMAP_FOR_EACH_SAFE. */
194
#define HMAP_FOR_EACH_SAFE_SHORT(NODE, MEMBER, HMAP)                          \
195
0
    HMAP_FOR_EACH_SAFE_SHORT_INIT (NODE, MEMBER, HMAP, (void) 0)
196
197
#define HMAP_FOR_EACH_SAFE_SHORT_INIT(NODE, MEMBER, HMAP, ...)                \
198
1.57M
    for (INIT_MULTIVAR_SAFE_SHORT_EXP(NODE, MEMBER, hmap_first(HMAP),         \
199
1.57M
                                      struct hmap_node, __VA_ARGS__);         \
200
1.60M
         CONDITION_MULTIVAR_SAFE_SHORT(NODE, MEMBER,                          \
201
1.57M
                                       ITER_VAR(NODE) != NULL,                \
202
1.57M
                      ITER_NEXT_VAR(NODE) = hmap_next(HMAP, ITER_VAR(NODE))); \
203
1.57M
         UPDATE_MULTIVAR_SAFE_SHORT(NODE))
204
205
#define HMAP_FOR_EACH_SAFE(...)                                               \
206
0
    OVERLOAD_SAFE_MACRO(HMAP_FOR_EACH_SAFE_LONG,                              \
207
0
                        HMAP_FOR_EACH_SAFE_SHORT,                             \
208
0
                        4, __VA_ARGS__)
209
210
211
/* Continues an iteration from just after NODE. */
212
#define HMAP_FOR_EACH_CONTINUE(NODE, MEMBER, HMAP) \
213
    HMAP_FOR_EACH_CONTINUE_INIT(NODE, MEMBER, HMAP, (void) 0)
214
#define HMAP_FOR_EACH_CONTINUE_INIT(NODE, MEMBER, HMAP, ...)                  \
215
    for (INIT_MULTIVAR_EXP(NODE, MEMBER, hmap_next(HMAP, &(NODE)->MEMBER),    \
216
                           struct hmap_node, __VA_ARGS__);                    \
217
         CONDITION_MULTIVAR(NODE, MEMBER, ITER_VAR(NODE) != NULL);            \
218
         UPDATE_MULTIVAR(NODE, hmap_next(HMAP, ITER_VAR(NODE))))
219
220
struct hmap_pop_helper_iter__ {
221
    size_t bucket;
222
    struct hmap_node *node;
223
};
224
225
static inline void
226
0
hmap_pop_helper__(struct hmap *hmap, struct hmap_pop_helper_iter__ *iter) {
227
0
228
0
    for (; iter->bucket <= hmap->mask; (iter->bucket)++) {
229
0
        struct hmap_node *node = hmap->buckets[iter->bucket];
230
0
231
0
        if (node) {
232
0
            hmap_remove(hmap, node);
233
0
            iter->node = node;
234
0
            return;
235
0
        }
236
0
    }
237
0
    iter->node = NULL;
238
0
}
Unexecuted instantiation: json_parser_target.c:hmap_pop_helper__
Unexecuted instantiation: json.c:hmap_pop_helper__
Unexecuted instantiation: jsonrpc.c:hmap_pop_helper__
Unexecuted instantiation: poll-loop.c:hmap_pop_helper__
Unexecuted instantiation: seq.c:hmap_pop_helper__
Unexecuted instantiation: shash.c:hmap_pop_helper__
Unexecuted instantiation: timeval.c:hmap_pop_helper__
Unexecuted instantiation: unixctl.c:hmap_pop_helper__
Unexecuted instantiation: stream-ssl.c:hmap_pop_helper__
Unexecuted instantiation: cooperative-multitasking.c:hmap_pop_helper__
Unexecuted instantiation: fatal-signal.c:hmap_pop_helper__
Unexecuted instantiation: hmap.c:hmap_pop_helper__
Unexecuted instantiation: packets.c:hmap_pop_helper__
Unexecuted instantiation: sset.c:hmap_pop_helper__
Unexecuted instantiation: dp-packet.c:hmap_pop_helper__
Unexecuted instantiation: lockfile.c:hmap_pop_helper__
239
240
#define HMAP_FOR_EACH_POP(NODE, MEMBER, HMAP)                                 \
241
    for (struct hmap_pop_helper_iter__ ITER_VAR(NODE) = { 0, NULL };          \
242
         hmap_pop_helper__(HMAP, &ITER_VAR(NODE)),                            \
243
         (ITER_VAR(NODE).node != NULL) ?                                      \
244
            (((NODE) = OBJECT_CONTAINING(ITER_VAR(NODE).node,                 \
245
                                         NODE, MEMBER)),1):                   \
246
            (((NODE) = NULL), 0);)
247
248
static inline struct hmap_node *hmap_first(const struct hmap *);
249
static inline struct hmap_node *hmap_next(const struct hmap *,
250
                                          const struct hmap_node *);
251
252
struct hmap_position {
253
    unsigned int bucket;
254
    unsigned int offset;
255
};
256
257
struct hmap_node *hmap_at_position(const struct hmap *,
258
                                   struct hmap_position *);
259
260
/* Returns the number of nodes currently in 'hmap'. */
261
static inline size_t
262
hmap_count(const struct hmap *hmap)
263
796k
{
264
796k
    return hmap->n;
265
796k
}
Unexecuted instantiation: json_parser_target.c:hmap_count
Unexecuted instantiation: json.c:hmap_count
Unexecuted instantiation: jsonrpc.c:hmap_count
Unexecuted instantiation: poll-loop.c:hmap_count
Unexecuted instantiation: seq.c:hmap_count
shash.c:hmap_count
Line
Count
Source
263
796k
{
264
796k
    return hmap->n;
265
796k
}
Unexecuted instantiation: timeval.c:hmap_count
Unexecuted instantiation: unixctl.c:hmap_count
Unexecuted instantiation: stream-ssl.c:hmap_count
Unexecuted instantiation: cooperative-multitasking.c:hmap_count
Unexecuted instantiation: fatal-signal.c:hmap_count
Unexecuted instantiation: hmap.c:hmap_count
Unexecuted instantiation: packets.c:hmap_count
Unexecuted instantiation: sset.c:hmap_count
Unexecuted instantiation: dp-packet.c:hmap_count
Unexecuted instantiation: lockfile.c:hmap_count
266
267
/* Returns the maximum number of nodes that 'hmap' may hold before it should be
268
 * rehashed. */
269
static inline size_t
270
hmap_capacity(const struct hmap *hmap)
271
0
{
272
0
    return hmap->mask * 2 + 1;
273
0
}
Unexecuted instantiation: json_parser_target.c:hmap_capacity
Unexecuted instantiation: json.c:hmap_capacity
Unexecuted instantiation: jsonrpc.c:hmap_capacity
Unexecuted instantiation: poll-loop.c:hmap_capacity
Unexecuted instantiation: seq.c:hmap_capacity
Unexecuted instantiation: shash.c:hmap_capacity
Unexecuted instantiation: timeval.c:hmap_capacity
Unexecuted instantiation: unixctl.c:hmap_capacity
Unexecuted instantiation: stream-ssl.c:hmap_capacity
Unexecuted instantiation: cooperative-multitasking.c:hmap_capacity
Unexecuted instantiation: fatal-signal.c:hmap_capacity
Unexecuted instantiation: hmap.c:hmap_capacity
Unexecuted instantiation: packets.c:hmap_capacity
Unexecuted instantiation: sset.c:hmap_capacity
Unexecuted instantiation: dp-packet.c:hmap_capacity
Unexecuted instantiation: lockfile.c:hmap_capacity
274
275
/* Returns true if 'hmap' currently contains no nodes,
276
 * false otherwise.
277
 * Note: While hmap in general is not thread-safe without additional locking,
278
 * hmap_is_empty() is. */
279
static inline bool
280
hmap_is_empty(const struct hmap *hmap)
281
787k
{
282
787k
    return hmap->n == 0;
283
787k
}
Unexecuted instantiation: json_parser_target.c:hmap_is_empty
Unexecuted instantiation: json.c:hmap_is_empty
Unexecuted instantiation: jsonrpc.c:hmap_is_empty
Unexecuted instantiation: poll-loop.c:hmap_is_empty
Unexecuted instantiation: seq.c:hmap_is_empty
shash.c:hmap_is_empty
Line
Count
Source
281
787k
{
282
787k
    return hmap->n == 0;
283
787k
}
Unexecuted instantiation: timeval.c:hmap_is_empty
Unexecuted instantiation: unixctl.c:hmap_is_empty
Unexecuted instantiation: stream-ssl.c:hmap_is_empty
Unexecuted instantiation: cooperative-multitasking.c:hmap_is_empty
Unexecuted instantiation: fatal-signal.c:hmap_is_empty
Unexecuted instantiation: hmap.c:hmap_is_empty
Unexecuted instantiation: packets.c:hmap_is_empty
Unexecuted instantiation: sset.c:hmap_is_empty
Unexecuted instantiation: dp-packet.c:hmap_is_empty
Unexecuted instantiation: lockfile.c:hmap_is_empty
284
285
/* Inserts 'node', with the given 'hash', into 'hmap'.  'hmap' is never
286
 * expanded automatically. */
287
static inline void
288
hmap_insert_fast(struct hmap *hmap, struct hmap_node *node, size_t hash)
289
62.5k
{
290
62.5k
    struct hmap_node **bucket = &hmap->buckets[hash & hmap->mask];
291
62.5k
    node->hash = hash;
292
62.5k
    node->next = *bucket;
293
62.5k
    *bucket = node;
294
62.5k
    hmap->n++;
295
62.5k
}
Unexecuted instantiation: json_parser_target.c:hmap_insert_fast
Unexecuted instantiation: json.c:hmap_insert_fast
Unexecuted instantiation: jsonrpc.c:hmap_insert_fast
Unexecuted instantiation: poll-loop.c:hmap_insert_fast
Unexecuted instantiation: seq.c:hmap_insert_fast
shash.c:hmap_insert_fast
Line
Count
Source
289
30.3k
{
290
30.3k
    struct hmap_node **bucket = &hmap->buckets[hash & hmap->mask];
291
30.3k
    node->hash = hash;
292
30.3k
    node->next = *bucket;
293
30.3k
    *bucket = node;
294
30.3k
    hmap->n++;
295
30.3k
}
Unexecuted instantiation: timeval.c:hmap_insert_fast
Unexecuted instantiation: unixctl.c:hmap_insert_fast
Unexecuted instantiation: stream-ssl.c:hmap_insert_fast
Unexecuted instantiation: cooperative-multitasking.c:hmap_insert_fast
Unexecuted instantiation: fatal-signal.c:hmap_insert_fast
hmap.c:hmap_insert_fast
Line
Count
Source
289
32.1k
{
290
32.1k
    struct hmap_node **bucket = &hmap->buckets[hash & hmap->mask];
291
32.1k
    node->hash = hash;
292
32.1k
    node->next = *bucket;
293
32.1k
    *bucket = node;
294
32.1k
    hmap->n++;
295
32.1k
}
Unexecuted instantiation: packets.c:hmap_insert_fast
Unexecuted instantiation: sset.c:hmap_insert_fast
Unexecuted instantiation: dp-packet.c:hmap_insert_fast
Unexecuted instantiation: lockfile.c:hmap_insert_fast
296
297
/* Inserts 'node', with the given 'hash', into 'hmap', and expands 'hmap' if
298
 * necessary to optimize search performance.
299
 *
300
 * ('where' is used in debug logging.  Commonly one would use hmap_insert() to
301
 * automatically provide the caller's source file and line number for
302
 * 'where'.) */
303
static inline void
304
hmap_insert_at(struct hmap *hmap, struct hmap_node *node, size_t hash,
305
               const char *where)
306
30.3k
{
307
30.3k
    hmap_insert_fast(hmap, node, hash);
308
30.3k
    if (hmap->n / 2 > hmap->mask) {
309
6.93k
        hmap_expand_at(hmap, where);
310
6.93k
    }
311
30.3k
}
Unexecuted instantiation: json_parser_target.c:hmap_insert_at
Unexecuted instantiation: json.c:hmap_insert_at
Unexecuted instantiation: jsonrpc.c:hmap_insert_at
Unexecuted instantiation: poll-loop.c:hmap_insert_at
Unexecuted instantiation: seq.c:hmap_insert_at
shash.c:hmap_insert_at
Line
Count
Source
306
30.3k
{
307
30.3k
    hmap_insert_fast(hmap, node, hash);
308
30.3k
    if (hmap->n / 2 > hmap->mask) {
309
6.93k
        hmap_expand_at(hmap, where);
310
6.93k
    }
311
30.3k
}
Unexecuted instantiation: timeval.c:hmap_insert_at
Unexecuted instantiation: unixctl.c:hmap_insert_at
Unexecuted instantiation: stream-ssl.c:hmap_insert_at
Unexecuted instantiation: cooperative-multitasking.c:hmap_insert_at
Unexecuted instantiation: fatal-signal.c:hmap_insert_at
Unexecuted instantiation: hmap.c:hmap_insert_at
Unexecuted instantiation: packets.c:hmap_insert_at
Unexecuted instantiation: sset.c:hmap_insert_at
Unexecuted instantiation: dp-packet.c:hmap_insert_at
Unexecuted instantiation: lockfile.c:hmap_insert_at
312
313
/* Removes 'node' from 'hmap'.  Does not shrink the hash table; call
314
 * hmap_shrink() directly if desired. */
315
static inline void
316
hmap_remove(struct hmap *hmap, struct hmap_node *node)
317
30.3k
{
318
30.3k
    struct hmap_node **bucket = &hmap->buckets[node->hash & hmap->mask];
319
30.4k
    while (*bucket != node) {
320
82
        bucket = &(*bucket)->next;
321
82
    }
322
30.3k
    *bucket = node->next;
323
30.3k
    hmap->n--;
324
30.3k
}
Unexecuted instantiation: json_parser_target.c:hmap_remove
Unexecuted instantiation: json.c:hmap_remove
Unexecuted instantiation: jsonrpc.c:hmap_remove
Unexecuted instantiation: poll-loop.c:hmap_remove
Unexecuted instantiation: seq.c:hmap_remove
shash.c:hmap_remove
Line
Count
Source
317
30.3k
{
318
30.3k
    struct hmap_node **bucket = &hmap->buckets[node->hash & hmap->mask];
319
30.4k
    while (*bucket != node) {
320
82
        bucket = &(*bucket)->next;
321
82
    }
322
30.3k
    *bucket = node->next;
323
30.3k
    hmap->n--;
324
30.3k
}
Unexecuted instantiation: timeval.c:hmap_remove
Unexecuted instantiation: unixctl.c:hmap_remove
Unexecuted instantiation: stream-ssl.c:hmap_remove
Unexecuted instantiation: cooperative-multitasking.c:hmap_remove
Unexecuted instantiation: fatal-signal.c:hmap_remove
Unexecuted instantiation: hmap.c:hmap_remove
Unexecuted instantiation: packets.c:hmap_remove
Unexecuted instantiation: sset.c:hmap_remove
Unexecuted instantiation: dp-packet.c:hmap_remove
Unexecuted instantiation: lockfile.c:hmap_remove
325
326
/* Puts 'new_node' in the position in 'hmap' currently occupied by 'old_node'.
327
 * The 'new_node' must hash to the same value as 'old_node'.  The client is
328
 * responsible for ensuring that the replacement does not violate any
329
 * client-imposed invariants (e.g. uniqueness of keys within a map).
330
 *
331
 * Afterward, 'old_node' is not part of 'hmap', and the client is responsible
332
 * for freeing it (if this is desirable). */
333
static inline void
334
hmap_replace(struct hmap *hmap,
335
             const struct hmap_node *old_node, struct hmap_node *new_node)
336
0
{
337
0
    struct hmap_node **bucket = &hmap->buckets[old_node->hash & hmap->mask];
338
0
    while (*bucket != old_node) {
339
0
        bucket = &(*bucket)->next;
340
0
    }
341
0
    *bucket = new_node;
342
0
    new_node->hash = old_node->hash;
343
0
    new_node->next = old_node->next;
344
0
}
Unexecuted instantiation: json_parser_target.c:hmap_replace
Unexecuted instantiation: json.c:hmap_replace
Unexecuted instantiation: jsonrpc.c:hmap_replace
Unexecuted instantiation: poll-loop.c:hmap_replace
Unexecuted instantiation: seq.c:hmap_replace
Unexecuted instantiation: shash.c:hmap_replace
Unexecuted instantiation: timeval.c:hmap_replace
Unexecuted instantiation: unixctl.c:hmap_replace
Unexecuted instantiation: stream-ssl.c:hmap_replace
Unexecuted instantiation: cooperative-multitasking.c:hmap_replace
Unexecuted instantiation: fatal-signal.c:hmap_replace
Unexecuted instantiation: hmap.c:hmap_replace
Unexecuted instantiation: packets.c:hmap_replace
Unexecuted instantiation: sset.c:hmap_replace
Unexecuted instantiation: dp-packet.c:hmap_replace
Unexecuted instantiation: lockfile.c:hmap_replace
345
346
static inline struct hmap_node *
347
hmap_next_with_hash__(const struct hmap_node *node, size_t hash)
348
36.8k
{
349
79.0k
    while (node != NULL && node->hash != hash) {
350
42.1k
        node = node->next;
351
42.1k
    }
352
36.8k
    return CONST_CAST(struct hmap_node *, node);
353
36.8k
}
Unexecuted instantiation: json_parser_target.c:hmap_next_with_hash__
Unexecuted instantiation: json.c:hmap_next_with_hash__
Unexecuted instantiation: jsonrpc.c:hmap_next_with_hash__
Unexecuted instantiation: poll-loop.c:hmap_next_with_hash__
Unexecuted instantiation: seq.c:hmap_next_with_hash__
shash.c:hmap_next_with_hash__
Line
Count
Source
348
36.8k
{
349
79.0k
    while (node != NULL && node->hash != hash) {
350
42.1k
        node = node->next;
351
42.1k
    }
352
36.8k
    return CONST_CAST(struct hmap_node *, node);
353
36.8k
}
Unexecuted instantiation: timeval.c:hmap_next_with_hash__
Unexecuted instantiation: unixctl.c:hmap_next_with_hash__
Unexecuted instantiation: stream-ssl.c:hmap_next_with_hash__
Unexecuted instantiation: cooperative-multitasking.c:hmap_next_with_hash__
Unexecuted instantiation: fatal-signal.c:hmap_next_with_hash__
Unexecuted instantiation: hmap.c:hmap_next_with_hash__
Unexecuted instantiation: packets.c:hmap_next_with_hash__
Unexecuted instantiation: sset.c:hmap_next_with_hash__
Unexecuted instantiation: dp-packet.c:hmap_next_with_hash__
Unexecuted instantiation: lockfile.c:hmap_next_with_hash__
354
355
/* Returns the first node in 'hmap' with the given 'hash', or a null pointer if
356
 * no nodes have that hash value. */
357
static inline struct hmap_node *
358
hmap_first_with_hash(const struct hmap *hmap, size_t hash)
359
35.9k
{
360
35.9k
    return hmap_next_with_hash__(hmap->buckets[hash & hmap->mask], hash);
361
35.9k
}
Unexecuted instantiation: json_parser_target.c:hmap_first_with_hash
Unexecuted instantiation: json.c:hmap_first_with_hash
Unexecuted instantiation: jsonrpc.c:hmap_first_with_hash
Unexecuted instantiation: poll-loop.c:hmap_first_with_hash
Unexecuted instantiation: seq.c:hmap_first_with_hash
shash.c:hmap_first_with_hash
Line
Count
Source
359
35.9k
{
360
35.9k
    return hmap_next_with_hash__(hmap->buckets[hash & hmap->mask], hash);
361
35.9k
}
Unexecuted instantiation: timeval.c:hmap_first_with_hash
Unexecuted instantiation: unixctl.c:hmap_first_with_hash
Unexecuted instantiation: stream-ssl.c:hmap_first_with_hash
Unexecuted instantiation: cooperative-multitasking.c:hmap_first_with_hash
Unexecuted instantiation: fatal-signal.c:hmap_first_with_hash
Unexecuted instantiation: hmap.c:hmap_first_with_hash
Unexecuted instantiation: packets.c:hmap_first_with_hash
Unexecuted instantiation: sset.c:hmap_first_with_hash
Unexecuted instantiation: dp-packet.c:hmap_first_with_hash
Unexecuted instantiation: lockfile.c:hmap_first_with_hash
362
363
/* Returns the first node in 'hmap' in the bucket in which the given 'hash'
364
 * would land, or a null pointer if that bucket is empty. */
365
static inline struct hmap_node *
366
hmap_first_in_bucket(const struct hmap *hmap, size_t hash)
367
0
{
368
0
    return hmap->buckets[hash & hmap->mask];
369
0
}
Unexecuted instantiation: json_parser_target.c:hmap_first_in_bucket
Unexecuted instantiation: json.c:hmap_first_in_bucket
Unexecuted instantiation: jsonrpc.c:hmap_first_in_bucket
Unexecuted instantiation: poll-loop.c:hmap_first_in_bucket
Unexecuted instantiation: seq.c:hmap_first_in_bucket
Unexecuted instantiation: shash.c:hmap_first_in_bucket
Unexecuted instantiation: timeval.c:hmap_first_in_bucket
Unexecuted instantiation: unixctl.c:hmap_first_in_bucket
Unexecuted instantiation: stream-ssl.c:hmap_first_in_bucket
Unexecuted instantiation: cooperative-multitasking.c:hmap_first_in_bucket
Unexecuted instantiation: fatal-signal.c:hmap_first_in_bucket
Unexecuted instantiation: hmap.c:hmap_first_in_bucket
Unexecuted instantiation: packets.c:hmap_first_in_bucket
Unexecuted instantiation: sset.c:hmap_first_in_bucket
Unexecuted instantiation: dp-packet.c:hmap_first_in_bucket
Unexecuted instantiation: lockfile.c:hmap_first_in_bucket
370
371
/* Returns the next node in the same bucket as 'node', or a null pointer if
372
 * there are no more nodes in that bucket.
373
 *
374
 * If the hash map has been reallocated since 'node' was visited, some nodes
375
 * may be skipped; if new nodes with the same hash value have been added, they
376
 * will be skipped.  (Removing 'node' from the hash map does not prevent
377
 * calling this function, since node->next is preserved, although freeing
378
 * 'node' of course does.) */
379
static inline struct hmap_node *
380
hmap_next_in_bucket(const struct hmap_node *node)
381
0
{
382
0
    return node->next;
383
0
}
Unexecuted instantiation: json_parser_target.c:hmap_next_in_bucket
Unexecuted instantiation: json.c:hmap_next_in_bucket
Unexecuted instantiation: jsonrpc.c:hmap_next_in_bucket
Unexecuted instantiation: poll-loop.c:hmap_next_in_bucket
Unexecuted instantiation: seq.c:hmap_next_in_bucket
Unexecuted instantiation: shash.c:hmap_next_in_bucket
Unexecuted instantiation: timeval.c:hmap_next_in_bucket
Unexecuted instantiation: unixctl.c:hmap_next_in_bucket
Unexecuted instantiation: stream-ssl.c:hmap_next_in_bucket
Unexecuted instantiation: cooperative-multitasking.c:hmap_next_in_bucket
Unexecuted instantiation: fatal-signal.c:hmap_next_in_bucket
Unexecuted instantiation: hmap.c:hmap_next_in_bucket
Unexecuted instantiation: packets.c:hmap_next_in_bucket
Unexecuted instantiation: sset.c:hmap_next_in_bucket
Unexecuted instantiation: dp-packet.c:hmap_next_in_bucket
Unexecuted instantiation: lockfile.c:hmap_next_in_bucket
384
385
/* Returns the next node in the same hash map as 'node' with the same hash
386
 * value, or a null pointer if no more nodes have that hash value.
387
 *
388
 * If the hash map has been reallocated since 'node' was visited, some nodes
389
 * may be skipped; if new nodes with the same hash value have been added, they
390
 * will be skipped.  (Removing 'node' from the hash map does not prevent
391
 * calling this function, since node->next is preserved, although freeing
392
 * 'node' of course does.) */
393
static inline struct hmap_node *
394
hmap_next_with_hash(const struct hmap_node *node)
395
906
{
396
906
    return hmap_next_with_hash__(node->next, node->hash);
397
906
}
Unexecuted instantiation: json_parser_target.c:hmap_next_with_hash
Unexecuted instantiation: json.c:hmap_next_with_hash
Unexecuted instantiation: jsonrpc.c:hmap_next_with_hash
Unexecuted instantiation: poll-loop.c:hmap_next_with_hash
Unexecuted instantiation: seq.c:hmap_next_with_hash
shash.c:hmap_next_with_hash
Line
Count
Source
395
906
{
396
906
    return hmap_next_with_hash__(node->next, node->hash);
397
906
}
Unexecuted instantiation: timeval.c:hmap_next_with_hash
Unexecuted instantiation: unixctl.c:hmap_next_with_hash
Unexecuted instantiation: stream-ssl.c:hmap_next_with_hash
Unexecuted instantiation: cooperative-multitasking.c:hmap_next_with_hash
Unexecuted instantiation: fatal-signal.c:hmap_next_with_hash
Unexecuted instantiation: hmap.c:hmap_next_with_hash
Unexecuted instantiation: packets.c:hmap_next_with_hash
Unexecuted instantiation: sset.c:hmap_next_with_hash
Unexecuted instantiation: dp-packet.c:hmap_next_with_hash
Unexecuted instantiation: lockfile.c:hmap_next_with_hash
398
399
static inline struct hmap_node *
400
hmap_next__(const struct hmap *hmap, size_t start)
401
1.61M
{
402
1.61M
    size_t i;
403
3.23M
    for (i = start; i <= hmap->mask; i++) {
404
1.65M
        struct hmap_node *node = hmap->buckets[i];
405
1.65M
        if (node) {
406
37.5k
            return node;
407
37.5k
        }
408
1.65M
    }
409
1.57M
    return NULL;
410
1.61M
}
Unexecuted instantiation: json_parser_target.c:hmap_next__
json.c:hmap_next__
Line
Count
Source
401
803k
{
402
803k
    size_t i;
403
1.59M
    for (i = start; i <= hmap->mask; i++) {
404
811k
        struct hmap_node *node = hmap->buckets[i];
405
811k
        if (node) {
406
18.5k
            return node;
407
18.5k
        }
408
811k
    }
409
785k
    return NULL;
410
803k
}
Unexecuted instantiation: jsonrpc.c:hmap_next__
Unexecuted instantiation: poll-loop.c:hmap_next__
Unexecuted instantiation: seq.c:hmap_next__
shash.c:hmap_next__
Line
Count
Source
401
813k
{
402
813k
    size_t i;
403
1.64M
    for (i = start; i <= hmap->mask; i++) {
404
845k
        struct hmap_node *node = hmap->buckets[i];
405
845k
        if (node) {
406
18.9k
            return node;
407
18.9k
        }
408
845k
    }
409
794k
    return NULL;
410
813k
}
Unexecuted instantiation: timeval.c:hmap_next__
Unexecuted instantiation: unixctl.c:hmap_next__
Unexecuted instantiation: stream-ssl.c:hmap_next__
Unexecuted instantiation: cooperative-multitasking.c:hmap_next__
Unexecuted instantiation: fatal-signal.c:hmap_next__
Unexecuted instantiation: hmap.c:hmap_next__
Unexecuted instantiation: packets.c:hmap_next__
Unexecuted instantiation: sset.c:hmap_next__
Unexecuted instantiation: dp-packet.c:hmap_next__
Unexecuted instantiation: lockfile.c:hmap_next__
411
412
/* Returns the first node in 'hmap', in arbitrary order, or a null pointer if
413
 * 'hmap' is empty. */
414
static inline struct hmap_node *
415
hmap_first(const struct hmap *hmap)
416
1.58M
{
417
1.58M
    return hmap_next__(hmap, 0);
418
1.58M
}
Unexecuted instantiation: json_parser_target.c:hmap_first
json.c:hmap_first
Line
Count
Source
416
785k
{
417
785k
    return hmap_next__(hmap, 0);
418
785k
}
Unexecuted instantiation: jsonrpc.c:hmap_first
Unexecuted instantiation: poll-loop.c:hmap_first
Unexecuted instantiation: seq.c:hmap_first
shash.c:hmap_first
Line
Count
Source
416
795k
{
417
795k
    return hmap_next__(hmap, 0);
418
795k
}
Unexecuted instantiation: timeval.c:hmap_first
Unexecuted instantiation: unixctl.c:hmap_first
Unexecuted instantiation: stream-ssl.c:hmap_first
Unexecuted instantiation: cooperative-multitasking.c:hmap_first
Unexecuted instantiation: fatal-signal.c:hmap_first
Unexecuted instantiation: hmap.c:hmap_first
Unexecuted instantiation: packets.c:hmap_first
Unexecuted instantiation: sset.c:hmap_first
Unexecuted instantiation: dp-packet.c:hmap_first
Unexecuted instantiation: lockfile.c:hmap_first
419
420
/* Returns the next node in 'hmap' following 'node', in arbitrary order, or a
421
 * null pointer if 'node' is the last node in 'hmap'.
422
 *
423
 * If the hash map has been reallocated since 'node' was visited, some nodes
424
 * may be skipped or visited twice.  (Removing 'node' from the hash map does
425
 * not prevent calling this function, since node->next is preserved, although
426
 * freeing 'node' of course does.) */
427
static inline struct hmap_node *
428
hmap_next(const struct hmap *hmap, const struct hmap_node *node)
429
55.6k
{
430
55.6k
    return (node->next
431
55.6k
            ? node->next
432
55.6k
            : hmap_next__(hmap, (node->hash & hmap->mask) + 1));
433
55.6k
}
Unexecuted instantiation: json_parser_target.c:hmap_next
json.c:hmap_next
Line
Count
Source
429
29.8k
{
430
29.8k
    return (node->next
431
29.8k
            ? node->next
432
29.8k
            : hmap_next__(hmap, (node->hash & hmap->mask) + 1));
433
29.8k
}
Unexecuted instantiation: jsonrpc.c:hmap_next
Unexecuted instantiation: poll-loop.c:hmap_next
Unexecuted instantiation: seq.c:hmap_next
shash.c:hmap_next
Line
Count
Source
429
25.8k
{
430
25.8k
    return (node->next
431
25.8k
            ? node->next
432
25.8k
            : hmap_next__(hmap, (node->hash & hmap->mask) + 1));
433
25.8k
}
Unexecuted instantiation: timeval.c:hmap_next
Unexecuted instantiation: unixctl.c:hmap_next
Unexecuted instantiation: stream-ssl.c:hmap_next
Unexecuted instantiation: cooperative-multitasking.c:hmap_next
Unexecuted instantiation: fatal-signal.c:hmap_next
Unexecuted instantiation: hmap.c:hmap_next
Unexecuted instantiation: packets.c:hmap_next
Unexecuted instantiation: sset.c:hmap_next
Unexecuted instantiation: dp-packet.c:hmap_next
Unexecuted instantiation: lockfile.c:hmap_next
434
435
#ifdef  __cplusplus
436
}
437
#endif
438
439
#endif /* hmap.h */