]> git.proxmox.com Git - mirror_ovs.git/blame - lib/sset.h
dpif-netlink: Use netlink helpers for packet_type.
[mirror_ovs.git] / lib / sset.h
CommitLineData
f391294f 1/*
05e43c5d 2 * Copyright (c) 2011, 2012, 2013, 2015, 2016 Nicira, Inc.
f391294f
BP
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 SSET_H
18#define SSET_H
19
ee89ea7b 20#include "openvswitch/hmap.h"
ebc56baa 21#include "util.h"
f391294f 22
43d1478b
CB
23#ifdef __cplusplus
24extern "C" {
25#endif
26
f391294f
BP
27struct sset_node {
28 struct hmap_node hmap_node;
29 char name[1];
30};
31
32/* A set of strings. */
33struct sset {
34 struct hmap map;
35};
36
37#define SSET_INITIALIZER(SSET) { HMAP_INITIALIZER(&(SSET)->map) }
38
39/* Basics. */
40void sset_init(struct sset *);
41void sset_destroy(struct sset *);
42void sset_clone(struct sset *, const struct sset *);
43void sset_swap(struct sset *, struct sset *);
44void sset_moved(struct sset *);
45
63a10e1e
BP
46void sset_from_delimited_string(struct sset *, const char *s,
47 const char *delimiters);
48
f391294f
BP
49/* Count. */
50bool sset_is_empty(const struct sset *);
51size_t sset_count(const struct sset *);
52
53/* Insertion. */
54struct sset_node *sset_add(struct sset *, const char *);
55struct sset_node *sset_add_and_free(struct sset *, char *);
56void sset_add_assert(struct sset *, const char *);
57void sset_add_array(struct sset *, char **, size_t n);
58
59/* Deletion. */
60void sset_clear(struct sset *);
61void sset_delete(struct sset *, struct sset_node *);
62bool sset_find_and_delete(struct sset *, const char *);
63void sset_find_and_delete_assert(struct sset *, const char *);
64char *sset_pop(struct sset *);
65
66/* Search. */
67struct sset_node *sset_find(const struct sset *, const char *);
68bool sset_contains(const struct sset *, const char *);
69bool sset_equals(const struct sset *, const struct sset *);
bfbcebc2
DDP
70
71struct sset_position {
72 struct hmap_position pos;
73};
74
6822daf2 75struct sset_node *sset_at_position(const struct sset *,
bfbcebc2 76 struct sset_position *);
f391294f 77
a4686ba3
BP
78/* Set operations. */
79void sset_intersect(struct sset *, const struct sset *);
80
f391294f
BP
81/* Iteration macros. */
82#define SSET_FOR_EACH(NAME, SSET) \
83 for ((NAME) = SSET_FIRST(SSET); \
55d26906 84 NAME != NULL; \
f391294f
BP
85 (NAME) = SSET_NEXT(SSET, NAME))
86
87#define SSET_FOR_EACH_SAFE(NAME, NEXT, SSET) \
88 for ((NAME) = SSET_FIRST(SSET); \
55d26906 89 (NAME != NULL \
f391294f
BP
90 ? (NEXT) = SSET_NEXT(SSET, NAME), true \
91 : false); \
92 (NAME) = (NEXT))
808311f6 93
842733c3 94const char **sset_array(const struct sset *);
808311f6 95const char **sset_sort(const struct sset *);
f391294f
BP
96\f
97/* Implementation helper macros. */
98
99#define SSET_NODE_FROM_HMAP_NODE(HMAP_NODE) \
100 CONTAINER_OF(HMAP_NODE, struct sset_node, hmap_node)
101#define SSET_NAME_FROM_HMAP_NODE(HMAP_NODE) \
55d26906
AW
102 HMAP_NODE == NULL \
103 ? NULL \
104 : (CONST_CAST(const char *, (SSET_NODE_FROM_HMAP_NODE(HMAP_NODE)->name)))
f391294f 105#define SSET_NODE_FROM_NAME(NAME) CONTAINER_OF(NAME, struct sset_node, name)
05e43c5d
BP
106#define SSET_FIRST(SSET) \
107 (BUILD_ASSERT_TYPE(SSET, struct sset *), \
108 SSET_NAME_FROM_HMAP_NODE(hmap_first(&(SSET)->map)))
f391294f 109#define SSET_NEXT(SSET, NAME) \
05e43c5d
BP
110 (BUILD_ASSERT_TYPE(SSET, struct sset *), \
111 SSET_NAME_FROM_HMAP_NODE( \
112 hmap_next(&(SSET)->map, &SSET_NODE_FROM_NAME(NAME)->hmap_node)))
f391294f 113
43d1478b
CB
114#ifdef __cplusplus
115}
116#endif
117
f391294f 118#endif /* sset.h */