NAME

Tree::Binary::Dictionary - A dictionary API to a binary tree

DESCRIPTION

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.

SYNOPSIS

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();

METHODS

new - constructor

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.

rebuild

$dictionary->rebuild();

Rebuilds the internal binary tree to reduce wasteful memory use

add

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.

set

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

exists

$dictionary->exists('bar');

get

my $value = $dictionary->get('eeee');

delete

my $deleted = $dictionary->delete('cccc');

to_hash

my %hash = $dictionary->to_hash;

returns a hash populated from the dictionary

values

my @values = $dictionary->values;

returns dictionary values as an array

keys

my @keys = $dictionary->keys;

returns dictionary keys as an array

count

my $count = $dictionary->count

returns the number of entries in the dictionary

SEE ALSO

Tree::Binary

AUTHOR

aaron trevena, <teejay@droogs.org>

COPYRIGHT AND LICENSE

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.