Typedefs | |
typedef cxbool(*) | cx_tree_compare_func (cxcptr, cxcptr) |
The tree's key comparison operator function. | |
Functions | |
cx_tree_iterator | cx_tree_begin (const cx_tree *tree) |
Get an iterator to the first pair in the tree. | |
cx_tree_iterator | cx_tree_end (const cx_tree *tree) |
Get an iterator for the position after the last pair in the tree. | |
cx_tree_iterator | cx_tree_next (const cx_tree *tree, cx_tree_const_iterator position) |
Get an iterator for the next pair in the tree. | |
cx_tree_iterator | cx_tree_previous (const cx_tree *tree, cx_tree_const_iterator position) |
Get an iterator for the previous pair in the tree. | |
void | cx_tree_clear (cx_tree *tree) |
Remove all pairs from a tree. | |
cxbool | cx_tree_empty (const cx_tree *tree) |
Check whether a tree is empty. | |
cx_tree * | cx_tree_new (cx_tree_compare_func compare, cx_free_func key_destroy, cx_free_func value_destroy) |
Create a new tree without any elements. | |
void | cx_tree_delete (cx_tree *tree) |
Destroy a tree and all its elements. | |
cxsize | cx_tree_size (const cx_tree *tree) |
Get the actual number of pairs in the tree. | |
cxsize | cx_tree_max_size (const cx_tree *tree) |
Get the maximum number of pairs possible. | |
cx_tree_compare_func | cx_tree_key_comp (const cx_tree *tree) |
Get the key comparison function. | |
void | cx_tree_swap (cx_tree *tree1, cx_tree *tree2) |
Swap the contents of two trees. | |
cxptr | cx_tree_assign (cx_tree *tree, cx_tree_iterator position, cxcptr data) |
Assign data to an iterator position. | |
cxptr | cx_tree_get_key (const cx_tree *tree, cx_tree_const_iterator position) |
Get the key from a given iterator position. | |
cxptr | cx_tree_get_value (const cx_tree *tree, cx_tree_const_iterator position) |
Get the data from a given iterator position. | |
cx_tree_iterator | cx_tree_find (const cx_tree *tree, cxcptr key) |
Locate an element in the tree. | |
cx_tree_iterator | cx_tree_lower_bound (const cx_tree *tree, cxcptr key) |
Find the beginning of a subsequence. | |
cx_tree_iterator | cx_tree_upper_bound (const cx_tree *tree, cxcptr key) |
Find the end of a subsequence. | |
void | cx_tree_equal_range (const cx_tree *tree, cxcptr key, cx_tree_iterator *begin, cx_tree_iterator *end) |
Find a subsequence matching a given key. | |
cxsize | cx_tree_count (const cx_tree *tree, cxcptr key) |
Get the number of elements matching a key. | |
cx_tree_iterator | cx_tree_insert_unique (cx_tree *tree, cxcptr key, cxcptr data) |
Attempt to insert data into a tree. | |
cx_tree_iterator | cx_tree_insert_equal (cx_tree *tree, cxcptr key, cxcptr data) |
Insert data into a tree. | |
void | cx_tree_erase_position (cx_tree *tree, cx_tree_iterator position) |
Erase an element from a tree. | |
void | cx_tree_erase_range (cx_tree *tree, cx_tree_iterator begin, cx_tree_iterator end) |
Erase a range of elements from a tree. | |
cxsize | cx_tree_erase (cx_tree *tree, cxcptr key) |
Erase all elements from a tree matching the provided key. | |
cxbool | cx_tree_verify (const cx_tree *tree) |
Validate a tree. |
#include <cxtree.h>
typedef cxbool(*) cx_tree_compare_func(cxcptr, cxcptr) |
The tree's key comparison operator function.
This type of function is used by a tree internally to compare the keys of its elements. A key comparison operator returns TRUE
if the comparison of its first argument with the second argument succeeds, and FALSE
otherwise, as, for instance, the logical operators < or > do.
Examples:
#include <cxtree.h> cxbool less_int(cxcptr i1, cxcptr i2) { return *i1 < *i2; }
#include <string.h> #include <cxtree.h> cxbool less_string(cxcptr s1, cxcptr s2) { return strcmp(s1, s2) < 0; }
cxptr cx_tree_assign | ( | cx_tree * | tree, | |
cx_tree_iterator | position, | |||
cxcptr | data | |||
) |
Assign data to an iterator position.
tree | A tree. | |
position | Iterator positions where the data will be stored. | |
data | Data to store. |
cx_tree_iterator cx_tree_begin | ( | const cx_tree * | tree | ) |
Get an iterator to the first pair in the tree.
tree | The tree to query. |
void cx_tree_clear | ( | cx_tree * | tree | ) |
Remove all pairs from a tree.
tree | Tree to be cleared. |
cxsize cx_tree_count | ( | const cx_tree * | tree, | |
cxcptr | key | |||
) |
Get the number of elements matching a key.
tree | A tree. | |
key | Key of the (key, value) pair(s) to locate. |
void cx_tree_delete | ( | cx_tree * | tree | ) |
Destroy a tree and all its elements.
tree | The tree to destroy. |
cxbool cx_tree_empty | ( | const cx_tree * | tree | ) |
Check whether a tree is empty.
tree | A tree. |
TRUE
if the tree is empty, and FALSE
otherwise.return (cx_tree_size(tree) == 0);
cx_tree_iterator cx_tree_end | ( | const cx_tree * | tree | ) |
Get an iterator for the position after the last pair in the tree.
tree | The tree to query. |
void cx_tree_equal_range | ( | const cx_tree * | tree, | |
cxcptr | key, | |||
cx_tree_iterator * | begin, | |||
cx_tree_iterator * | end | |||
) |
Find a subsequence matching a given key.
tree | A tree. | |
key | The key of the (key, value) pair(s) to be located. | |
begin | First element with key key. | |
end | Last element with key key. |
cxsize cx_tree_erase | ( | cx_tree * | tree, | |
cxcptr | key | |||
) |
Erase all elements from a tree matching the provided key.
tree | A tree. | |
key | Key of the element to be erased. |
void cx_tree_erase_position | ( | cx_tree * | tree, | |
cx_tree_iterator | position | |||
) |
Erase an element from a tree.
tree | A tree. | |
position | Iterator position of the element to be erased. |
void cx_tree_erase_range | ( | cx_tree * | tree, | |
cx_tree_iterator | begin, | |||
cx_tree_iterator | end | |||
) |
Erase a range of elements from a tree.
tree | A tree. | |
begin | Iterator pointing to the start of the range to erase. | |
end | Iterator pointing to the end of the range to erase. |
cx_tree_iterator cx_tree_find | ( | const cx_tree * | tree, | |
cxcptr | key | |||
) |
Locate an element in the tree.
tree | A tree. | |
key | Key of the (key, value) pair to locate. |
cxptr cx_tree_get_key | ( | const cx_tree * | tree, | |
cx_tree_const_iterator | position | |||
) |
Get the key from a given iterator position.
tree | A tree. | |
position | Iterator position the data is retrieved from. |
cxptr cx_tree_get_value | ( | const cx_tree * | tree, | |
cx_tree_const_iterator | position | |||
) |
Get the data from a given iterator position.
tree | A tree. | |
position | Iterator position the data is retrieved from. |
cx_tree_iterator cx_tree_insert_equal | ( | cx_tree * | tree, | |
cxcptr | key, | |||
cxcptr | data | |||
) |
Insert data into a tree.
tree | A tree. | |
key | Key used to store the data. | |
data | Data to insert. |
cx_tree_iterator cx_tree_insert_unique | ( | cx_tree * | tree, | |
cxcptr | key, | |||
cxcptr | data | |||
) |
Attempt to insert data into a tree.
tree | A tree. | |
key | Key used to store the data. | |
data | Data to insert. |
NULL
if the pair could not be inserted.cx_tree_compare_func cx_tree_key_comp | ( | const cx_tree * | tree | ) |
Get the key comparison function.
tree | The tree to query. |
cx_tree_iterator cx_tree_lower_bound | ( | const cx_tree * | tree, | |
cxcptr | key | |||
) |
Find the beginning of a subsequence.
tree | A tree. | |
key | Key of the (key, value) pair(s) to locate. |
cxsize cx_tree_max_size | ( | const cx_tree * | tree | ) |
Get the maximum number of pairs possible.
tree | A tree. |
cx_tree* cx_tree_new | ( | cx_tree_compare_func | compare, | |
cx_free_func | key_destroy, | |||
cx_free_func | value_destroy | |||
) |
Create a new tree without any elements.
compare | Function used to compare keys. | |
key_destroy | Destructor for the keys. | |
value_destroy | Destructor for the value field. |
The tree's key comparison function is set to compare. It must return TRUE
or FALSE
if the comparison of the first argument passed to it with the second argument is found to be true or false respectively.
The destructors for a tree node's key and value field are set to key_destroy and value_destroy. Whenever a tree node is destroyed these functions are used to deallocate the memory used by the key and the value. Each of the destructors might be NULL
, i.e. keys and values are not deallocated during destroy operations.
cx_tree_iterator cx_tree_next | ( | const cx_tree * | tree, | |
cx_tree_const_iterator | position | |||
) |
Get an iterator for the next pair in the tree.
tree | A tree. | |
position | Current iterator position. |
cx_tree_iterator cx_tree_previous | ( | const cx_tree * | tree, | |
cx_tree_const_iterator | position | |||
) |
Get an iterator for the previous pair in the tree.
tree | A tree. | |
position | Current iterator position. |
cxsize cx_tree_size | ( | const cx_tree * | tree | ) |
Get the actual number of pairs in the tree.
tree | A tree. |
void cx_tree_swap | ( | cx_tree * | tree1, | |
cx_tree * | tree2 | |||
) |
Swap the contents of two trees.
tree1 | First tree. | |
tree2 | Second tree. |
cx_tree_iterator cx_tree_upper_bound | ( | const cx_tree * | tree, | |
cxcptr | key | |||
) |
Find the end of a subsequence.
tree | A tree. | |
key | Key of the (key, value) pair(s) to locate. |
cxbool cx_tree_verify | ( | const cx_tree * | tree | ) |
Validate a tree.
tree | The tree to verify. |
TRUE
if the tree is valid, or FALSE
otherwise.