]> git.proxmox.com Git - ovs.git/blob - include/openvswitch/shash.h
afc482364f2490a2cbb3db27d54ab4b4f3466ae4
[ovs.git] / include / openvswitch / shash.h
1 /*
2 * Copyright (c) 2009, 2010, 2011, 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 SHASH_H
18 #define SHASH_H 1
19
20 #include "openvswitch/hmap.h"
21 #include "openvswitch/util.h"
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 struct shash_node {
28 struct hmap_node node;
29 char *name;
30 void *data;
31 };
32
33 struct shash {
34 struct hmap map;
35 };
36
37 #define SHASH_INITIALIZER(SHASH) { HMAP_INITIALIZER(&(SHASH)->map) }
38
39 #define SHASH_FOR_EACH(SHASH_NODE, SHASH) \
40 HMAP_FOR_EACH_INIT (SHASH_NODE, node, &(SHASH)->map, \
41 BUILD_ASSERT_TYPE(SHASH_NODE, struct shash_node *), \
42 BUILD_ASSERT_TYPE(SHASH, struct shash *))
43
44 #define SHASH_FOR_EACH_SAFE(SHASH_NODE, NEXT, SHASH) \
45 HMAP_FOR_EACH_SAFE_INIT ( \
46 SHASH_NODE, NEXT, node, &(SHASH)->map, \
47 BUILD_ASSERT_TYPE(SHASH_NODE, struct shash_node *), \
48 BUILD_ASSERT_TYPE(NEXT, struct shash_node *), \
49 BUILD_ASSERT_TYPE(SHASH, struct shash *))
50
51 void shash_init(struct shash *);
52 void shash_destroy(struct shash *);
53 void shash_destroy_free_data(struct shash *);
54 void shash_swap(struct shash *, struct shash *);
55 void shash_moved(struct shash *);
56 void shash_clear(struct shash *);
57 void shash_clear_free_data(struct shash *);
58 bool shash_is_empty(const struct shash *);
59 size_t shash_count(const struct shash *);
60 struct shash_node *shash_add(struct shash *, const char *, const void *);
61 struct shash_node *shash_add_nocopy(struct shash *, char *, const void *);
62 bool shash_add_once(struct shash *, const char *, const void *);
63 void shash_add_assert(struct shash *, const char *, const void *);
64 void *shash_replace(struct shash *, const char *, const void *data);
65 void shash_delete(struct shash *, struct shash_node *);
66 char *shash_steal(struct shash *, struct shash_node *);
67 struct shash_node *shash_find(const struct shash *, const char *);
68 struct shash_node *shash_find_len(const struct shash *, const char *, size_t);
69 void *shash_find_data(const struct shash *, const char *);
70 void *shash_find_and_delete(struct shash *, const char *);
71 void *shash_find_and_delete_assert(struct shash *, const char *);
72 struct shash_node *shash_first(const struct shash *);
73 const struct shash_node **shash_sort(const struct shash *);
74 bool shash_equal_keys(const struct shash *, const struct shash *);
75 struct shash_node *shash_random_node(struct shash *);
76
77 #ifdef __cplusplus
78 }
79 #endif
80
81 #endif /* shash.h */