Tie::Hash::Treap - Ties a hash to a treap structure
use Tie::Hash::Treap;
my $T = tie my %hash, 'Tie::Hash::Treap';
my $key = 'a';
for (1..10) {
$hash{$key++} = $_;
}
foreach (keys %hash) {
print "<$_:$hash{$_}> ";
}
print "\n---\n";
delete $hash{'c'};
delete $hash{'g'};
$hash{e} = 'XXX';
for ($T->range_keys('b', 'i')){
print "<$_:$hash{$_}> ";
}
print "\n---\n";
print "min key: ", $T->min(),"\n";
__END__
<a:1> <b:2> <c:3> <d:4> <e:5> <f:6> <g:7> <h:8> <i:9> <j:10>
---
<b:2> <d:4> <e:XXX> <f:6> <h:8> <i:9>
---
min key: a
A treap is a form of randomized binary search tree and gets it name from combining a normal binary search tree with a heap (using random priorities). This module ties a hash to such a structure giving you a comparison ordered hash that is relatively efficient in both space and time.
Tie'ing the hash is done in the standard manner:
my $T = tie my %hash, 'Tie::Hash::Treap', \&compare_keys;
The third argument to tie is an optional argument that may either be a string: ``str'', ``rstr'', ``num'', ``rnum'' --- denoting stringwise, reverse stringwise, numeric, or reverse numeric ordering of keys respectively. Alternatively, you can supply a reference to a comparison routine that returns -1,0,1 just like any custom sort routine.
All standard hash functions are supported, as well as a few
additional object methods that may called on the object returned
from the tie() call.
min()max()min() or max() will be used respectively for the
or second argument.
Copyright 2002 Andrew Johnson (ajohnson@cpan.org) This is free software released under the same terms as perl itself.
perl, Tree::Treap