Algorithm-Networksort
view release on metacpan or search on metacpan
- Added David C. Van Voorhis's 16-input network (found in
Designing Sorting Networks) to Best.pm.
2.01
Wed Apr 20 2016
- Add nwsrt_title() to the list of default exported functions
in Networksort.pm for consistency with ::Best.pm and for the
programs that call it.
- Explain this in documentation.
- Also for consistency, =item items are now enclosed in
single quotes in both modules.
- Grey background in SVG at begining lightened up.
2.00
Tue Apr 12 2016
- The module now returns the sorting network as an object.
This is obviously a major change; please see the documentation
for reassuring examples. The OO basis is Moose, plus
Moose::Exporter for a couple of convenience functions. The
function-heavy Version 1.30 will remain on CPAN for at
least another year in the mean time.
- The collection of 'best' networks has been greatly added to,
Algorithm::Networksort::Optimal, but 'optimal' has seven
letters and 'best' has four, so 'best' wins.
- Doug Hoyte provided code for an astonishing three more
algorithms: odd-even merge, odd-even transposition, and balanced.
- The example scripts in eg/ have been updated and in some
cases improved.
- Found untested cases (formats in particular) and added them
to the tests.
- SVG output is massively improved. The graphing example is now
HTML5 instead of XML, beginning circles now cover their line
instead of vice versa, background color is now supported, and
the ids of graph elements now have a random component in them
so as not to confuse the parser if more than one graph is on
the page (this is one that bit me).
1.31
Sat Mar 22 2012
- Good grief, I mis-spelled nw_comparators() in the
documentation.
- And I left out abecedarian.t in the MANIFEST.
1.30
Tue Nov 20 2012
vt_sep => 12,
);
my %colorset = (compbegin => undef,
compend => undef,
compline => undef,
inputbegin => undef,
inputend => undef,
inputline => undef,
foreground => undef,
background => undef,
);
my $alg = 'bosenelson';
my($nw, $best);
GetOptions('co_cb=s' => \$colorset{compbegin},
'co_ce=s' => \$colorset{compend},
'co_cl=s' => \$colorset{compline},
'co_ib=s' => \$colorset{inputbegin},
'co_ie=s' => \$colorset{inputend},
'co_il=s'=> \$colorset{inputline},
'co_fg=s' => \$colorset{foreground},
'co_bg=s' => \$colorset{background},
#
'hz_margin=i' => \$graphset{hz_margin},
'hz_sep=i' => \$graphset{hz_sep},
'indent=i' => \$graphset{indent},
'inputradius=i' => \$graphset{inputradius},
'compradius=i' => \$graphset{compradius},
'inputline=i' => \$graphset{inputline},
'compline=i' => \$graphset{compline},
'vt_margin=i' => \$graphset{vt_margin},
'vt_sep=i' => \$graphset{vt_sep},
vt_sep => 12,
);
my %colorset = (compbegin => undef,
compend => undef,
compline => undef,
inputbegin => undef,
inputend => undef,
inputline => undef,
foreground => undef,
background => undef,
);
my $alg = 'bosenelson';
my($nw, $best);
GetOptions('co_cb=s' => \$colorset{compbegin},
'co_ce=s' => \$colorset{compend},
'co_cl=s' => \$colorset{compline},
'co_ib=s' => \$colorset{inputbegin},
'co_ie=s' => \$colorset{inputend},
'co_il=s'=> \$colorset{inputline},
'co_fg=s' => \$colorset{foreground},
'co_bg=s' => \$colorset{background},
#
'hz_margin=i' => \$graphset{hz_margin},
'hz_sep=i' => \$graphset{hz_sep},
'indent=i' => \$graphset{indent},
'inputradius=i' => \$graphset{inputradius},
'compradius=i' => \$graphset{compradius},
'inputline=i' => \$graphset{inputline},
'compline=i' => \$graphset{compline},
'vt_margin=i' => \$graphset{vt_margin},
'vt_sep=i' => \$graphset{vt_sep},
lib/Algorithm/Networksort.pm view on Meta::CPAN
# Default graphing color parameters.
#
my %colorset = (
foreground => undef,
inputbegin => undef,
inputline => undef,
inputend => undef,
compbegin => undef,
compline=> undef,
compend => undef,
background => undef,
);
has algorithm => (
isa => 'Str', is => 'ro',
default => 'bosenelson',
);
has inputs => (
isa => 'Int', is => 'ro', required => 1,
);
lib/Algorithm/Networksort.pm view on Meta::CPAN
$vcoord[$idx] += $idx * ($grset{vt_sep} + $grset{inputline});
}
return @vcoord;
}
sub colorswithdefaults
{
#
# Get the colorset, using the foreground color as the default color
# for drawing, except for 'background', which has its own default.
#
my @keylist = grep{$_ !~ /background/} keys %colorset;
my %clrset = map{$_ => ($colorset{$_} // $colorset{foreground} // '#000')}
@keylist;
$clrset{background} = $colorset{background};
#
#### colorset after defaults are set: %clrset
#
return %clrset;
}
#
# Helper function to see if the drawing colors are all identical.
# The hash is presumed to be one returned by colorswithdefaults().
#
sub ismonotone
{
my (%clrs) = @_;
my @keylist = grep{$_ !~ /foreground|background/} keys %colorset;
return !scalar grep{$clrs{$_} ne $clrs{foreground}} @keylist;
}
#
# For the postscript setrgbcolor operator.
#
sub psrgbcolor
{
my $color = $_[0] // '000';
lib/Algorithm/Networksort.pm view on Meta::CPAN
$string .= qq(} bind def\n\n);
#
# Save the current graphics state, then change the drawing
# coordinates (from (0,0) = lower left to (0,0) = upper left),
# and the color if we're drawing in a single color.
#
$string .= qq(gsave\n0 $ybound translate\n1 -1 scale\n);
$string .= qq($clrset{foreground}\n) if ($monotone);
if (defined $clrset{background})
{
$string .= qq(\ngsave $clrset{background}\n);
$string .= qq(0 0 moveto 0 $ybound lineto $xbound $ybound lineto $xbound 0 lineto closepath);
$string .= qq(\nfill grestore\n);
}
#
# Draw the input lines.
#
$string .= qq(\n%\n% Draw the input lines.\n%\n$grset{inputline} setlinewidth\n) .
qq(0 1 ) . ($inputs-1) . qq( {draw-inputline} for\n);
lib/Algorithm/Networksort.pm view on Meta::CPAN
}
$string .= qq( </defs>\n\n);
#
# End of definitions. Draw the input lines as a group.
#
$string .= qq( <g id=") . $self->nwid() . qq($salt">\n);
#
# If there's a background color, insert as the first element a <rect>
# with the full size of the view and a fill of the desired color.
#
if (defined $clrset{background})
{
$string .= qq( <rect width="100%" height="100%" style="fill:$clrset{background}" />\n);
}
$string .= qq( <!-- Draw the input lines. -->\n);
$string .= qq( <use xlink:href="#I$salt" y="$vcoord[$_]" />\n) for (0..$inputs-1);
#
# Draw our comparators.
# Each member of a group of comparators is drawn in the same column.
#
$string .= qq(\n <!-- Draw the comparator lines. -->\n);
lib/Algorithm/Networksort.pm view on Meta::CPAN
The comparator line.
=item 'compend'
Closing of the comparator line.
=item 'foreground'
Default color for the graph as a whole.
=item 'background'
Color of the background.
=back
All parts I<not> named are reset to 'undef' (which means calling
C<colorsettings()> with no arguments resets everything), and will be
colored with the 'foreground' color. The foreground color itself has a
default value of '#000000' (black). The one exception is 'background',
which has no default color at all.
=cut
sub colorsettings
{
my $self = shift;
my %settings = @_;
my %old_settings;
is_well_formed_xml($svg, "Test with default SVG settings");
diag($svg) if ($show_svg);
#
# Now create one that has the defaults changed.
#
$nw->title($nw->inputs . " input network using " . $nw->algorithm);
$nw->colorsettings(
background => 'grey',
compbegin => 'red',
compend => 'blue');
$nw->graphsettings(
vt_margin => 25,
vt_sep => 16,
indent => 8,
hz_margin => 20,
hz_sep => 16,
inputradius => 0,
( run in 0.674 second using v1.01-cache-2.11-cpan-f56aa216473 )