]> git.proxmox.com Git - mirror_ovs.git/blob - lib/simap.h
cirrus: Use FreeBSD 12.2.
[mirror_ovs.git] / lib / simap.h
1 /*
2 * Copyright (c) 2009, 2010, 2011, 2012, 2016, 2017 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 SIMAP_H
18 #define SIMAP_H 1
19
20 #include "openvswitch/hmap.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 /* A map from strings to unsigned integers. */
27 struct simap {
28 struct hmap map; /* Contains "struct simap_node"s. */
29 };
30
31 struct 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
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 *))
43
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 *))
49
50 void simap_init(struct simap *);
51 void simap_destroy(struct simap *);
52 void simap_swap(struct simap *, struct simap *);
53 void simap_moved(struct simap *);
54 void simap_clear(struct simap *);
55
56 bool simap_is_empty(const struct simap *);
57 size_t simap_count(const struct simap *);
58
59 bool simap_put(struct simap *, const char *, unsigned int);
60 unsigned int simap_increase(struct simap *, const char *, unsigned int);
61
62 unsigned int simap_get(const struct simap *, const char *);
63 struct simap_node *simap_find(const struct simap *, const char *);
64 struct simap_node *simap_find_len(const struct simap *,
65 const char *, size_t len);
66 bool simap_contains(const struct simap *, const char *);
67
68 void simap_delete(struct simap *, struct simap_node *);
69 bool simap_find_and_delete(struct simap *, const char *);
70
71 const struct simap_node **simap_sort(const struct simap *);
72 bool simap_equal(const struct simap *, const struct simap *);
73 uint32_t simap_hash(const struct simap *);
74
75 #ifdef __cplusplus
76 }
77 #endif
78
79 #endif /* simap.h */