| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Quantum::Superpositions::Lazy::Util; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '1.11'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
15
|
|
|
15
|
|
120474
|
use v5.24; |
|
|
15
|
|
|
|
|
52
|
|
|
6
|
15
|
|
|
15
|
|
73
|
use warnings; |
|
|
15
|
|
|
|
|
38
|
|
|
|
15
|
|
|
|
|
397
|
|
|
7
|
15
|
|
|
15
|
|
76
|
use Exporter qw(import); |
|
|
15
|
|
|
|
|
23
|
|
|
|
15
|
|
|
|
|
407
|
|
|
8
|
15
|
|
|
15
|
|
67
|
use Scalar::Util qw(blessed); |
|
|
15
|
|
|
|
|
25
|
|
|
|
15
|
|
|
|
|
746
|
|
|
9
|
15
|
|
|
15
|
|
89
|
use List::Util qw(max); |
|
|
15
|
|
|
|
|
27
|
|
|
|
15
|
|
|
|
|
1559
|
|
|
10
|
15
|
|
|
15
|
|
6359
|
use Random::Any qw(rand); |
|
|
15
|
|
|
|
|
4388
|
|
|
|
15
|
|
|
|
|
73
|
|
|
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
|
16838
|
|
|
16838
|
0
|
28193
|
my ($item) = @_; |
|
22
|
|
|
|
|
|
|
|
|
23
|
16838
|
|
66
|
|
|
223936
|
return blessed $item && $item->DOES("Quantum::Superpositions::Lazy::Role::Collapsible"); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub is_state |
|
27
|
|
|
|
|
|
|
{ |
|
28
|
247797
|
|
|
247797
|
0
|
328937
|
my ($item) = @_; |
|
29
|
|
|
|
|
|
|
|
|
30
|
247797
|
|
66
|
|
|
725563
|
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
|
120
|
sub get_rand { rand() } |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get_iterator |
|
37
|
|
|
|
|
|
|
{ |
|
38
|
146
|
|
|
146
|
0
|
301
|
my (@states) = @_; |
|
39
|
|
|
|
|
|
|
|
|
40
|
146
|
|
|
|
|
299
|
my @indexes = map { 0 } @states; |
|
|
299
|
|
|
|
|
473
|
|
|
41
|
146
|
|
|
|
|
277
|
my @max_indexes = map { $#$_ } @states; |
|
|
299
|
|
|
|
|
554
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# we can't iterate if one of the elements do not exist |
|
44
|
146
|
|
|
|
|
232
|
my $finished = scalar grep { $_ < 0 } @max_indexes; |
|
|
299
|
|
|
|
|
565
|
|
|
45
|
|
|
|
|
|
|
return sub { |
|
46
|
123947
|
|
|
123947
|
|
184333
|
my ($with_indexes) = @_; |
|
47
|
123947
|
100
|
|
|
|
186567
|
return if $finished; |
|
48
|
|
|
|
|
|
|
|
|
49
|
123865
|
|
|
|
|
147792
|
my $i = 0; |
|
50
|
|
|
|
|
|
|
my @ret = |
|
51
|
247797
|
100
|
|
|
|
343540
|
map { is_state($_) ? $_->value : $_ } |
|
52
|
123865
|
|
|
|
|
161786
|
map { $states[$i++][$_] } |
|
|
247797
|
|
|
|
|
401015
|
|
|
53
|
|
|
|
|
|
|
@indexes; |
|
54
|
|
|
|
|
|
|
|
|
55
|
123865
|
100
|
|
|
|
209509
|
if ($with_indexes) { |
|
56
|
39529
|
|
|
|
|
99873
|
@ret = map { $indexes[$_], $ret[$_] } 0 .. max($#indexes, $#ret); |
|
|
79058
|
|
|
|
|
163206
|
|
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
123865
|
|
|
|
|
159071
|
$i = 0; |
|
60
|
123865
|
|
100
|
|
|
337313
|
while ($i < @indexes && ++$indexes[$i] > $max_indexes[$i]) { |
|
61
|
16099
|
|
|
|
|
19767
|
$indexes[$i] = 0; |
|
62
|
16099
|
|
|
|
|
38768
|
$i += 1; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
123865
|
|
|
|
|
181142
|
$finished = $i == @indexes; |
|
66
|
123865
|
|
|
|
|
322404
|
return @ret; |
|
67
|
146
|
|
|
|
|
922
|
}; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |