CObject
|
Tree data structure interface. More...
#include <CITree.h>
Public Member Functions | |
CITreeError | CITree_Push (struct CITree *self, const void *element, const void *key) |
CITreeError | CITree_Pop (struct CITree *self, void *element) |
CITreeError | CITree_DeleteElement (struct CITree *self, void *element) |
CITreeError | CITree_Peek (struct CITree *self, void *element) |
CITreeError | CITree_Get (struct CITree *self, void *element, size_t index) |
CITreeError | CITree_Delete (struct CITree *self, void *element, size_t index) |
size_t | CITree_Size (struct CITree *self) |
size_t | CITree_MaxSize (struct CITree *self) |
void | CITree_Clear (struct CITree *self) |
Data Fields | |
struct CInterface | interface |
An interface for adding/removing data from trees. The tree is copy by value, meaning data and keys added to the tree are copied into it.
void CITree_Clear | ( | struct CITree * | self | ) |
Reset the tree to have zero ndoes in it. All data in the tree is lost.
self | The tree. |
CITreeError CITree_Delete | ( | struct CITree * | self, |
void * | element, | ||
size_t | index | ||
) |
Delete at an arbitrary index in the tree. Indexing is done such that at any index i, left_child(i) = 2i and right_child(i) = 2i + 1.
element | Pointer to location where data at the index will be copied to. Use NULL to ignore and simply delete from the tree. |
index | Location in the tree to delete data from |
CITreeError CITree_DeleteElement | ( | struct CITree * | self, |
void * | element | ||
) |
Delete the node in the three who's element matches the input parameter element. This function has O(n) execution time.
self | The tree. |
element | The data pointed to by this is the search critera. The function will search for a node whos element matches the data pointed to by this and remove it. |
CITreeError CITree_Get | ( | struct CITree * | self, |
void * | element, | ||
size_t | index | ||
) |
Look at an arbitrary index in the tree. Indexing is done such that at any index i, left_child(i) = 2i + 1 and right_child(i) = 2i + 2.
element | Pointer to location where data at the index will be copied to. |
index | Location in the tree to copy data from |
size_t CITree_MaxSize | ( | struct CITree * | self | ) |
The maximum number of nodes which can be added to the tree.
self | The tree. |
CITreeError CITree_Peek | ( | struct CITree * | self, |
void * | element | ||
) |
Get the element at the root of the tree without removing it.
self | The tree. |
element | A pointer to the location where data will be copied out of the tree. |
CITreeError CITree_Pop | ( | struct CITree * | self, |
void * | element | ||
) |
Get the root of the tree and remove it. The tree will then have its nodes adjusted such that the heap property is maintained.
self | The tree. |
element | Pointer to location where that data at the root of the tree will be copied too. Use NULL to safely ignore. |
CITreeError CITree_Push | ( | struct CITree * | self, |
const void * | element, | ||
const void * | key | ||
) |
Put an element into the tree by copy and move it up the tree such that the heap property is not violated using the input param key to evaluate the heap property. The heap property requires the root of the tree has the key which evaluates to be less than all other keys in the tree.
self | The tree. |
element | Pointer to data that will be copied into the three. |
key | Pointer to the key for the data added to the tree. |
size_t CITree_Size | ( | struct CITree * | self | ) |
Get the current size of tree, ie, how many nodes have been added to the tree.
self | The tree. |