Tree::SEMETrie - Single-Edge Multi-Edge Trie
Version 0.03
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;
Create a new empty trie.
my $trie = Tree::SEMETrie->new;
Get the list of all immediate [edge => subtrie] pairs.
my @edge_subtrie_pairs = $trie->children; my ($edge, $subtrie) = @{$edge_subtrie_pairs[0]};
Alias for children.
Get/Set the value of the root. Return undef if there is no value.
my $new_value = $trie->value($new_value);
Return true if the root has any child paths.
$trie->has_children;
Alias for has_children.
Return true if the root has an associated value.
$trie->has_value;
Find the root of a subtrie that matches the given key. If no such subtrie exists, return undef.
my $subtrie = $trie->find($key);
Alias for find.
Find the value associated with the given key. If no such key exists, return undef.
my $value = $trie->find_value($key);
Alias for find_value.
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; }
Alias for add.
Remove a key from the trie. Return the value associated with the removed key.
my $optional_value = $trie->erase('some path');
Alias for erase.
IN DEVELOPMENT
Remove the entire subtrie of the given key. Return the removed subtrie.
Get a list of every key and its associated value as [key => value] pairs. Order is not guaranteed.
my @key_value_pairs = $trie->all;
Get a Tree::SEMETrie::Iterator for efficient trie traversal. Order is not guaranteed.
my $iterator = $trie->iterator;
Aaron Cohen, <aarondcohen at gmail.com>
<aarondcohen at gmail.com>
Please report any bugs or feature requests to bug-tree-semetrie at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tree-SEMETrie. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-tree-semetrie at rt.cpan.org
Finish SYNOPSIS section.
Finish merge function.
Finish prune function.
Add benchmarking scripts.
Add SEE ALSO section.
You can find documentation for this module with the perldoc command.
perldoc Tree::SEMETrie
You can also look for information at:
Official GitHub Repository
http://github.com/shutterstock/Tree-SEMETrie
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tree-SEMETrie
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Tree-SEMETrie
CPAN Ratings
http://cpanratings.perl.org/d/Tree-SEMETrie
Search CPAN
http://search.cpan.org/dist/Tree-SEMETrie/
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.
To install Tree::SEMETrie, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tree::SEMETrie
CPAN shell
perl -MCPAN -e shell install Tree::SEMETrie
For more information on module installation, please visit the detailed CPAN module installation guide.