Relational Algebra Engine
Loading...
Searching...
No Matches
set.h
Go to the documentation of this file.
1#ifndef SET_H
2#define SET_H
3
4#include <stddef.h>
5
6typedef struct Set Set;
7
8/* Function pointer type for comparison.
9 Should return 0 if equal, <0 if a < b, >0 if a > b */
10typedef int (*SetCompareFn)(const void *a, const void *b);
11
12/* Function pointer type for freeing elements (optional, can be NULL) */
13typedef void (*SetFreeFn)(void *elem);
14
16void set_destroy(Set *set);
17
18/* Basic operations */
19int set_add(Set *set, void *elem);
20int set_remove(Set *set, const void *elem);
21int set_contains(const Set *set, const void *elem);
22size_t set_size(const Set *set);
23
24/* Iteration */
25typedef void (*SetIterFn)(void *elem, void *userdata);
26void set_foreach(const Set *set, SetIterFn fn, void *userdata);
27
28#endif // SET_H
int(* SetCompareFn)(const void *a, const void *b)
Definition set.h:10
int set_contains(const Set *set, const void *elem)
Check if a Set contains an element.
Definition set.c:70
size_t set_size(const Set *set)
Get the number of elements in a Set.
Definition set.c:131
void(* SetIterFn)(void *elem, void *userdata)
Definition set.h:25
Set * set_create(SetCompareFn cmp, SetFreeFn freer)
Create a new Set.
Definition set.c:31
int set_add(Set *set, void *elem)
Add an element to a Set.
Definition set.c:85
int set_remove(Set *set, const void *elem)
Remove an element from a Set.
Definition set.c:105
void set_destroy(Set *set)
Destroy a Set and free its memory.
Definition set.c:49
void set_foreach(const Set *set, SetIterFn fn, void *userdata)
Iterate over all elements in a Set.
Definition set.c:140
void(* SetFreeFn)(void *elem)
Definition set.h:13
Definition set.c:17
SetFreeFn freer
Definition set.c:20
SetCompareFn cmp
Definition set.c:19