Algorithm-SkipList
view release on metacpan or search on metacpan
lib/Algorithm/SkipList/Node.pm view on Meta::CPAN
package Algorithm::SkipList::Node;
use 5.006;
use strict;
use warnings;
our $VERSION = '1.02';
# $VERSION = eval $VERSION;
use enum qw( HEADER=0 KEY VALUE );
sub new {
my ($class, $key, $value, $hdr) = @_;
my $self = [ ($hdr || [ ]), $key, $value ];
bless $self, $class;
}
sub header {
my ($self, $hdr) = @_;
$self->[HEADER];
}
# sub prev {
# my ($self, $prev) = @_;
# return (@_ > 1) ? ( $self->[PREV] = $prev ) : $self->[PREV];
# }
sub level {
my ($self) = @_;
scalar( @{$self->[HEADER]} );
}
sub key {
my ($self, $key) = @_;
$self->[KEY];
}
sub key_cmp {
my ($self, $right) = @_;
# OPT: It would be nice to use $self->key instead of $self->[KEY],
# but we gain a nearly 25% speed improvement!
($self->[KEY] cmp $right);
}
sub value {
my ($self, $value) = @_;
(@_ > 1) ? ( $self->[VALUE] = $value ) : $self->[VALUE];
}
1;
__END__
=head1 NAME
Algorithm::SkipList::Node - node class for Algorithm::SkipList
=head1 REQUIREMENTS
The following non-standard modules are used:
enum
=head1 DESCRIPTION
Methods are documented below.
=over
( run in 2.184 seconds using v1.01-cache-2.11-cpan-5b529ec07f3 )