Declaration¶
Source position: avl_tree.pp line 89
type
TAVLTree = class
public
constructor Create(const OnCompareMethod: TListSortCompare);
constructor Create;
constructor CreateObjectCompare;
destructor Destroy;
property OnCompare: TListSortCompare; {rw}
property OnObjectCompare: TObjectSortCompare; {rw}
property NodeClass: TAVLTreeNodeClass; {rw}
procedure SetNodeManager;
function NewNode : TAVLTreeNode;
procedure DisposeNode;
procedure Add(ANode: TAVLTreeNode);
function Add(Data: Pointer) : TAVLTreeNode;
function AddAscendingSequence : TAVLTreeNode;
procedure Delete;
function Remove : Boolean;
function RemovePointer : Boolean;
procedure MoveDataLeftMost;
procedure MoveDataRightMost;
procedure Clear;
procedure FreeAndClear;
procedure FreeAndDelete;
function Equals : Boolean;
function IsEqual : Boolean;
procedure Assign;
property Root: TAVLTreeNode; {r}
property Count: SizeInt; {r}
function Compare : Integer;
function Find : TAVLTreeNode;
function FindKey : TAVLTreeNode;
function FindNearestKey : TAVLTreeNode;
function FindSuccessor : TAVLTreeNode;
function FindPrecessor : TAVLTreeNode;
function FindLowest : TAVLTreeNode;
function FindHighest : TAVLTreeNode;
function FindNearest : TAVLTreeNode;
function FindPointer : TAVLTreeNode;
function FindLeftMost : TAVLTreeNode;
function FindRightMost : TAVLTreeNode;
function FindLeftMostKey : TAVLTreeNode;
function FindRightMostKey : TAVLTreeNode;
function FindLeftMostSameKey : TAVLTreeNode;
function FindRightMostSameKey : TAVLTreeNode;
function GetEnumerator : TAVLTreeNodeEnumerator;
function GetEnumeratorHighToLow : TAVLTreeNodeEnumerator;
procedure ConsistencyCheck;
procedure WriteReportToStream;
function NodeToReportStr : string;
function ReportAsString : string;
end;
Description¶
TAVLTree maintains a balanced AVL tree. The tree consists of TAVLTreeNode nodes, each of which has a Data pointer associated with it. The TAVLTree component offers methods to balance and search the tree.
By default, the list is searched with a simple pointer comparison algorithm, but a custom search mechanism can be specified in the OnCompare property.
Properties¶
| Member | Visibility | Description |
|---|---|---|
| Count read only | public | Number of nodes in the tree. |
| NodeClass | public | Node class to create. |
| Root read only | public | Root node of the tree. |
Methods¶
| Member | Visibility | Description |
|---|---|---|
| Add | public | Add a new node to the tree. |
| AddAscendingSequence | public | |
| Assign | public | Assign another tree. |
| Clear | public | Clears the tree. |
| Compare | public | Compare 2 nodes. |
| ConsistencyCheck | public | Check the consistency of the tree. |
| Create | public | Create a new instance of TAVLTree. |
| CreateObjectCompare | public | Create an instance of the tree with extended compare method. |
| Delete | public | Delete a node from the tree. |
| Destroy | public | Destroy the TAVLTree instance. |
| DisposeNode | public | Dispose of a node outside of the tree. |
| Equals | public | Check if two trees are equal. |
| Find | public | Find a data item in the tree. |
| FindHighest | public | Find the highest (rightmost) node in the tree. |
| FindKey | public | Find a data item in the tree using alternate compare mechanism. |
| FindLeftMost | public | Find the node most left to a specified data node. |
| FindLeftMostKey | public | Find the node most left to a specified key node. |
| FindLeftMostSameKey | public | Find the node most left to a specified node with the same data. |
| FindLowest | public | Find the lowest (leftmost) node in the tree. |
| FindNearest | public | Find the node closest to the data in the tree. |
| FindNearestKey | public | Find nearest key for a data pointer. |
| FindPointer | public | Search for a data pointer. |
| FindPrecessor | public | |
| FindRightMost | public | Find the node most right to a specified node. |
| FindRightMostKey | public | Find the node most right to a specified key node. |
| FindRightMostSameKey | public | Find the node most right of a specified node with the same data. |
| FindSuccessor | public | Find successor to node. |
| FreeAndClear | public | Clears the tree and frees nodes. |
| FreeAndDelete | public | Delete a node from the tree and destroy it. |
| GetEnumerator | public | Get an enumerator for the tree. |
| GetEnumeratorHighToLow | public | Return an enumerator that enumerates the tree in reversed order. |
| IsEqual | public | Check whether 2 tree instances are equal. |
| MoveDataLeftMost | public | Move data to the nearest left element. |
| MoveDataRightMost | public | Move data to the nearest right element. |
| NewNode | public | Create a new tree node. |
| NodeToReportStr | public | Create a textual dump of the tree. |
| Remove | public | Remove a data item from the list. |
| RemovePointer | public | Remove a pointer item from the list. |
| ReportAsString | public | Return the tree report as a string. |
| SetNodeManager | public | Set the node instance manager to use. |
| WriteReportToStream | public | Write the contents of the tree consistency check to the stream. |
Events¶
| Member | Visibility | Description |
|---|---|---|
| OnCompare | public | Compare function used when comparing nodes. |
| OnObjectCompare | public | Compare handler. |
See also¶
| Name | Description |
|---|---|
| TAVLTreeNode | Represents a node in the tree. |