line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Quantum::Superpositions::Lazy::Util; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '1.10'; |
4
|
|
|
|
|
|
|
|
5
|
15
|
|
|
15
|
|
113632
|
use v5.24; |
|
15
|
|
|
|
|
54
|
|
6
|
15
|
|
|
15
|
|
63
|
use warnings; |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
367
|
|
7
|
15
|
|
|
15
|
|
72
|
use Exporter qw(import); |
|
15
|
|
|
|
|
24
|
|
|
15
|
|
|
|
|
364
|
|
8
|
15
|
|
|
15
|
|
62
|
use Scalar::Util qw(blessed); |
|
15
|
|
|
|
|
27
|
|
|
15
|
|
|
|
|
673
|
|
9
|
15
|
|
|
15
|
|
89
|
use List::Util qw(max); |
|
15
|
|
|
|
|
33
|
|
|
15
|
|
|
|
|
1455
|
|
10
|
15
|
|
|
15
|
|
5853
|
use Random::Any qw(rand); |
|
15
|
|
|
|
|
3894
|
|
|
15
|
|
|
|
|
68
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
13
|
|
|
|
|
|
|
is_collapsible |
14
|
|
|
|
|
|
|
is_state |
15
|
|
|
|
|
|
|
get_rand |
16
|
|
|
|
|
|
|
get_iterator |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub is_collapsible |
20
|
|
|
|
|
|
|
{ |
21
|
16835
|
|
|
16835
|
0
|
26550
|
my ($item) = @_; |
22
|
|
|
|
|
|
|
|
23
|
16835
|
|
66
|
|
|
194180
|
return blessed $item && $item->DOES("Quantum::Superpositions::Lazy::Role::Collapsible"); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub is_state |
27
|
|
|
|
|
|
|
{ |
28
|
248137
|
|
|
248137
|
0
|
309044
|
my ($item) = @_; |
29
|
|
|
|
|
|
|
|
30
|
248137
|
|
66
|
|
|
664717
|
return blessed $item && $item->isa("Quantum::Superpositions::Lazy::State"); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# MUST return a value in range of [0, 1) |
34
|
35
|
|
|
35
|
0
|
93
|
sub get_rand { rand() } |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get_iterator |
37
|
|
|
|
|
|
|
{ |
38
|
146
|
|
|
146
|
0
|
302
|
my (@states) = @_; |
39
|
|
|
|
|
|
|
|
40
|
146
|
|
|
|
|
296
|
my @indexes = map { 0 } @states; |
|
296
|
|
|
|
|
479
|
|
41
|
146
|
|
|
|
|
226
|
my @max_indexes = map { $#$_ } @states; |
|
296
|
|
|
|
|
472
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# we can't iterate if one of the elements do not exist |
44
|
146
|
|
|
|
|
231
|
my $finished = scalar grep { $_ < 0 } @max_indexes; |
|
296
|
|
|
|
|
525
|
|
45
|
|
|
|
|
|
|
return sub { |
46
|
124119
|
|
|
124119
|
|
175016
|
my ($with_indexes) = @_; |
47
|
124119
|
100
|
|
|
|
167892
|
return if $finished; |
48
|
|
|
|
|
|
|
|
49
|
124037
|
|
|
|
|
133002
|
my $i = 0; |
50
|
|
|
|
|
|
|
my @ret = |
51
|
248137
|
100
|
|
|
|
321248
|
map { is_state($_) ? $_->value : $_ } |
52
|
124037
|
|
|
|
|
161641
|
map { $states[$i++][$_] } |
|
248137
|
|
|
|
|
367854
|
|
53
|
|
|
|
|
|
|
@indexes; |
54
|
|
|
|
|
|
|
|
55
|
124037
|
100
|
|
|
|
196586
|
if ($with_indexes) { |
56
|
39529
|
|
|
|
|
95535
|
@ret = map { $indexes[$_], $ret[$_] } 0 .. max($#indexes, $#ret); |
|
79058
|
|
|
|
|
154459
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
124037
|
|
|
|
|
140052
|
$i = 0; |
60
|
124037
|
|
100
|
|
|
329629
|
while ($i < @indexes && ++$indexes[$i] > $max_indexes[$i]) { |
61
|
16106
|
|
|
|
|
18857
|
$indexes[$i] = 0; |
62
|
16106
|
|
|
|
|
35909
|
$i += 1; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
124037
|
|
|
|
|
159358
|
$finished = $i == @indexes; |
66
|
124037
|
|
|
|
|
322444
|
return @ret; |
67
|
146
|
|
|
|
|
855
|
}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |