[fpc-devel] TAVLTree(avl_tree.pp) thread safety : second proposition

Mattias Gärtner nc-gaertnma at netcologne.de
Fri Aug 8 14:35:39 CEST 2008

Zitat von Henri Gourvest <hgourvest at progdigy.com>:

> 2008/8/8 Mattias Gärtner <nc-gaertnma at netcologne.de>:
> > Correct me if I'm wrong, but this seems not very comfortable.
> > - No custom sort function (unless you override)
> ...
> > - A node does not know its parent. So with First or Search you can not get
> to
> > the next node. You need always an iterator (iterators should be optional).
> it is your own opinion, personnaly I need more than one cursor on the tree.

I meant: I can not use the First to get to the second. I must create an
The current avl tree has a 'parent' of each node, so you can have as many
'cursors' as you want without iterators. I know this costs an extra pointer
memory per node, which might be bad in some cases. But I was talking about

> > - no function to resort the tree
> the tree is autobalanced

.. with a compare function. If you want to change the compare function, you need
to create a new avl tree and add manually all nodes. The current FPC avl tree
has a simple property for the compare function which can be set any time.

> > - no functions to reorder nodes with same keys
> it is useless, you can do everything in the same compare function if
> you have more than one key.

I meant: For example: two different items with Compare(Item1,Item2)=0. The order
between those two is free and the avl tree does not care. So I can reorder them.
This is needed in some algorithms. You can work around this, but it is
comfortable to have the ability.

> > - You have to override to actually store some data
> You are describing an avl tree, it do exactly what it expected to do
> regardless of data type.

I meant the default tree can not even store a pointer. You have to create a

> it is usefull for me, I hope it will be usefull for someoneelse.

No offense meant. I just pointed out, that it misses some nice-to-haves.

> > - it's not 64bit save
> 8-| why do you say that ?

Because of this:
AVL_MAX_DEPTH = sizeof(longint) * 8;


More information about the fpc-devel mailing list