#include <stddef.h>
Go to the source code of this file.
◆ 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) |
◆ set_add()
| int set_add |
( |
Set * |
set, |
|
|
void * |
elem |
|
) |
| |
Add an element to a Set.
- Parameters
-
| set | Pointer to the Set. |
| elem | Pointer 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
-
| set | Pointer to the Set. |
| elem | Pointer to the element to check. |
- Returns
- 1 if present, 0 if not.
◆ set_create()
Create a new Set.
- Parameters
-
| cmp | Comparison function for elements. |
| freer | Free 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
-
| set | Pointer 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
-
| set | Pointer to the Set. |
| fn | Callback function to call for each element. |
| userdata | User data to pass to callback. |
◆ set_remove()
| int set_remove |
( |
Set * |
set, |
|
|
const void * |
elem |
|
) |
| |
Remove an element from a Set.
- Parameters
-
| set | Pointer to the Set. |
| elem | Pointer 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
-
- Returns
- Number of elements in the Set.