NAME

Tie::Hash::Treap - Ties a hash to a treap structure


SYNOPSIS

    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


DESCRIPTION

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.


ADDITIONAL OBJECT METHODS

min()
Returns the minimum key in the hash (according to the comparison routine).

max()
Returns the maximum key in the hash (according to the comparison routine).

range_keys($key1, $key2)
Takes two optional arguments and returns all the keys in the hash greater than or equal to the first argument and less than or equal to the second argument. If any argument is missing or undefined the min() or max() will be used respectively for the or second argument.

range_values($key1, $key2)
Same as range_keys above but instead of returning the range of keys it returns the values for keys in the requested range.


AUTHOR

Copyright 2002 Andrew Johnson (ajohnson@cpan.org) This is free software released under the same terms as perl itself.


SEE ALSO

perl, Tree::Treap