Public interface for a Sset (Sorted Set) class. More...
#include <Sset.h>
Related Functions | |
(Note that these are not member functions.) | |
Sset_ptr | Sset_copy (const Sset_ptr self) |
Creates a copy of the given set instance. | |
Sset_ptr | Sset_copy_func (const Sset_ptr self, void *(*func)(void *, void *), void *arg) |
Creates a copy of the given set instance, copying each element by calling given function. | |
Sset_ptr | Sset_create (void) |
Creates an instance of a Sorted Set. | |
Sset_ptr | Sset_create_with_param (PFIVPVP compare) |
Creates an instance of a Sorted Set with a comparing function. | |
void * | Sset_delete (Sset_ptr self, Sset_key key, boolean *is_found) |
Removes an element with key "key" from the set. | |
void | Sset_delete_iter (Sset_ptr self, Ssiter iter) |
Removes an element pointed by the iterator. | |
void | Sset_destroy (Sset_ptr self) |
Destroys a set instance. | |
Ssiter | Sset_find (Sset_ptr self, Sset_key key) |
Looks up for an element with a given key. | |
Ssiter | Sset_find_ge (Sset_ptr self, Sset_key key) |
Looks up for the closest element whose key is greater than or equal a given key. | |
Ssiter | Sset_find_insert (Sset_ptr self, Sset_key key, boolean *is_found) |
Looks up for an element with a given key and if does not exist it is created. | |
Ssiter | Sset_find_le (Sset_ptr self, Sset_key key) |
Looks up for the closest element whose key is less than or equal a given key. | |
Ssiter | Sset_first (Sset_ptr self) |
Returns an iterator pointing to a first element of a set, i.e. element with the smallest key. | |
size_t | Sset_get_size (Sset_ptr self) |
Returns the number of elements in a set. | |
boolean | Sset_insert (Sset_ptr self, Sset_key key, void *element) |
Insert an element "element" under the key "key" into the set. | |
boolean | Sset_is_empty (Sset_ptr self) |
Returns true iff the set is empty. | |
Ssiter | Sset_last (Sset_ptr self) |
Returns an iterator pointing to the last element of a set, i.e. element with the greatest key. |
Public interface for a Sset (Sorted Set) class.
Implementation of Sset class
Sset_ptr Sset_copy_func | ( | const Sset_ptr | self, | |
void *(*)(void *, void *) | func, | |||
void * | arg | |||
) | [related] |
Creates a copy of the given set instance, copying each element by calling given function.
Sset_ptr Sset_create | ( | void | ) | [related] |
Creates an instance of a Sorted Set.
Keys are sorted as integers (< and == operators are used)
Creates an instance of a Sorted Set with a comparing function.
Removes an element with key "key" from the set.
The returned value is the element stored in the deleted node. If parameter "is_found" is no NULL, "*is_found" is set to true if such an element with the provided key was found, and false otherwise. Note: if an element with the key does no exist in the set the returned value is NULL.
The operation takes O(log2 N) time (N is the size of the set).
Removes an element pointed by the iterator.
Precondition: the iterator should be returned one by Ssiter_first, Ssiter_last, Ssiter_next, Ssiter_prev. Precondition: an element pointed by iterator has to belong to this set. Precondition: Ssiter_is_valid(iter) has to be return true.
WARNING: After this function call the iterator will have undefined value and no operation is allowed with it except assignment of a new value.
The operation takes O(log2 N) time (N is the size of the set).
void Sset_destroy | ( | Sset_ptr | self | ) | [related] |
Destroys a set instance.
The memory used by the set will be freed. Note: memory occupied by the elements is not freed! It is the user responsibility.
Looks up for an element with a given key.
Returns an iterator pointing to the found element. If there is no such element Ssiter_is_valid() returns false on the returned iterator.
The operation takes O(log2 N) time (N is the size of the set).
Looks up for the closest element whose key is greater than or equal a given key.
Returns an iterator pointing to the found element. If there is no such element Ssiter_is_valid() returns false on the returned iterator.
The operation takes O(log2 N) time (N is the size of the set).
Looks up for an element with a given key and if does not exist it is created.
Returns an iterator pointing to the found (created) element. If is_found != NULL, *is_found is set to true if the element was found and false if it was created.
The operation takes O(log2 N) time (N is the size of the set).
It is user responsibility to free the key, if needed.
Looks up for the closest element whose key is less than or equal a given key.
Returns an iterator pointing to the found element. If there is no such element Ssiter_is_valid() returns false on the returned iterator.
The operation takes O(log2 N) time (N is the size of the set).
Returns an iterator pointing to a first element of a set, i.e. element with the smallest key.
If the set is empty Ssiter_is_valid() will be false on the returned iterator. NOTE: there is no need to free the iterator after using it. NOTE: it is allowed to assign one iterator to another one. NOTE: The operation may take up to O(log2 N) time (N is the size of the set).
size_t Sset_get_size | ( | Sset_ptr | self | ) | [related] |
Returns the number of elements in a set.
Constant time operation
Returns true iff the set is empty.
Constant time operation
Returns an iterator pointing to the last element of a set, i.e. element with the greatest key.
If the set is empty Ssiter_is_valid() will be false on the returned iterator. NOTE: there is no need to free the iterator after using it. NOTE: it is allowed to assign one iterator to another one. NOTE: The operation may take up to O(log2 N) time (N is the size of the set).