| 1 | package Sort::Packed; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 1 | require Exporter; | |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||
| 12 | 1 | our @EXPORT_OK = qw( sort_packed | |||||||||||||||||||||||||||||||
| 13 | radixsort_packed | ||||||||||||||||||||||||||||||||
| 14 | mergesort_packed | ||||||||||||||||||||||||||||||||
| 15 | sort_packed_custom | ||||||||||||||||||||||||||||||||
| 16 | mergesort_packed_custom | ||||||||||||||||||||||||||||||||
| 17 | reverse_packed | ||||||||||||||||||||||||||||||||
| 18 | shuffle_packed ); | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | # byte_order: | ||||||||||||||||||||||||||||||||
| 21 | # 0 - big endian | ||||||||||||||||||||||||||||||||
| 22 | # 1 - little endian | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | # type | ||||||||||||||||||||||||||||||||
| 25 | # 0 - unsigned | ||||||||||||||||||||||||||||||||
| 26 | # 1 - signed | ||||||||||||||||||||||||||||||||
| 27 | # 2 - float | ||||||||||||||||||||||||||||||||
| 28 | # 3 - float x86 | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 1 | my %nv_format = ( '5839b4c876bebf3f' => 'LE', | |||||||||||||||||||||||||||||||
| 31 | '3fbfbe76c8b43958' => 'BE', | ||||||||||||||||||||||||||||||||
| 32 | '83c0caa145b6f3fdfb3f0000' => 'LE_x86', | ||||||||||||||||||||||||||||||||
| 33 | '3ffbfbe76c8b4395810624dd2f1a9fbe' => 'BE', | ||||||||||||||||||||||||||||||||
| 34 | 'be9f1a2fdd24068195438b6ce7fbfb3f' => 'LE', | ||||||||||||||||||||||||||||||||
| 35 | '83c0caa145b6f3fdfb3f000000000000' => 'LE_x86'); | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | my $double_format = $nv_format{unpack 'H*' => pack d => 0.124} || 'LE'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$nv_format{unpack 'H*', "X9\264\310v\276\277?"} || 'LE'
MC/DC0%0/1
$nv_format{unpack 'H*', "X9\264\310v\276\277?"} || 'LE'
$nv_format{unpack 'H*', "X9\264\310v\276\277?"}
Truth table50%1/2
A
A= $nv_format{unpack 'H*', "X9\264\310v\276\277?"}
| |||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | my $double_byte_order = ($double_format =~ /^BE/ ? 0 : 1); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | my $double_type = ($double_format =~ /x86/ ? 2 : 3); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 1 | require XSLoader; | |||||||||||||||||||||||||||||||
| 42 | 1 | XSLoader::load('Sort::Packed', $VERSION); | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 1 | my %cache; | |||||||||||||||||||||||||||||||
| 45 | 42 | ▶ | sub _template_props { | ||||||||||||||||||||||||||||||
|
Subroutine
_template_props: called CC=11 SCAR=24.4
| |||||||||||||||||||||||||||||||||
| 46 | 42 | ▶ | my ($dir, $pattern, $rep) = $_[0] =~ /^([+\-]?)(\w!?)(\d*)$/ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 47 | or croak "invalid template '$_[0]'"; | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 42 | ▶ | $dir = ($dir eq '-' ? -1 : 1); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 50 | 42 | ▶ | $rep ||= 1; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$rep ||= 1
MC/DC0%0/1
$rep ||= 1
$rep
Truth table50%1/2
A
A= $rep
| |||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | 42 | ▶ | $pattern =~ /^[bBhHuUwxX]/ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | and croak "unsupported pack format '$pattern'"; | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 42 | my ($test1, $test2, $test3); | |||||||||||||||||||||||||||||||
| 56 | 42 | eval { | |||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | no warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 58 | 42 | $test1 = pack $pattern => 0x1; | |||||||||||||||||||||||||||||||
| 59 | 42 | $test2 = unpack $pattern => pack $pattern => -1; | |||||||||||||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||||||||||||||
| 61 | 42 | ▶ | $@ and croak "invalid pack pattern '$pattern': $@"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 42 | my $vsize = length $test1; | |||||||||||||||||||||||||||||||
| 64 | 42 | my $ix = index $test1, chr 0x1; | |||||||||||||||||||||||||||||||
| 65 | 42 | ▶ | my $vtype = ($test2 eq '-1' ? 1 : 0); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 66 | 42 | my $byte_order; | |||||||||||||||||||||||||||||||
| 67 | 42 | ▶ | if ($pattern =~ /^[fdFD]/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | 12 | $vtype = $double_type; | |||||||||||||||||||||||||||||||
| 69 | 12 | $byte_order = $double_byte_order; | |||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | else { | ||||||||||||||||||||||||||||||||
| 72 | 30 | ▶ | if ($vsize == 1 or $ix == $vsize - 1) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$vsize == 1 or $ix == $vsize - 1
MC/DC50%1/2
$vsize == 1 or $ix == $vsize - 1
$vsize == 1
$ix == $vsize - 1
Truth table66%2/3
A or B
A= $vsize == 1B= $ix == $vsize - 1
| |||||||||||||||||||||||||||||||||
| 73 | 6 | $byte_order = 0; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | elsif ($ix == 0) { | ||||||||||||||||||||||||||||||||
| 76 | 24 | $byte_order = 1; | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | else { | ||||||||||||||||||||||||||||||||
| 79 | 0 | croak "unsupported pack format '$pattern'" | |||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 42 | $dir, $vsize, $vtype, $byte_order, $rep | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 420 | ▶ | sub radixsort_packed { | ||||||||||||||||||||||||||||||
|
Subroutine
radixsort_packed: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 87 | 420 | ▶ | @_ == 2 or croak 'Usage: sort_packed($format, $vector)'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 88 | 420 | ▶ | my ($dir, $vsize, $vtype, $byte_order, $rep) = @{$cache{$_[0]} ||= [_template_props($_[0])]}; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$cache{$_[0]} ||= [_template_props($_[0])]
MC/DC100%1/1
$cache{$_[0]} ||= [_template_props($_[0])]
$cache{$_[0]}
Truth table100%2/2
A
A= $cache{$_[0]}
| |||||||||||||||||||||||||||||||||
| 89 | 420 | _radixsort_packed($_[1], $dir, $vsize, $vtype, $byte_order, $rep); | |||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 420 | ▶ | sub mergesort_packed { | ||||||||||||||||||||||||||||||
|
Subroutine
mergesort_packed: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 93 | 420 | ▶ | @_ == 2 or croak 'Usage: radixsort_packed($format, $vector)'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | 420 | ▶ | my ($dir, $vsize, $vtype, $byte_order, $rep) = @{$cache{$_[0]} ||= [_template_props($_[0])]}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$cache{$_[0]} ||= [_template_props($_[0])]
MC/DC0%0/1
$cache{$_[0]} ||= [_template_props($_[0])]
$cache{$_[0]}
Truth table50%1/2
A
A= $cache{$_[0]}
| |||||||||||||||||||||||||||||||||
| 95 | 420 | _mergesort_packed($_[1], undef, $dir, $vsize, $vtype, $byte_order, $rep); | |||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 1 | *sort_packed = \&radixsort_packed; | |||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 420 | ▶ | sub mergesort_packed_custom (&@) { | ||||||||||||||||||||||||||||||
|
Subroutine
mergesort_packed_custom: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 101 | 420 | ▶ | @_ == 3 or croak 'Usage: mergesort_packed_custom { cmp($a, $b) } $format, $vector'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 102 | 420 | ▶ | my ($dir, $vsize, $vtype, $byte_order, $rep) = @{$cache{$_[1]} ||= [_template_props($_[1])]}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$cache{$_[1]} ||= [_template_props($_[1])]
MC/DC0%0/1
$cache{$_[1]} ||= [_template_props($_[1])]
$cache{$_[1]}
Truth table50%1/2
A
A= $cache{$_[1]}
| |||||||||||||||||||||||||||||||||
| 103 | 420 | _mergesort_packed($_[2], $_[0], $dir, $vsize, $vtype, $byte_order, $rep); | |||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 1 | *sort_packed_custom = \&radixsort_packed_custom; | |||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub reverse_packed { | ||||||||||||||||||||||||||||||
|
Subroutine
reverse_packed: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | @_ == 2 or croak 'Usage: reverse_packed($format, $vector)'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | my (undef, $vsize, undef, undef, $rep) = @{$cache{$_[0]} ||= [_template_props($_[0])]}; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$cache{$_[0]} ||= [_template_props($_[0])]
MC/DC0%0/1
$cache{$_[0]} ||= [_template_props($_[0])]
$cache{$_[0]}
Truth table0%0/2
A
A= $cache{$_[0]}
| |||||||||||||||||||||||||||||||||
| 111 | 0 | _reverse_packed($_[1], $vsize * $rep); | |||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub shuffle_packed { | ||||||||||||||||||||||||||||||
|
Subroutine
shuffle_packed: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | @_ == 2 or croak 'Usage: shuffle_packed($format, $vector)'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my (undef, $vsize, undef, undef, $rep) = @{$cache{$_[0]} ||= [_template_props($_[0])]}; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$cache{$_[0]} ||= [_template_props($_[0])]
MC/DC0%0/1
$cache{$_[0]} ||= [_template_props($_[0])]
$cache{$_[0]}
Truth table0%0/2
A
A= $cache{$_[0]}
| |||||||||||||||||||||||||||||||||
| 117 | 0 | _shuffle_packed($_[1], $vsize * $rep); | |||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 1 | 1; | |||||||||||||||||||||||||||||||
| 121 | __END__ | ||||||||||||||||||||||||||||||||