CObject
CITree Struct Reference

Tree data structure interface. More...

#include <CITree.h>

+ Inheritance diagram for CITree:

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
 

Detailed Description

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.

Member Function Documentation

void CITree_Clear ( struct CITree self)

Reset the tree to have zero ndoes in it. All data in the tree is lost.

Parameters
selfThe 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.

Parameters
elementPointer to location where data at the index will be copied to. Use NULL to ignore and simply delete from the tree.
indexLocation in the tree to delete data from
Returns
  • CITREE_ERR_EMPTY: Nothing at given index to delete.
  • CITREE_OK: Success.
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.

Parameters
selfThe tree.
elementThe 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.
Returns
  • CITREE_ERR_EMPTY: Nothing in the tree to delete or no matching element.
  • CITREE_OK: Root of the tree successfully popped.
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.

Parameters
elementPointer to location where data at the index will be copied to.
indexLocation in the tree to copy data from
Returns
  • CITREE_ERR_EMPTY: Nothing at given index to copy.
  • CITREE_OK: Success.
size_t CITree_MaxSize ( struct CITree self)

The maximum number of nodes which can be added to the tree.

Parameters
selfThe tree.
Returns
The maximum number of nodes which can be added to the tree.
CITreeError CITree_Peek ( struct CITree self,
void *  element 
)

Get the element at the root of the tree without removing it.

Parameters
selfThe tree.
elementA pointer to the location where data will be copied out of the tree.
Returns
  • CITREE_ERR_EMPTY: Nothing in the tree to peek at.
  • CITREE_OK: Root of the tree successfully looked at.
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.

Parameters
selfThe tree.
elementPointer to location where that data at the root of the tree will be copied too. Use NULL to safely ignore.
Returns
  • CITREE_ERR_EMPTY: Nothing in the tree to pop.
  • CITREE_OK: Root of the tree successfully popped.
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.

Parameters
selfThe tree.
elementPointer to data that will be copied into the three.
keyPointer to the key for the data added to the tree.
Returns
  • CITREE_ERR_FULL: No room in tree to insert the element.
  • CITREE_OK: Element successfully inserted.
size_t CITree_Size ( struct CITree self)

Get the current size of tree, ie, how many nodes have been added to the tree.

Parameters
selfThe tree.
Returns
The current size of the tree.

The documentation for this struct was generated from the following file: