]> git.proxmox.com Git - mirror_ovs.git/blame - lib/shash.h
ofp-actions: Add extension to support "group" action in OF1.0.
[mirror_ovs.git] / lib / shash.h
CommitLineData
064af421 1/*
bc8d7dfa 2 * Copyright (c) 2009, 2010, 2011, 2016 Nicira, Inc.
064af421 3 *
a14bc59f
BP
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:
064af421 7 *
a14bc59f
BP
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.
064af421
BP
15 */
16
17#ifndef SHASH_H
18#define SHASH_H 1
19
20#include "hmap.h"
bc8d7dfa 21#include "util.h"
064af421 22
fbfffdbb
BP
23#ifdef __cplusplus
24extern "C" {
25#endif
26
064af421
BP
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
bc8d7dfa
BP
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 *))
fd30311c 50
064af421
BP
51void shash_init(struct shash *);
52void shash_destroy(struct shash *);
a90b56b7 53void shash_destroy_free_data(struct shash *);
37e7f427 54void shash_swap(struct shash *, struct shash *);
baa8f41b 55void shash_moved(struct shash *);
064af421 56void shash_clear(struct shash *);
a90b56b7 57void shash_clear_free_data(struct shash *);
732dcb37 58bool shash_is_empty(const struct shash *);
c01da229 59size_t shash_count(const struct shash *);
55213fd5 60struct shash_node *shash_add(struct shash *, const char *, const void *);
ce5a3e38 61struct shash_node *shash_add_nocopy(struct shash *, char *, const void *);
76343538 62bool shash_add_once(struct shash *, const char *, const void *);
4a1ee6ae 63void shash_add_assert(struct shash *, const char *, const void *);
79903dd1 64void *shash_replace(struct shash *, const char *, const void *data);
064af421 65void shash_delete(struct shash *, struct shash_node *);
4f222648 66char *shash_steal(struct shash *, struct shash_node *);
064af421 67struct shash_node *shash_find(const struct shash *, const char *);
e74a239d 68struct shash_node *shash_find_len(const struct shash *, const char *, size_t);
064af421 69void *shash_find_data(const struct shash *, const char *);
837e8097 70void *shash_find_and_delete(struct shash *, const char *);
4a1ee6ae 71void *shash_find_and_delete_assert(struct shash *, const char *);
7efc68eb 72struct shash_node *shash_first(const struct shash *);
07423999 73const struct shash_node **shash_sort(const struct shash *);
37e7f427 74bool shash_equal_keys(const struct shash *, const struct shash *);
f2f7be86 75struct shash_node *shash_random_node(struct shash *);
064af421 76
fbfffdbb
BP
77#ifdef __cplusplus
78}
79#endif
80
064af421 81#endif /* shash.h */