Setting tag sliver-openvswitch-2.2.90-1
[sliver-openvswitch.git] / lib / simap.h
1 /*
2  * Copyright (c) 2009, 2010, 2011, 2012 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 "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 (SIMAP_NODE, node, &(SIMAP)->map)
41
42 #define SIMAP_FOR_EACH_SAFE(SIMAP_NODE, NEXT, SIMAP) \
43     HMAP_FOR_EACH_SAFE (SIMAP_NODE, NEXT, node, &(SIMAP)->map)
44
45 void simap_init(struct simap *);
46 void simap_destroy(struct simap *);
47 void simap_swap(struct simap *, struct simap *);
48 void simap_moved(struct simap *);
49 void simap_clear(struct simap *);
50
51 bool simap_is_empty(const struct simap *);
52 size_t simap_count(const struct simap *);
53
54 bool simap_put(struct simap *, const char *, unsigned int);
55 unsigned int simap_increase(struct simap *, const char *, unsigned int);
56
57 unsigned int simap_get(const struct simap *, const char *);
58 struct simap_node *simap_find(const struct simap *, const char *);
59 struct simap_node *simap_find_len(const struct simap *,
60                                   const char *, size_t len);
61 bool simap_contains(const struct simap *, const char *);
62
63 void simap_delete(struct simap *, struct simap_node *);
64 bool simap_find_and_delete(struct simap *, const char *);
65
66 const struct simap_node **simap_sort(const struct simap *);
67
68 #ifdef  __cplusplus
69 }
70 #endif
71
72 #endif /* simap.h */