Algorithm-DLX
view release on metacpan or search on metacpan
lib/Algorithm/DLX.pm view on Meta::CPAN
my ($class, $row, $col) = @_;
my $self = {
row => $row,
col => $col,
left => undef,
right => undef,
up => undef,
down => undef,
column => undef,
};
bless $self, $class;
return $self;
}
# Column structure for DLX
package DLX::Column;
use base 'DLX::Node';
sub new {
my ($class, $col) = @_;
my $self = $class->SUPER::new(undef, $col);
$self->{size} = 0;
$self->{name} = $col;
$self->{column} = $self;
bless $self, $class;
return $self;
}
# Main DLX package
package Algorithm::DLX;
sub new {
my ($class) = @_;
my $self = {
header => DLX::Column->new('header'),
solution => [],
solutions => [],
};
# Initialize header links
$self->{header}->{left} = $self->{header};
$self->{header}->{right} = $self->{header};
bless $self, $class;
return $self;
}
sub add_column {
my ($self, $col_name) = @_;
my $col = DLX::Column->new($col_name);
$col->{left} = $self->{header}->{left};
$col->{right} = $self->{header};
( run in 1.538 second using v1.01-cache-2.11-cpan-de7293f3b23 )