# Preferred use tie %tree, 'Paranoid::Data::AVLTree'; # Or, purely as an object $tree = new Paranoid::Data::AVLTree; $count = $tree->count; $height = $tree->height; @keys = $tree->nodeKeys; $rv = $tree->nodeExists($key): $val = $tree->fetchVal($key); $rv = $tree->addPair($key, $value); $rv = $tree->delNode($key); $rv = $tree->purgeNodes; $tree->dumpKeys; $tree->profile(1); %stats = $tree->stats; $rv = $tree->save2File($filename); $rv = $tree->loadFromFile($filename);
NOTE: while these objects do support assignment of any arbitrary value to each node, spooling to and from files only supports the use of scalar values. Any object/code references, globs, or nested data structures will not survive save/load functionality.
$tree = new Paranoid::Data::AVLTree;
This creates a new tree object.
$rv = $obj->profile(1); $rv = $obj->profile(0);
This method enables or disables performance profiling, which can provide some basic statistics on internal operations. Whenever profiling is enabled the counters are reset.
%stats = $obj->stats;
This method returns a hash of various performance counters. The contents of the hash at this time consists of the following:
key purpose ------------------------------------------------ insertions number of node insertions deletions number of node deletions rebalances number of rebalances triggered rotations number of branch rotations triggered
$count = $tree->count;
This method returns a count of all the nodes in the tree.
$height = $tree->height;
This method returns the height of the tree.
@keys = $tree->nodeKeys;
This method returns a list of all keys for all nodes in the tree.
$rv = $tree->nodeExists($key):
This method returns a boolean value indicating whether a node exists wtih a matching key.
$val = $tree->fetchVal($key);
This method returns the associated value for the passed key. Like hashes, it will return undef for nonexistant keys.
$rv = $tree->addPair($key, $value);
This method adds the requested key/value pair, or updates an existing node with the same key. It will return a boolean false if the key is an invalid value.
$rv = $tree->delNode($key);
This method deletes the specified node if it exists. It will return boolean false should no matching node exist.
$rv = $tree->purgeNodes;
This purges all nodes from the tree.
$tree->dumpKeys;
This method exists purely for diagnostic purposes. It dumps a formatted tree structure to STDERR showing all keys in the tree, along with the relative branch height and balance of every node, along with what side of the tree each node is attached.
$rv = $tree->save2File($filename);
This method saves the current contents of the AVL Tree to the specified file. It attempts to save the nodes in an order which minimizes the number of rotations when read to maximize loading performance.
$rv = $tree->loadFromFile($filename);
This method loads the contents of the named file into memory. It does only the most rudimentary validation of records upon loading. Note that the current contents of the AVL Tree is purged prior to loading to ensure the contents after loading reflect precisely what is in the file. That said, if there is any kind of file corruption in the middle of the file, it can mean the AVL Tree is only partially loaded after a failed attempt.
a) the GNU General Public License <https://www.gnu.org/licenses/gpl-1.0.html> as published by the Free Software Foundation <http://www.fsf.org/>; either version 1 <https://www.gnu.org/licenses/gpl-1.0.html>, or any later version <https://www.gnu.org/licenses/license-list.html#GNUGPL>, or b) the Artistic License 2.0 <https://opensource.org/licenses/Artistic-2.0>,
subject to the following additional term: No trademark rights to ``Paranoid'' have been or are conveyed under any of the above licenses. However, ``Paranoid'' may be used fairly to describe this unmodified software, in good faith, but not as a trademark.
(c) 2005 - 2020, Arthur Corliss (corliss@digitalmages.com) (tm) 2008 - 2020, Paranoid Inc. (www.paranoid.com)
Copyright © 1997 - 2019, Arthur Corliss, all rights reserved.