FB_Tree_Set (Function Block)

A collection that contains no duplicate items implemented using an iterative AVL Tree. This data structure was implemented with the help of Max Goren’s iterative AVL tree in C++. See Function Block’s body for more details.

Extends: FB_Collection

Implements: I_Tree_Set

Properties

_Traversal

Type: T_BST_Traversal

Traversal method for retrieving values in the tree set.

Methods

Balance

Performs rotation and updates heights until tree is balanced.

Inputs

Name

Type

Description

pNode

POINTER TO T_AVL_Node

Clear

Empties/Clears/Deletes every item in the set.

Clear_Node

Deletes the node and its tree/sub-trees.

Inputs

Name

Type

Description

pRoot

POINTER TO T_AVL_Node

Contains

Checks if item is contained in set.

Inputs

Name

Type

Description

Item

ANY

Item to find.

Create_Node

Creates a new node in dynamic memory with a clone of the generic item as it data.

Inputs

Name

Type

Description

Item

T_Generic

Outputs

Name

Type

Description

bSuccess

BOOL

Error

T_Error

Delete_Node

Safety deletes node. If the node and/or it’s value/data is in dynamic memory it/they will be deleted.

Inputs

Name

Type

Description

pNode

REFERENCE TO POINTER TO T_AVL_Node

FB_exit

Inputs

Name

Type

Description

bInCopyCode

BOOL

if TRUE, the exit method is called for exiting an instance that is copied afterwards (online change).

Find_Minimum_Node

Finds the node with the smallest item in a tree or sub-tree.

Inputs

Name

Type

Description

pNode

POINTER TO T_AVL_Node

Get_Balance

Gets the difference between the left and right sub-trees.

Inputs

Name

Type

Description

pNode

POINTER TO T_AVL_Node

Get_Height

Safely gets the height of a sub-tree.

Inputs

Name

Type

Description

pNode

POINTER TO T_AVL_Node

Get_Values

Gets an immutable list of the values in the set.

Insert

Insert item into set.

Inputs

Name

Type

Description

Item

ANY

Data to insert

Outputs

Name

Type

Description

bSuccess

BOOL

Indicates whether operation was successful. Success = TRUE, Failure = FALSE

Insert_Generic

Adds new generic item at into set. The set will store a copy of the generic item so as to not modify the original value outside it’s scope.

Inputs

Name

Type

Description

Item

T_Generic

Item to store

Outputs

Name

Type

Description

bSuccess

BOOL

Indicates whether operation was successful. Success = TRUE, Failure = FALSE

Move_Node

Moves from node at source into the position of the destination.

Inputs

Name

Type

Description

pDestination, pSource

POINTER TO T_AVL_Node

Remove

Removes item from the set.

Inputs

Name

Type

Description

Item

ANY

Data to remove

Outputs

Name

Type

Description

bSuccess

BOOL

Indicates whether operation was successful. Success = TRUE, Failure = FALSE

Remove_Generic

Removes generic item from the set.

Inputs

Name

Type

Description

Item

T_Generic

Data to remove

Outputs

Name

Type

Description

bSuccess

BOOL

Indicates whether operation was successful. Success = TRUE, Failure = FALSE

Remove_Node

Finds and removes a node from a tree/sub-tree and returns the new root of the tree/subtree.

Inputs

Name

Type

Description

pNode

REFERENCE TO POINTER TO T_AVL_Node

Rotate_Left

Rotates a tree/sub-tree left.

Inputs

Name

Type

Description

pX

POINTER TO T_AVL_Node

Rotate_Right

Rotates a tree/sub-tree right.

Inputs

Name

Type

Description

pX

POINTER TO T_AVL_Node

Search_Node

Checks if an item is in a tree/ sub-tree.

Inputs

Name

Type

Description

pNode

POINTER TO T_AVL_Node

Item

T_Generic

Update_Height

Inputs

Name

Type

Description

pNode

POINTER TO T_AVL_Node