RNGRB (RPGLE)

Red Black Tree Implementation : Wrapper
Details ....

Copybooks  

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

Procedures  

countNodeexported
tree_rb_createexported
Create tree
tree_rb_isEmptyexported
Is empty
tree_rb_sizeexported
Get tree size

Detailed Description  

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

It also manages the dynamic memory allocation and deallocation. The user can choose to make the allocation from a new or existing user heap. The default heap can also be used.

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.

This module contains all general procedures for the wrapper which is not specific for any datatype.

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

Procedure Documentation  

countNode  

voidcountNode()
Exported.

tree_rb_create  

Pointertree_rb_create(Pointer, Boolean)
Creates a new tree. If no id for a heap (user or default heap) is provided a new user heap will be created for memory allocation.

A compare function must be passed to the constructor for comparing two nodes. See tree_rb_int_compare for an implementation with integer keys.

Per default any memory from removed nodes will be deallocated but you can also passed *on as the third parameter and have the system free all allocated resources on activation group end.

Parameter:
Pointer   valueCompare function
Boolean   const   optionalDeallocate memory (default: *on)
Return value:
PointerPointer to new tree
Exported.
Infos:
  The calling program must make sure to free the memory of the tree either with the procedure tree_rb_finalize or by discarding the heap manually. All allocated memory will automatically be free with the end of the activation group.

tree_rb_isEmpty  

Booleantree_rb_isEmpty(Pointer)
Checks if the tree is empty.
Parameter:
Pointer   constPointer to tree
Return value:
Boolean*on = the tree is empty
*off = tree has elements
Exported.

tree_rb_size  

Integertree_rb_size(Pointer)
Returns the number of elements/nodes in this tree.
Parameter:
Pointer   constPointer to tree
Return value:
Numerisch (Integer) (10)Number of elements in the tree
Exported.
Infos:
  As the number of elements is not saved in the head data structure this procedure must traverse the whole tree before returning the result. This might take some time on huge trees.