Algorithm-Bitonic-Sort
view release on metacpan or search on metacpan
lib/Algorithm/Bitonic/Sort.pm view on Meta::CPAN
package Algorithm::Bitonic::Sort;
use utf8;
use feature 'say';
use common::sense;
use constant DEBUG => $ENV{ALGORITHM_BITONIC_SORT_DEBUG};
if (DEBUG) {
require Data::Dumper::Simple;
}
our (@ISA, @EXPORT);
BEGIN {
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(bitonic_sort); # symbols to export on request
}
# "A supercomputer is a device for turning compute-bound problems into I/O-bound problems."
=encoding utf8
=head1 NAME
Algorithm::Bitonic::Sort - Sorting numbers with Bitonic Sort
=head1 VERSION
Version 0.06
=cut
our $VERSION = '0.06';
=head1 SYNOPSIS
Use L<Algorithm::Bitonic::Sort> with the following style.
use Algorithm::Bitonic::Sort;
my @sample = (1,4,8,4,4365,2,67,33,345);
my @result_inc = bitonic_sort( 1 ,@sample); # incremental
my @result_dec = bitonic_sort( 0 ,@sample); # decremental
=head1 DESCRIPTION
Bitonic mergesort is a parallel algorithm for sorting. It is also used as a construction method for building a sorting network.
This is an Perl 5 implementation of Ken Batcher's Bitonic mergesort.
=head1 Limitation
This is a enhanced version of Bitonic Sort which removed the limitation of original version.
This module supports any amount of numbers.
The original Bitonic can only sort N numbers, which N is a power of 2.
=head1 EXPORT
bitonic_sort
=head1 SUBROUTINES
=head2 bitonic_sort
The First Parameter works as the ascending/decreasing selector.
True (1 or any true value) means ascending (incremental),
False (0 or any false value) means decreasing.
All other params will be treated as members/items to be sorted.
=cut
sub bitonic_sort {
my $up = shift;
say '#### Sort: '.Dumper(@_) if DEBUG;
return @_ if int @_ <= 1;
( run in 0.548 second using v1.01-cache-2.11-cpan-119454b85a5 )