]> git.proxmox.com Git - mirror_ovs.git/blame - lib/simap.h
netdev-offload-tc: Use single 'once' variable for probing tc features
[mirror_ovs.git] / lib / simap.h
CommitLineData
44bac24b 1/*
c841e96a 2 * Copyright (c) 2009, 2010, 2011, 2012, 2016, 2017 Nicira, Inc.
44bac24b
BP
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 SIMAP_H
18#define SIMAP_H 1
19
ee89ea7b 20#include "openvswitch/hmap.h"
44bac24b
BP
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/* A map from strings to unsigned integers. */
27struct simap {
28 struct hmap map; /* Contains "struct simap_node"s. */
29};
30
31struct simap_node {
32 struct hmap_node node; /* In struct simap's 'map' hmap. */
33 char *name;
34 unsigned int data;
35};
36
37#define SIMAP_INITIALIZER(SIMAP) { HMAP_INITIALIZER(&(SIMAP)->map) }
38
bc8d7dfa
BP
39#define SIMAP_FOR_EACH(SIMAP_NODE, SIMAP) \
40 HMAP_FOR_EACH_INIT (SIMAP_NODE, node, &(SIMAP)->map, \
41 BUILD_ASSERT_TYPE(SIMAP_NODE, struct simap_node *), \
42 BUILD_ASSERT_TYPE(SIMAP, struct simap *))
44bac24b 43
bc8d7dfa
BP
44#define SIMAP_FOR_EACH_SAFE(SIMAP_NODE, NEXT, SIMAP) \
45 HMAP_FOR_EACH_SAFE_INIT (SIMAP_NODE, NEXT, node, &(SIMAP)->map, \
46 BUILD_ASSERT_TYPE(SIMAP_NODE, struct simap_node *), \
47 BUILD_ASSERT_TYPE(NEXT, struct simap_node *), \
48 BUILD_ASSERT_TYPE(SIMAP, struct simap *))
44bac24b
BP
49
50void simap_init(struct simap *);
51void simap_destroy(struct simap *);
52void simap_swap(struct simap *, struct simap *);
53void simap_moved(struct simap *);
54void simap_clear(struct simap *);
55
56bool simap_is_empty(const struct simap *);
57size_t simap_count(const struct simap *);
58
59bool simap_put(struct simap *, const char *, unsigned int);
60unsigned int simap_increase(struct simap *, const char *, unsigned int);
61
62unsigned int simap_get(const struct simap *, const char *);
63struct simap_node *simap_find(const struct simap *, const char *);
64struct simap_node *simap_find_len(const struct simap *,
65 const char *, size_t len);
bcac5b7c 66bool simap_contains(const struct simap *, const char *);
44bac24b
BP
67
68void simap_delete(struct simap *, struct simap_node *);
bcac5b7c 69bool simap_find_and_delete(struct simap *, const char *);
44bac24b
BP
70
71const struct simap_node **simap_sort(const struct simap *);
c841e96a 72bool simap_equal(const struct simap *, const struct simap *);
6a16962c 73uint32_t simap_hash(const struct simap *);
44bac24b
BP
74
75#ifdef __cplusplus
76}
77#endif
78
79#endif /* simap.h */