|
NAMETree::Binary::Dictionary - A dictionary API to a binary treeDESCRIPTIONA simple class to provide a dictionary style API to a binary tree of data.This can provide a useful alternative to a long-lived hash in long running daemons and processes. SYNOPSISuse Tree::Binary::Dictionary;my $dictionary = Tree::Binary::Dictionary->new; # populate $dictionary->add(aaaa => "One"); $dictionary->add(cccc => "Three"); $dictionary->add(dddd => "Four"); $dictionary->add(eeee => "Five"); $dictionary->add(foo => "Foo"); $dictionary->add(bar => "quuz"); # interact $dictionary->exists('bar'); $dictionary->get('eeee'); $dictionary->delete('cccc'); # hash stuff my %hash = $dictionary->to_hash; my @values = $dictionary->values; my @keys = $dictionary->keys; # for long running processes $dictionary->rebuild(); METHODSnew - constructormy $dictionary = Tree::Binary::Dictionary->new (cache => 0);Instantiates and returns a new dictionary object. Optional arguments are cache, which will re-use internal objects and structures rather than rebuilding them as required. Default is 1 / True. rebuild$dictionary->rebuild();Rebuilds the internal binary tree to reduce wasteful memory use addmy $added = $dictionary->add(bar => "quuz");Adds new key and value in dictionary object, returns true on success, warns and returns 0 on duplicate key or other failure. setmy $set = $dictionary->set(bar => 'quuuz');Sets key and value in dictionary object, returns true on success, 0 on error. This will add a new key and value if the key is new, or update the value of an existing key exists$dictionary->exists('bar');getmy $value = $dictionary->get('eeee');deletemy $deleted = $dictionary->delete('cccc');to_hashmy %hash = $dictionary->to_hash;returns a hash populated from the dictionary valuesmy @values = $dictionary->values;returns dictionary values as an array keysmy @keys = $dictionary->keys;returns dictionary keys as an array countmy $count = $dictionary->countreturns the number of entries in the dictionary SEE ALSOTree::BinaryAUTHORaaron trevena, <teejay@droogs.org>COPYRIGHT AND LICENSECopyright (C) 2006 by Aaron TrevenaThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.
Visit the GSP FreeBSD Man Page Interface. |