RNGRB_STR (RPGLE)

Red Black Tree Implementation : Wrapper for string keys
Details ....

Copybooks  

de 'libtree_h.rpgle'
de 'libc_h.rpgle'

Procedures  

removeNodesRecursively
tree_rb_string_clearexported
Clear tree
tree_rb_string_compareexported
String compare function
tree_rb_string_compare_ignore_caseexported
String compare function (ignores case)
tree_rb_string_container_ofexported
Return pointer to user data structure
tree_rb_string_containsKeyexported
Contains key
tree_rb_string_finalizeexported
Dispose tree
tree_rb_string_firstexported
Get first element
tree_rb_string_getexported
Get element
tree_rb_string_lastexported
Get last element
tree_rb_string_nextexported
Get next element
tree_rb_string_previousexported
Get previous element
tree_rb_string_putexported
Insert new element
tree_rb_string_removeexported
Remove node by key
tree_rb_string_removeByNodeexported
Remove node

Detailed Description  

This module is a wrapper around the red black tree implemtation from the libtree project at github.com.

The wrapper adds type specific procedures for string keys. It also manages the dynamic memory allocation and deallocation. Memory will be allocated from the default heap. Depending on the compile options this is either from single level storage or from teraspace.

The tree has no maximum number of elements. As long as you can get memory from your heap you can add elements to the tree.

Author:
Mihael Schmidt
Date:
2011-03-08
Links:
https://github.com/fbuihuu/libtree
http://www.rpgnextgen.com

Procedure Documentation  

removeNodesRecursively  

voidremoveNodesRecursively()

tree_rb_string_clear  

voidtree_rb_string_clear(Pointer)
Removes all nodes from the tree recursively from top to bottom. All memory allocated to the nodes will be freed.
Parameter:
Pointer   constPointer to tree
Exported.
Infos:
  This procedure traverses the whole tree to complete. The tree will also rebalance itself on every remove operation. This might be costly on huge trees. It might be simpler to build a whole new tree.

tree_rb_string_compare  

Integertree_rb_string_compare(Pointer, Pointer)
This procedure is used for a tree with integer keys. It can be used on the tree creation procedure like this: tree_rb_create(%paddr('tree_rb_string_compare'));
Parameter:
Pointer   valueEmbedded node pointer A
Pointer   valueEmbedded node pointer B
Return value:
Numerisch (Integer) (10)less than 0 = key A is less than key B
0 = key A and B are equal
greater than 0 = key A is greater than key B
Exported.

tree_rb_string_compare_ignore_case  

Integertree_rb_string_compare_ignore_case(Pointer, Pointer)
This procedure is used for a tree with string keys. It can be used on the tree creation procedure like this: tree_rb_create(%paddr('tree_rb_string_compare'));
Parameter:
Pointer   valueEmbedded node pointer A
Pointer   valueEmbedded node pointer B
Return value:
Numerisch (Integer) (10)less than 0 = key A is less than key B
0 = key A and B are equal
greater than 0 = key A is greater than key B
Exported.

tree_rb_string_container_of  

Pointertree_rb_string_container_of(Pointer)
Returns a pointer to the user data structure of a node relative to the passed embedded data structure pointer.
Parameter:
Pointer   valuePointer to embedded data structure
Return value:
PointerPointer to user data structure or *null if input parameter is also *null
Exported.

tree_rb_string_containsKey  

Booleantree_rb_string_containsKey(Pointer, Zeichen)
Checks if the tree contains an element with the passed key.
Parameter:
Pointer   constPointer to tree
Zeichen (65535)   const   varyingKey
Return value:
Boolean*on = tree contains key
*off = tree does not contain key
Exported.

tree_rb_string_finalize  

voidtree_rb_string_finalize(Pointer)
Frees all allocated resources of the tree.
Parameter:
PointerPointer to tree
Exported.

tree_rb_string_first  

Pointertree_rb_string_first(Pointer)
Returns the first element of the tree.
Parameter:
Pointer   constPointer to tree
Return value:
PointerPointer to user data structure or *null if the tree is empty.
Exported.

tree_rb_string_get  

Pointertree_rb_string_get(Pointer, Zeichen)
Returns a pointer to the user node of the given key.
Parameter:
Pointer   constPointer to tree
Zeichen (65535)   const   varyingKey
Return value:
PointerPointer to user data structure or *null if there is no element with the given key in the tree.
Exported.

tree_rb_string_last  

Pointertree_rb_string_last(Pointer)
Returns the last element of the tree.
Parameter:
Pointer   constPointer to tree
Return value:
PointerPointer to user data structure or *null if the tree is empty.
Exported.

tree_rb_string_next  

Pointertree_rb_string_next(Pointer)
Returns the next element of the tree starting from the passed element.
Parameter:
Pointer   constPointer to user data structure
Return value:
PointerPointer to user data structure of the next node or *null if there are no more elements after the passed one.
Exported.

tree_rb_string_previous  

Pointertree_rb_string_previous(Pointer)
Returns the previous element of the tree starting from the passed element.
Parameter:
Pointer   constPointer to user data structure
Return value:
PointerPointer to user data structure of the previous node or *null if there are no more elements before the passed one.
Exported.

tree_rb_string_put  

voidtree_rb_string_put(Pointer, Zeichen, Pointer, Integer)
Inserts a new element into the tree. Any existing element will be replaced. The resources of any existing element will be freed.

The value is a passed as a pointer to the real value. If the length parameter is omitted it is assumed that the value is null-terminated.

The key and value will be copied to the tree node.

Parameter:
Pointer   constPointer to tree
Zeichen (65535)   const   varyingKey
Pointer   constPointer to value
Numerisch (Integer) (10)   const   optionalValue length (default: value must be null-terminated)
Exported.

tree_rb_string_remove  

voidtree_rb_string_remove(Pointer, Zeichen)
Removes a node from the tree. All allocated resources to the node will be freed. The procedure returns normally if the key does not exist in the tree.
Parameter:
Pointer   constPointer to tree
Zeichen (65535)   const   varyingKey
Exported.

tree_rb_string_removeByNode  

voidtree_rb_string_removeByNode(Pointer, Pointer)
Removes a node from the tree. All allocated resources to the node will be freed.
Parameter:
Pointer   constPointer to tree
PointerPointer to user data structure (node)
Exported.