Relational Algebra Engine
Loading...
Searching...
No Matches
Typedefs | Functions
set.h File Reference
#include <stddef.h>
Include dependency graph for set.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct Set Set
 
typedef int(* SetCompareFn) (const void *a, const void *b)
 
typedef void(* SetFreeFn) (void *elem)
 
typedef void(* SetIterFn) (void *elem, void *userdata)
 

Functions

Set * set_create (SetCompareFn cmp, SetFreeFn freer)
 Create a new Set.
 
void set_destroy (Set *set)
 Destroy a Set and free its memory.
 
int set_add (Set *set, void *elem)
 Add an element to a Set.
 
int set_remove (Set *set, const void *elem)
 Remove an element from a Set.
 
int set_contains (const Set *set, const void *elem)
 Check if a Set contains an element.
 
size_t set_size (const Set *set)
 Get the number of elements in a Set.
 
void set_foreach (const Set *set, SetIterFn fn, void *userdata)
 Iterate over all elements in a Set.
 

Typedef Documentation

◆ Set

typedef struct Set Set

◆ SetCompareFn

typedef int(* SetCompareFn) (const void *a, const void *b)

◆ SetFreeFn

typedef void(* SetFreeFn) (void *elem)

◆ SetIterFn

typedef void(* SetIterFn) (void *elem, void *userdata)

Function Documentation

◆ set_add()

int set_add ( Set *  set,
void *  elem 
)

Add an element to a Set.

Parameters
setPointer to the Set.
elemPointer to the element to add.
Returns
1 if added, 0 if already present, -1 on error.

◆ set_contains()

int set_contains ( const Set *  set,
const void *  elem 
)

Check if a Set contains an element.

Parameters
setPointer to the Set.
elemPointer to the element to check.
Returns
1 if present, 0 if not.

◆ set_create()

Set * set_create ( SetCompareFn  cmp,
SetFreeFn  freer 
)

Create a new Set.

Parameters
cmpComparison function for elements.
freerFree function for elements (can be NULL).
Returns
Pointer to new Set, or NULL on failure.

◆ set_destroy()

void set_destroy ( Set *  set)

Destroy a Set and free its memory.

Parameters
setPointer to the Set to destroy. Safe to pass NULL.

◆ set_foreach()

void set_foreach ( const Set *  set,
SetIterFn  fn,
void *  userdata 
)

Iterate over all elements in a Set.

Parameters
setPointer to the Set.
fnCallback function to call for each element.
userdataUser data to pass to callback.

◆ set_remove()

int set_remove ( Set *  set,
const void *  elem 
)

Remove an element from a Set.

Parameters
setPointer to the Set.
elemPointer to the element to remove.
Returns
1 if removed, 0 if not found.

◆ set_size()

size_t set_size ( const Set *  set)

Get the number of elements in a Set.

Parameters
setPointer to the Set.
Returns
Number of elements in the Set.