[Lazarus] How to iterate through a TAvgLvlTree

Martin lazarus at mfriebe.de
Fri Mar 16 11:51:49 CET 2012


On 16/03/2012 10:36, Felipe Monteiro de Carvalho wrote:
> Can I add a routine to access the AvgLvlTree as an array? To make it a
> better substitute to TFPList in objects which offer an indirect
> interface to the internal list, such as TLazAccessibleObject.
>
> My idea is defining:
> Index zero = Tree.FindLowest
> Indez Count-1= Tree.FindHighest
>
> On each access store the last accessed node and if the next call wants
> a node index=oldindex+1 or -1 then just use:
>
>   Tree.FindSuccessor(Node)
>   Tree.FindPrecessor(Node)
>
> Because almost always I use the array access only to iterate in a loop.
>
> Non-ordened access ofcourse would be slow because it would require a
> loop till the index is found.
>
And don't forget to invalidate the index on any node operation 
(*change/add/remove)

But I would try to avoid that.

If you need that, synedi has an AVL tree which can be used (abused) to 
keep track of the position/index. It will need minor modifications, as 
it currently stores the data, as difference to the previous node, rather 
than absolute value




More information about the Lazarus mailing list