Import from old repository commit 61ef2b42a9c4ba8e1600f15bb0236765edc2ad45.
[cascardo/ovs.git] / lib / svec.h
1 /*
2  * Copyright (c) 2008, 2009 Nicira Networks.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef SVEC_H
18 #define SVEC_H 1
19
20 #include <stdbool.h>
21 #include <stddef.h>
22
23 struct svec {
24     char **names;
25     size_t n;
26     size_t allocated;
27 };
28
29 #define SVEC_EMPTY_INITIALIZER { NULL, 0, 0 }
30
31 void svec_init(struct svec *);
32 void svec_clone(struct svec *, const struct svec *);
33 void svec_destroy(struct svec *);
34 void svec_clear(struct svec *);
35 void svec_add(struct svec *, const char *);
36 void svec_add_nocopy(struct svec *, char *);
37 void svec_del(struct svec *, const char *);
38 void svec_append(struct svec *, const struct svec *);
39 void svec_terminate(struct svec *);
40 void svec_sort(struct svec *);
41 void svec_sort_unique(struct svec *);
42 void svec_unique(struct svec *);
43 void svec_compact(struct svec *);
44 void svec_diff(const struct svec *a, const struct svec *b,
45                struct svec *a_only, struct svec *both, struct svec *b_only);
46 bool svec_contains(const struct svec *, const char *);
47 size_t svec_find(const struct svec *, const char *);
48 bool svec_is_sorted(const struct svec *);
49 bool svec_is_unique(const struct svec *);
50 const char *svec_get_duplicate(const struct svec *);
51 void svec_swap(struct svec *a, struct svec *b);
52 void svec_print(const struct svec *svec, const char *title);
53 void svec_parse_words(struct svec *svec, const char *words);
54 bool svec_equal(const struct svec *, const struct svec *);
55 char *svec_join(const struct svec *,
56                 const char *delimiter, const char *terminator);
57 const char *svec_back(const struct svec *);
58 void svec_pop_back(struct svec *);
59
60 #endif /* svec.h */