Tree::Binary::Dictionary - A dictionary API to a binary tree
A 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.
use 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();
my $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.
$dictionary->rebuild();
Rebuilds the internal binary tree to reduce wasteful memory use
my $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.
my $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
$dictionary->exists('bar');
my $value = $dictionary->get('eeee');
my $deleted = $dictionary->delete('cccc');
my %hash = $dictionary->to_hash;
returns a hash populated from the dictionary
my @values = $dictionary->values;
returns dictionary values as an array
my @keys = $dictionary->keys;
returns dictionary keys as an array
my $count = $dictionary->count
returns the number of entries in the dictionary
Tree::Binary
aaron trevena, <teejay@droogs.org>
Copyright (C) 2006 by Aaron Trevena
This 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.
To install Tree::Binary::Dictionary, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tree::Binary::Dictionary
CPAN shell
perl -MCPAN -e shell install Tree::Binary::Dictionary
For more information on module installation, please visit the detailed CPAN module installation guide.