line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Sort::Half::Maker; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
1490
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
50
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
839
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(make_halfsorter make_halfsort); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub make_halfsort { |
14
|
5
|
|
|
5
|
1
|
3556
|
my %args = @_; |
15
|
5
|
|
100
|
9
|
|
34
|
my $sort_sub = $args{fallback} || sub ($$) { $_[0] cmp $_[1] }; |
|
9
|
|
|
|
|
21
|
|
16
|
5
|
|
|
|
|
5
|
my %start_hash; |
17
|
5
|
100
|
|
|
|
15
|
if ( $args{start} ) { |
18
|
4
|
|
|
|
|
5
|
my @start = @{ $args{start} }; |
|
4
|
|
|
|
|
10
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#@start_hash{@start} = (1..@start); |
21
|
4
|
|
|
|
|
7
|
my $idx = 1; |
22
|
4
|
|
|
|
|
8
|
for (@start) { |
23
|
12
|
100
|
|
|
|
68
|
$start_hash{$_} = $idx unless exists $start_hash{$_}; |
24
|
12
|
|
|
|
|
24
|
$idx++; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
5
|
|
|
|
|
6
|
my %end_hash; |
28
|
5
|
100
|
|
|
|
12
|
if ( $args{end} ) { |
29
|
2
|
|
|
|
|
3
|
my @end = @{ $args{end} }; |
|
2
|
|
|
|
|
6
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#@end_hash{@end} = (1..@end); |
32
|
2
|
|
|
|
|
3
|
my $idx = 1 |
33
|
|
|
|
|
|
|
; # the same as "@end_hash{@end} = (1..@end)" but keeps the first occurrence |
34
|
2
|
100
|
|
|
|
4
|
for (@end) { $end_hash{$_} = $idx unless exists $end_hash{$_}; $idx++ } |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
11
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
return sub ($$) { |
37
|
52
|
|
|
52
|
|
4313
|
my ( $left, $right ) = @_; |
38
|
52
|
100
|
66
|
|
|
203
|
if ( $start_hash{$left} || $start_hash{$right} ) { |
|
|
100
|
66
|
|
|
|
|
39
|
26
|
|
66
|
|
|
63
|
my $ia = $start_hash{$left} || keys(%start_hash) + 1; |
40
|
26
|
|
66
|
|
|
71
|
my $ib = $start_hash{$right} || keys(%start_hash) + 1; |
41
|
26
|
|
|
|
|
41
|
return $ia <=> $ib; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
elsif ( $end_hash{$left} || $end_hash{$right} ) { |
44
|
8
|
|
100
|
|
|
21
|
my $ia = $end_hash{$left} || 0; |
45
|
8
|
|
100
|
|
|
21
|
my $ib = $end_hash{$right} || 0; |
46
|
8
|
|
|
|
|
21
|
return $ia <=> $ib; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
18
|
|
|
|
|
38
|
return $sort_sub->( $left, $right ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
5
|
|
|
|
|
29
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#sub make_halfsorter { |
56
|
|
|
|
|
|
|
# my %args = @_; |
57
|
|
|
|
|
|
|
# my $sort_sub = $args{any} || sub { $_[0] cmp $_[1] }; |
58
|
|
|
|
|
|
|
# my %pre_hash; |
59
|
|
|
|
|
|
|
# if ($args{pre}) { |
60
|
|
|
|
|
|
|
# my @pre = @{$args{pre}}; |
61
|
|
|
|
|
|
|
# @pre_hash{@pre} = (1..@pre); |
62
|
|
|
|
|
|
|
# } |
63
|
|
|
|
|
|
|
# my %post_hash; |
64
|
|
|
|
|
|
|
# if ($args{post}) { |
65
|
|
|
|
|
|
|
# my @post = @{$args{post}}; |
66
|
|
|
|
|
|
|
# @post_hash{@post} = (1..@post); |
67
|
|
|
|
|
|
|
# } |
68
|
|
|
|
|
|
|
# return sub { |
69
|
|
|
|
|
|
|
# sort { |
70
|
|
|
|
|
|
|
# my ($left, $right) = map { $_ } $a, $b; |
71
|
|
|
|
|
|
|
# #my ($left, $right) = map { $_ } @_; |
72
|
|
|
|
|
|
|
# if ($pre_hash{$left} || $pre_hash{$right}) { |
73
|
|
|
|
|
|
|
# my $ia = $pre_hash{$left} || keys(%pre_hash)+1; |
74
|
|
|
|
|
|
|
# my $ib = $pre_hash{$right} || keys(%pre_hash)+1; |
75
|
|
|
|
|
|
|
# return $ia <=> $ib; |
76
|
|
|
|
|
|
|
# } elsif ($post_hash{$left} || $post_hash{$right}) { |
77
|
|
|
|
|
|
|
# my $ia = $post_hash{$left} || 0; |
78
|
|
|
|
|
|
|
# my $ib = $post_hash{$right} || 0; |
79
|
|
|
|
|
|
|
# return $ia <=> $ib; |
80
|
|
|
|
|
|
|
# } else { |
81
|
|
|
|
|
|
|
# return $sort_sub->($left, $right); |
82
|
|
|
|
|
|
|
# } |
83
|
|
|
|
|
|
|
# } @_ |
84
|
|
|
|
|
|
|
# } |
85
|
|
|
|
|
|
|
# |
86
|
|
|
|
|
|
|
#} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |