Algorithm-Networksort

 view release on metacpan or  search on metacpan

lib/Algorithm/Networksort.pm  view on Meta::CPAN


I<Default value: "  " (two spaces).>
The characters that start the gap between the input lines.

=item 'gapcompline'

I<Default value: " | " (space vertical bar space).>
The characters that make up the gap with a comparator passing through.

=item 'gapnone'

I<Default value: "  " (three spaces).>
The characters that make up the space between the input lines.

=item 'gapend'

I<Default value: "  \n" (two spaces and a newline).>
The characters that end the gap between the input lines.

=back

=cut

sub textsettings
{
	my $self = shift;
	my %settings = @_;
	my %old_settings;

	return %textset if (scalar @_ == 0);

	for my $k (keys %settings)
	{
		#
		# If it's a real part to graph, save the
		# old value, then set it.
		#
		if (exists $textset{$k})
		{
			$old_settings{$k} = $textset{$k};
			$textset{$k} = $settings{$k};
		}
		else
		{
			carp "textsettings(): Unknown key '$k'";
		}
	}

	return %old_settings;
}

#
# @newlist = semijoin($expr, $itemcount, @list);
#
# $expr      - A string to be used in a join() call.
# $itemcount - The number of items in a list to be joined.
#              It may be negative.
# @list      - The list
#
# Create a new list by performing a join on I<$itemcount> elements at a
# time on the original list. Any leftover elements from the end of the
# list become the last item of the new list, unless I<$itemcount> is
# negative, in which case the first item of the new list is made from the
# leftover elements from the front of the list.
#
sub semijoin
{
	my($jstr, $itemcount, @oldlist) = @_;
	my(@newlist);

	return @oldlist if ($itemcount <= 1 and $itemcount >= -1);

	if ($itemcount > 0)
	{
		push @newlist, join $jstr, splice(@oldlist, 0, $itemcount)
			while @oldlist;
	}
	else
	{
		$itemcount = -$itemcount;
		unshift @newlist, join $jstr, splice(@oldlist, -$itemcount, $itemcount)
		    while $itemcount <= @oldlist;
		unshift @newlist, join $jstr, splice( @oldlist, 0, $itemcount)
		    if @oldlist;
	}

	return @newlist;
}

1;
__END__

=head1 ACKNOWLEDGMENTS

L<Doug Hoyte|https://github.com/hoytech> provided the code for the bitonic,
odd-even merge, odd-even transposition, balanced, and bubble sort algorithms,
and the idea for what became the L<statistics()> method.

L<Morwenn|https://github.com/Morwenn> found documentation errors and networks
that went into L<Algorithm::Networksort::Best>.

=head1 SEE ALSO

=head2 Bose and Nelson's algorithm.

=over 3

=item

Bose and Nelson, "A Sorting Problem", Journal of the ACM, Vol. 9, 1962, pp. 282-296.

=item

Joseph Celko, "Bose-Nelson Sort", Doctor Dobb's Journal, September 1985.

=item

Frederick Hegeman, "Sorting Networks", The C/C++ User's Journal, February 1993.

=item



( run in 1.434 second using v1.01-cache-2.11-cpan-5b529ec07f3 )