NAME

Tree::SEMETrie - Single-Edge Multi-Edge Trie

VERSION

Version 0.02

SYNOPSIS

COMING SOON

use Tree::SEMETrie;

my $trie = Tree::SEMETrie->new();
$trie->add('a long word', 23.7);
$trie->add('a longer word', 102);

for (my $iterator = $self->iterator; ! $iterator->is_done; $iterator->next) {
	print $iterator->key . ' => ' . $trie->find($iterator->key)->has_children
		if $trie->find_value($iterator->key) eq $iterator->value;
}

$trie->remove($_->[0]) for $trie->all;

SUBROUTINES/METHODS

Constructors

new

Create a new empty trie.

my $trie = Tree::SEMETrie->new;

Root Accessors/Mutators

children

Get the list of all immediate [edge => subtrie] pairs.

my @edge_subtrie_pairs = $trie->children;
my ($edge, $subtrie) = @{$edge_subtrie_pairs[0]};

childs

Alias for children.

value

Get/Set the value of the root. Return undef if there is no value.

my $new_value = $trie->value($new_value);

Root Verifiers

has_children

Return true if the root has any child paths.

$trie->has_children;

has_childs

Alias for has_children.

has_value

Return true if the root has an associated value.

$trie->has_value;

Trie Accessors

find

Find the root of a subtrie that matches the given key. If no such subtrie exists, return undef.

my $subtrie = $trie->find($key);

lookup

Alias for find.

find_value

Find the value associated with the given key. If no such key exists, return undef.

my $value = $trie->find_value($key);

lookup_value

Alias for find_value.

Trie Mutators

add

Insert a key into the trie. Return a reference to the key's value. In the case of a pre-existing key, the strategy function determines which value is stored. The default strategy function chooses the original value.

$trie->add('some path');
$trie->add('some path', 'optional value');
$trie->add('some path', 'new value to be ignored', sub { $_[0] });
$trie->add('some path', 'new value to be inserted', sub { $_[1] });

A custom strategy must conform to the following interface:

sub new_strategy {
	my ($current_value, $new_value) = @_;
	return $desired_value;
}

insert

Alias for add.

erase

Remove a key from the trie. Return the value associated with the removed key.

my $optional_value = $trie->erase('some path');

remove

Alias for erase.

merge

IN DEVELOPMENT

prune

IN DEVELOPMENT

Remove the entire subtrie of the given key. Return the removed subtrie.

Trie Traversal

all

Get a list of every key and its associated value as [key => value] pairs. Order is not guaranteed.

my @key_value_pairs = $trie->all;

iterator

Get a Tree::SEMETrie::Iterator for efficient trie traversal. Order is not guaranteed.

my $iterator = $trie->iterator;

AUTHOR

Aaron Cohen, <aarondcohen at gmail.com>

BUGS

Please report any bugs or feature requests to bug-tree-semetrie-fast at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tree-SEMETrie-Fast. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

TODO

  • Finish SYNOPSIS section.

  • Finish merge function.

  • Finish prune function.

  • Add benchmarking scripts.

  • Add SEE ALSO section.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Tree::SEMETrie

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2011 Aaron Cohen.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.