Generic abstract class to manage a AVL tree. AVL tree is a self balancing data structure that keeps a binary tree almost balanced. It has the restriction that all nodes have children with, at most, one level of difference between them. This constraint is stronger than those of the red-black trees and, as such, the cost for balance maintenance is higher. It has O(log n) complexity for searches, insertions and deletions. The delete operator has a constant multiplier higher than insertions. The height of an AVL tree is strictly less than 1.44 log(n + 2) - 0.328. It is more rigidly balanced than red-black trees leading to slower insertion and removals but slightly faster searches. The nodes in this tree must be comparable. As such, a class specialization must provide gcgAVLTREE::compare() method that has the function of determining if two gcgORDEREDNODE nodes are equal, greater or smaller. Use the gcgAVLTREE::getIterator() to obtain a fast iterator to traverse the AVL nodes in ascending or descending order.
More...
|
| gcgAVLTREE () |
| Constructs a valid and empty AVL tree. More...
|
|
virtual | ~gcgAVLTREE () |
| Destroys the AVL tree, releasing all nodes. All entries are deleted. More...
|
|
gcgORDEREDNODE * | insert (gcgORDEREDNODE *newnode) |
| Inserts a new entry newnode in the AVL tree. The tree is adjusted to keep the restriction that both children of all nodes must have heights differing of at most one level. Insertions take O(log n) operations to be finished. At most one tree rotation is performed. All nodes in the tree must be unique, i.e., they are mutually different in respect to gcgORDEREDNODE::compare() method. More...
|
|
gcgORDEREDNODE * | search (gcgORDEREDNODE *key) |
| Retrieves the entry of the AVL tree that is similar to the key in respect to the gcgAVLTREE::compare() method. The gcgAVLTREE::compare() method must return zero only for an unique node of the tree. AVL searchs take O(log n) operations to be finished and are slighly more efficient than in red-black trees. More...
|
|
gcgORDEREDNODE * | remove (gcgORDEREDNODE *key) |
| Removes the entry of the AVL tree that is similar to the key in respect to the gcgAVLTREE::compare() method. The gcgAVLTREE::compare() method must return zero only for an unique node of the tree. The tree is adjusted to keep the restriction that both children of all nodes must have heights differing of at most one level. Removals take O(log n) operations to be finished. More than one tree rotation can be performed, which means that this operation has generally a greater time cost in comparison with insertion and search operations. More...
|
|
uintptr_t | getCounter () |
| Returns the number of elements stored in the AVL tree. More...
|
|
virtual bool | deleteAll () |
| Deletes and removes all entries from the AVL tree. All AVL tree resources are also released. More...
|
|
gcgITERATOR * | getIterator (int traversemode=0) |
| Returns an iterator for traversing the elements of the AVL tree. The traversal order is defined by the parameter traversemode. Currently, the tree nodes can be traversed in two ways: traversemode = 0, to iterate in ascending order (default); and traversemode = 1, to iterate in descending order. The AVL tree must not be changed by insertions, removals or moves while the iterator is being used. You must delete the returned iterator after use. The iterator copies a minimal information from the AVL tree. Note that deleting a iterator does not affect the nodes. More...
|
|
gcgITERATOR * | detach (int traversemode=0) |
| Force the AVL tree to be empty. It has the same effect as removing all entries from the AVL tree but keeping their chaining (which will used by the returned iterator). The entries are NOT deleted. In order to retrieve the detached entries, a gcgITERATOR is returned. This is useful to process the nodes freely and without the possible restrictions of the underlying AVL tree. Thus, the gcgITERATOR returned by gcgAVLTREE::detach() MUST be used to delete all the entries or reinsert them in another data structure. The traversal order of the returned iterator is defined by the parameter traversemode. Currently, the tree nodes can be traversed in two ways: traversemode = 0, to iterate in ascending order (default); and traversemode = 1, to iterate in descending order. All resources currently used by the AVL tree are released (becomes empty) but it can be reused normally. You must delete the gcgITERATOR after its use. More...
|
|
virtual int | compare (gcgORDEREDNODE *refnode1, gcgORDEREDNODE *refnode2)=0 |
| Method that must be furnished by a specialization of gcgAVLTREE and is responsible for comparing two gcgORDEREDNODE nodes. This is necessary for all tree operations of insertion, retrieval and removal. It must compare the two nodes pointed by refnode1 and refnode2 and return zero if they are equal, -1 if refnode1 is smaller or precedes refnode2, or 1 if refnode1 is grater or succeeds refnode2. More...
|
|
void * | operator new (size_t size) |
| Defines a new operator to be used by instatiations of GCGlib classes instead the global one. More...
|
|
void * | operator new (size_t size, const std::nothrow_t &) throw () |
| Defines a new operator to be used by instantiations of GCGlib classes instead the global one. Returns a NULL pointer instead of throwing an exception if an error occurs. More...
|
|
void * | operator new[] (size_t size) |
| Defines a new operator to be used by GCGlib array allocations instead the global one. More...
|
|
void * | operator new[] (size_t size, const std::nothrow_t &) throw () |
| Defines a new operator to be used by vector allocations instead the global one. More...
|
|
void | operator delete (void *p) |
| Defines a delete operator to free instances of GCGlib classes instead the global one. It is designed to match the new operator. More...
|
|
void | operator delete (void *p, const std::nothrow_t &) throw () |
| Defines a delete operator to free instances of GCGlib classes instead the global one. It is designed to match the new operator. More...
|
|
void | operator delete[] (void *p) |
| Defines a delete operator to free instances of arrays for GCGlib classes instead the global one. It is designed to match the new[] operator. More...
|
|
void | operator delete[] (void *p, const std::nothrow_t &) throw () |
| Defines a delete operator to free instances of arrays for GCGlib classes instead the global one. It is designed to match the new[] operator. More...
|
|
Generic abstract class to manage a AVL tree. AVL tree is a self balancing data structure that keeps a binary tree almost balanced. It has the restriction that all nodes have children with, at most, one level of difference between them. This constraint is stronger than those of the red-black trees and, as such, the cost for balance maintenance is higher. It has O(log n) complexity for searches, insertions and deletions. The delete operator has a constant multiplier higher than insertions. The height of an AVL tree is strictly less than 1.44 log(n + 2) - 0.328. It is more rigidly balanced than red-black trees leading to slower insertion and removals but slightly faster searches. The nodes in this tree must be comparable. As such, a class specialization must provide gcgAVLTREE::compare() method that has the function of determining if two gcgORDEREDNODE nodes are equal, greater or smaller. Use the gcgAVLTREE::getIterator() to obtain a fast iterator to traverse the AVL nodes in ascending or descending order.
- Since
- 0.04.179