A pointer set with user-definable compare function.
More...
Typedefs |
| typedef int(* | cpset_cmp_function )(const void *p1, const void *p2) |
| | The type of a cpset compare function.
|
| typedef unsigned(* | cpset_hash_function )(const void *obj) |
| | The type of a cpset hash function.
|
| typedef struct cpset_t | cpset_t |
| | a pointer set with custom compare function
|
| typedef struct cpset_iterator_t | cpset_iterator_t |
| | iterator over a pointer set with custom compare function
|
Functions |
| void | cpset_init (cpset_t *cpset, cpset_hash_function hash_function, cpset_cmp_function cmp_function) |
| | Initializes a cpset.
|
| void | cpset_init_size (cpset_t *cpset, cpset_hash_function hash_function, cpset_cmp_function cmp_function, size_t expected_elements) |
| | Initializes a cpset.
|
| void | cpset_destroy (cpset_t *cpset) |
| | Destroys a cpset and frees the memory allocated for hashtable.
|
| void * | cpset_insert (cpset_t *cpset, void *obj) |
| | Inserts an element into a cpset.
|
| void | cpset_remove (cpset_t *cpset, const void *obj) |
| | Removes an element from a cpset.
|
| void * | cpset_find (const cpset_t *cpset, const void *obj) |
| | Tests whether a cpset contains a pointer.
|
| size_t | cpset_size (const cpset_t *cpset) |
| | Returns the number of pointers contained in the cpset.
|
| void | cpset_iterator_init (cpset_iterator_t *iterator, const cpset_t *cpset) |
| | Initializes a cpset iterator.
|
| void * | cpset_iterator_next (cpset_iterator_t *iterator) |
| | Advances the iterator and returns the current element or NULL if all elements in the cpset have been processed.
|
| void | cpset_remove_iterator (cpset_t *cpset, const cpset_iterator_t *iterator) |
| | Removed the element the iterator currently points to.
|
Detailed Description
A pointer set with user-definable compare function.
Typedef Documentation
The type of a cpset compare function.
- Parameters:
-
| p1 | pointer to an element |
| p2 | pointer to another element |
- Returns:
- 1 if the elements are identically, zero else
Definition at line 46 of file cpset.h.
The type of a cpset hash function.
Definition at line 51 of file cpset.h.
iterator over a pointer set with custom compare function
- See also:
- cpset_t
Definition at line 73 of file cpset.h.
a pointer set with custom compare function
Definition at line 70 of file cpset.h.
Function Documentation
| void cpset_destroy |
( |
cpset_t * |
cpset | ) |
|
Destroys a cpset and frees the memory allocated for hashtable.
The memory of the cpset itself is not freed.
- Parameters:
-
| cpset | Pointer to the cpset |
| void* cpset_find |
( |
const cpset_t * |
cpset, |
|
|
const void * |
obj |
|
) |
| |
Tests whether a cpset contains a pointer.
- Parameters:
-
| cpset | Pointer to the cpset |
| obj | The pointer to find |
- Returns:
- An equivalent object to
obj or NULL
Initializes a cpset.
- Parameters:
-
| cpset | Pointer to allocated space for the cpset |
| hash_function | The hash function to use |
| cmp_function | The compare function to use |
Initializes a cpset.
- Parameters:
-
| cpset | Pointer to allocated space for the cpset |
| hash_function | The hash function to use |
| cmp_function | The compare function to use |
| expected_elements | Number of elements expected in the cpset (roughly) |
| void* cpset_insert |
( |
cpset_t * |
cpset, |
|
|
void * |
obj |
|
) |
| |
Inserts an element into a cpset.
- Parameters:
-
| cpset | Pointer to the cpset |
| obj | Element to insert into the cpset |
- Returns:
- The element itself or a pointer to an existing element
Initializes a cpset iterator.
Sets the iterator before the first element in the cpset.
- Parameters:
-
| iterator | Pointer to already allocated iterator memory |
| cpset | Pointer to the cpset |
Advances the iterator and returns the current element or NULL if all elements in the cpset have been processed.
- Attention:
- It is not allowed to use cpset_insert or cpset_remove while iterating over a cpset.
- Parameters:
-
| iterator | Pointer to the cpset iterator. |
- Returns:
- Next element in the cpset or NULL
| void cpset_remove |
( |
cpset_t * |
cpset, |
|
|
const void * |
obj |
|
) |
| |
Removes an element from a cpset.
Does nothing if the cpset doesn't contain the element.
- Parameters:
-
| cpset | Pointer to the cpset |
| obj | Pointer to remove from the cpset |
Removed the element the iterator currently points to.
- Parameters:
-
| cpset | Pointer to the cpset |
| iterator | Pointer to the cpset iterator. |
| size_t cpset_size |
( |
const cpset_t * |
cpset | ) |
|
Returns the number of pointers contained in the cpset.
- Parameters:
-
| cpset | Pointer to the cpset |
- Returns:
- Number of pointers contained in the cpset