]>
git.proxmox.com Git - mirror_ovs.git/blob - lib/simap.h
2 * Copyright (c) 2009, 2010, 2011, 2012, 2016 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "openvswitch/hmap.h"
26 /* A map from strings to unsigned integers. */
28 struct hmap map
; /* Contains "struct simap_node"s. */
32 struct hmap_node node
; /* In struct simap's 'map' hmap. */
37 #define SIMAP_INITIALIZER(SIMAP) { HMAP_INITIALIZER(&(SIMAP)->map) }
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 *))
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 *))
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
*);
56 bool simap_is_empty(const struct simap
*);
57 size_t simap_count(const struct simap
*);
59 bool simap_put(struct simap
*, const char *, unsigned int);
60 unsigned int simap_increase(struct simap
*, const char *, unsigned int);
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 *);
68 void simap_delete(struct simap
*, struct simap_node
*);
69 bool simap_find_and_delete(struct simap
*, const char *);
71 const struct simap_node
**simap_sort(const struct simap
*);