A simple set implementation, based on hash.h.
More...
A simple set implementation, based on hash.h.
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. |
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. |
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. |
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.
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_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. |
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.