A simple set implementation, based on hash.h.
More...
|
typedef struct set_entry_s | SET_ENTRY_T |
| This structure represents an entry in the set.
|
|
typedef struct set_s | SET_T |
| This represents a set.
|
|
|
SET_T * | set_new (const unsigned long slots) |
| Create a new set with the given number of slots.
|
|
SET_T * | set_new_string (const unsigned long slots) |
| Create a new set which holds strings (pointers to char).
|
|
SET_T * | set_new_int (const unsigned long slots) |
| Create a new set which holds pointers to integers.
|
|
void * | set_add_int (SET_T *set, const int val) |
| Helper to add integers to sets.
|
|
void | set_free (SET_T *set) |
| Frees memory (including values) associated with a set.
|
|
void * | set_add (SET_T *set, const void *val) |
| Add a value to a set.
|
|
void * | set_del (SET_T *set, const void *val) |
| Remove a value from the set.
|
|
void * | set_contains (const SET_T *set, const void *val) |
| Test whether a set contains a given value.
|
|
void ** | set_values (const SET_T *set) |
| Obtains all values currently in the set.
|
|
SET_T * | set_dup (const SET_T *set) |
| Create a deep copy of a set.
|
|
A simple set implementation, based on hash.h.
◆ set_add()
void * set_add |
( |
SET_T * |
set, |
|
|
const void * |
val |
|
) |
| |
Add a value to a set.
If the set already contains the value, a pointer to the value in the set is returned.
- Parameters
-
set | The set to which the value will be added. |
val | The value to store. |
- Return values
-
void * | If the value already exists in the set. |
NULL | If the value did not already exist in the set. |
◆ set_contains()
void * set_contains |
( |
const SET_T * |
set, |
|
|
const void * |
val |
|
) |
| |
Test whether a set contains a given value.
- Parameters
-
set | The set to be searched for the value. |
val | The value which is to be searched for. |
- Return values
-
void * | The value, if found. |
NULL | If the value was not found. |
◆ set_del()
void * set_del |
( |
SET_T * |
set, |
|
|
const void * |
val |
|
) |
| |
Remove a value from the set.
- Parameters
-
set | The set from which the value will be removed. |
val | The value to be removed from the set. |
- Return values
-
void * | The value which was removed. The caller should free this value. |
NULL | If the value was not found. |
◆ set_dup()
Create a deep copy of a set.
set_free
should be called on the pointer when no longer needed.
- Parameters
-
- Returns
- A copy of the set.
◆ set_free()
void set_free |
( |
SET_T * |
set | ) |
|
Frees memory (including values) associated with a set.
This function can free all memory associated with a set.
- Parameters
-
◆ set_new()
SET_T * set_new |
( |
const unsigned long |
slots | ) |
|
Create a new set with the given number of slots.
- Parameters
-
slots | The number of slots available in the set. Values hash to a slot, and if a slot already contains a value which yields the same hash, it is chained to other entries in the bucket. |
- Return values
-
SET_T * | Returns a pointer to a SET_T structure. |
NULL | If the set cannot be created. |
◆ set_values()
void ** set_values |
( |
const SET_T * |
set | ) |
|
Obtains all values currently in the set.
- Parameters
-
set | The set to be inspected. |
- Returns
- A NULL-terminated array of all values in the set. Call free() on the array when it is no longer required; values are pointers into the set and should not be freed.