]> git.proxmox.com Git - mirror_ovs.git/blame_incremental - lib/shash.h
ofp-actions: Add extension to support "group" action in OF1.0.
[mirror_ovs.git] / lib / shash.h
... / ...
CommitLineData
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 "hmap.h"
21#include "util.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27struct shash_node {
28 struct hmap_node node;
29 char *name;
30 void *data;
31};
32
33struct 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
51void shash_init(struct shash *);
52void shash_destroy(struct shash *);
53void shash_destroy_free_data(struct shash *);
54void shash_swap(struct shash *, struct shash *);
55void shash_moved(struct shash *);
56void shash_clear(struct shash *);
57void shash_clear_free_data(struct shash *);
58bool shash_is_empty(const struct shash *);
59size_t shash_count(const struct shash *);
60struct shash_node *shash_add(struct shash *, const char *, const void *);
61struct shash_node *shash_add_nocopy(struct shash *, char *, const void *);
62bool shash_add_once(struct shash *, const char *, const void *);
63void shash_add_assert(struct shash *, const char *, const void *);
64void *shash_replace(struct shash *, const char *, const void *data);
65void shash_delete(struct shash *, struct shash_node *);
66char *shash_steal(struct shash *, struct shash_node *);
67struct shash_node *shash_find(const struct shash *, const char *);
68struct shash_node *shash_find_len(const struct shash *, const char *, size_t);
69void *shash_find_data(const struct shash *, const char *);
70void *shash_find_and_delete(struct shash *, const char *);
71void *shash_find_and_delete_assert(struct shash *, const char *);
72struct shash_node *shash_first(const struct shash *);
73const struct shash_node **shash_sort(const struct shash *);
74bool shash_equal_keys(const struct shash *, const struct shash *);
75struct shash_node *shash_random_node(struct shash *);
76
77#ifdef __cplusplus
78}
79#endif
80
81#endif /* shash.h */