DataStructure
view release on metacpan or search on metacpan
lib/DataStructure/BTree/Node.pm view on Meta::CPAN
package DataStructure::BTree::Node;
use strict;
use warnings;
use utf8;
use feature ':5.24';
use feature 'signatures';
no warnings 'experimental::signatures';
use Scalar::Util qw(weaken);
sub new ($class, $tree, $value, $parent = undef, $left = undef, $right = undef) {
my $self = bless {
tree => $tree,
parent => $parent,
left => $left,
right => $right,
value => $value,
}, $class;
weaken($self->{tree});
return $self;
}
sub parent ($self) {
return $self->{parent};
}
sub left ($self) {
return $self->{left};
lib/DataStructure/DoubleList/Node.pm view on Meta::CPAN
package DataStructure::DoubleList::Node;
use strict;
use warnings;
use utf8;
use feature ':5.24';
use feature 'signatures';
no warnings 'experimental::signatures';
use Scalar::Util qw(weaken);
=pod
=head1 NAME
DataStructure::DoubleList::Node
=head1 SYNOPSIS
A single node (element) in a L<DataStructure::DoubleList>.
lib/DataStructure/DoubleList/Node.pm view on Meta::CPAN
# The constructor is private and should be called only by this package and its
# parent.
sub new ($class, $list, $prev, $next, $value) {
my $self = bless {
list => $list,
prev => $prev,
next => $next,
value => $value,
}, $class;
weaken($self->{list});
return $self;
}
=pod
=head2 METHODS
All the functions below are class methods that should be called on a
C<DataStructure::DoubleList::Node> object.
lib/DataStructure/LinkedList/Node.pm view on Meta::CPAN
package DataStructure::LinkedList::Node;
use strict;
use warnings;
use utf8;
use feature ':5.24';
use feature 'signatures';
no warnings 'experimental::signatures';
use Scalar::Util qw(weaken);
=pod
=head1 NAME
DataStructure::LinkedList::Node
=head1 SYNOPSIS
A single node (element) in a L<DataStructure::LinkedList>.
lib/DataStructure/LinkedList/Node.pm view on Meta::CPAN
=cut
# The constructor is private and should be called only by this package and its
# parent.
sub new ($class, $list, $next, $value) {
my $self = bless {
list => $list,
next => $next,
value => $value,
}, $class;
weaken($self->{list});
return $self;
}
=pod
=head2 METHODS
All the functions below are class methods that should be called on a
C<DataStructure::LinkedList::Node> object.
t/30-btree.t view on Meta::CPAN
use strict;
use warnings;
use utf8;
use Scalar::Util qw(weaken);
use Test2::Bundle::More;
use Test2::Tools::Target 'DataStructure::BTree';
skip_all();
t/30-doublelist.t view on Meta::CPAN
use strict;
use warnings;
use utf8;
use Scalar::Util qw(weaken);
use Test2::Bundle::More;
use Test2::Tools::Target 'DataStructure::DoubleList';
{
my $l = DataStructure::DoubleList->new();
isa_ok($l, 'DataStructure::DoubleList');
cmp_ok($l->size(), '==', 0, 'empty size');
ok(!defined($l->first()), 'no first on empty list');
ok(!defined($l->last()), 'no last on empty list');
t/30-doublelist.t view on Meta::CPAN
my $weak_ref;
my $weak_node;
{
my $l = DataStructure::DoubleList->new();
$l->unshift('abc');
$l->unshift('def');
my $f = $l->first;
$weak_ref = $l;
$weak_node = $f;
weaken($weak_ref);
weaken($weak_node);
}
ok(!defined $weak_ref, 'garbage collection');
ok(!defined $weak_node, 'garbage collection 2');
done_testing();
t/30-linkedlist.t view on Meta::CPAN
use strict;
use warnings;
use utf8;
use Scalar::Util qw(weaken);
use Test2::Bundle::More;
use Test2::Tools::Target 'DataStructure::LinkedList';
my $l = DataStructure::LinkedList->new();
isa_ok($l, 'DataStructure::LinkedList');
is_deeply([$l->values()], []);
ok($l->empty(), 'empty');
cmp_ok($l->size(), '==', 0, 'empty size');
ok(!defined($l->first()), 'no first on empty list');
t/30-linkedlist.t view on Meta::CPAN
my $weak_ref;
my $weak_node;
{
my $l = DataStructure::LinkedList->new();
$l->unshift('abc');
$l->unshift('def');
my $f = $l->first;
$weak_ref = $l;
$weak_node = $f;
weaken($weak_ref);
weaken($weak_node);
}
ok(!defined $weak_ref, 'garbage collection');
ok(!defined $weak_node, 'garbage collection 2');
done_testing();
( run in 0.252 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )