Tree::BPTree

Tree::BPTree is a Perl implementation of B+ trees.
Download

Tree::BPTree Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Andrew Sterling Hanenkamp
  • Publisher web site:
  • http://search.cpan.org/~hanenkamp/

Tree::BPTree Tags


Tree::BPTree Description

Tree::BPTree is a Perl implementation of B+ trees. Tree::BPTree is a Perl implementation of B+ trees.SYNOPSIS use Tree::BPTree; # These arguments are actually the defaults my $tree = new Tree::BPTree( -n => 3, -unique => 0, -keycmp => sub { $_ cmp $_ }, -valuecmp => sub { $_ $_ }, ); # index the entries in this string: my $string = "THERE'S MORE THAN ONE WAY TO DO IT"; # TMTOWTDI my $i = 0; $tree->insert($_, $i++) foreach (split //, $string); # find the index of the first 'T' my $t = $tree->find('T'); # find the indexes of every 'T' my @t = $tree->find('T'); # We don't like the word 'WAY ', so let's remove it my $i = index $string, 'W'; $tree->delete($_, $i++) foreach (split //, substr($string, $i, 4)); # Reverse the sort order $tree->reverse; # Iterate through each key/value pair just like built-in each operator while (my ($key, $value) = $tree->each) { print "$key => $valuen"; } # Reset the iterator when we quit from an "each-loop" early $tree->reset; # You might also be interested in using multiple each loops at once, which is # possible through the cursor syntax. You can even delete individual pairs # from the list during iteration. my $cursor = $tree->new_cursor; while (my ($key, $value) = $cursor->each) { my $nested = $tree->new_cursor; while (my ($nkey, $nvalue) = $nested->each) { if ($key->shouldnt_be_in_this_tree_with($nkey)) { $nested->delete; } } } # Iterate using an iterator subroutine $tree->iterate(sub { print "$_ => $_n" }); # Iterate using an iterator subroutine that returns the list of return values # returned by the iterator print join(', ', $tree->map(sub { "$_ => $_" })),"n"; # Grep-like operations my @pairs = $tree->grep (sub { $_ =~ /S/ }); my @keys = $tree->grep_keys (sub { $_ =~ /S/ }); my @values = $tree->grep_values (sub { $_ =~ /S/ }); # Get all keys, values my @all_keys = $tree->keys; my @all_values = $tree->values; # Clear it out and start over $tree->clear;B+ trees are balanced trees which provide an ordered map from keys to values. They are useful for indexing large bodies of data. They are similar to 2-3-4 Trees and Red-Black Trees. This implementation supports B+ trees using an arbitrary n value.Requirements:· Perl Requirements: · Perl


Tree::BPTree Related Software