Sign in Join
FPDoc Onlineexperiment

TAVLTree.AddAscendingSequence function

Member of TAVLTreepublicIn unit AVL_Tree

Declaration

pascal
function AddAscendingSequence(Data: Pointer; LastAdded: TAVLTreeNode; 
 var Successor: TAVLTreeNode): TAVLTreeNode

Arguments

Data

Data to insert.

LastAdded

Last added node. Must initially be Nil.

Successor

Successor node. Must initially be Nil.

Function result

The newly inserted node.

Description

AddAscendingSequence is an optimized version of Add for quickly adding an ascending sequence of nodes. It adds Data between LastAdded and Successor as a state and skips searching for an insert position. For nodes with same value the order of the sequence is kept.

It can be used as follows:

LastNode:=nil; // TAvlTreeNode
Successor:=nil; // TAvlTreeNode
for i:=1 to 1000 do
 LastNode:=Tree.AddAscendingSequence(TItem.Create(i),LastNode,Successor);

If LastAdded is Nil a regular add is performed.

Errors

If the nodes are not in ascending order, the tree will not be consistent.

See also

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.