cctools
set.h
Go to the documentation of this file.
1/*
2Copyright (C) 2022 The University of Notre Dame
3This software is distributed under the GNU General Public License.
4See the file COPYING for details.
5*/
6
7#ifndef SET_H
8#define SET_H
9
10#include "int_sizes.h"
11#include "list.h"
12
44#define SET_ITERATE( set, element ) set_first_element(set); while((element = set_next_element(set)))
45
46#define SET_ITERATE_RANDOM_START( set, offset_bookkeep, element ) set_random_element(set, &offset_bookkeep); while((element = set_next_element_with_offset(set, offset_bookkeep)))
47
53struct set *set_create(int buckets);
54
61struct set *set_duplicate(struct set *s);
62
70struct set *set_union(struct set *s1, struct set *s2);
71
77void set_clear(struct set *s);
78
84void set_delete(struct set *s);
85
91int set_size(struct set *s);
92
102int set_insert(struct set *s, const void *element);
103
113int set_insert_set(struct set *s, struct set *s2);
114
124int set_insert_list(struct set *s, struct list *l);
125
130int set_push(struct set *h, const void *element);
131
138int set_lookup(struct set *s, void *element);
139
146int set_remove(struct set *s, const void *element);
147
152void *set_pop(struct set *s);
153
161void set_first_element(struct set *s);
162
169void *set_next_element(struct set *s);
170
179void set_random_element(struct set *s, int *offset_bookkeep);
180
187void *set_next_element_with_offset(struct set *s, int offset_bookkeep);
188
194void **set_values(struct set *s);
195
196#endif
Robust, reentrant linked list structure.
struct set * set_create(int buckets)
Create a new set.
int set_insert_set(struct set *s, struct set *s2)
Insert an existing set into the set.
int set_size(struct set *s)
Count the entries in a set.
void set_delete(struct set *s)
Delete a set.
struct set * set_union(struct set *s1, struct set *s2)
Unions two sets into one set.
int set_insert_list(struct set *s, struct list *l)
Insert an existing list into the set.
int set_insert(struct set *s, const void *element)
Insert an element to the set.
void set_clear(struct set *s)
Remove all entries from a set.
void set_first_element(struct set *s)
Begin iteration over all the elements.
void * set_pop(struct set *s)
Remove an arbitrary element from the set.
void * set_next_element(struct set *s)
Continue iteration over all elements.
void set_random_element(struct set *s, int *offset_bookkeep)
Begin iteration over all elements from a random offset.
void ** set_values(struct set *s)
A set_size(s) array of the current elements in the set in a random order.
int set_push(struct set *h, const void *element)
Insert an element to the set.
int set_lookup(struct set *s, void *element)
Look up a element in the set.
struct set * set_duplicate(struct set *s)
Duplicate a set from an existing set.
void * set_next_element_with_offset(struct set *s, int offset_bookkeep)
Continue iteration over all elements from an arbitray offset.
int set_remove(struct set *s, const void *element)
Remove an element.