line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Quantum::Superpositions::Lazy; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '1.10'; |
4
|
|
|
|
|
|
|
|
5
|
15
|
|
|
15
|
|
536051
|
use v5.24; |
|
15
|
|
|
|
|
117
|
|
6
|
15
|
|
|
15
|
|
108
|
use warnings; |
|
15
|
|
|
|
|
33
|
|
|
15
|
|
|
|
|
485
|
|
7
|
15
|
|
|
15
|
|
79
|
use Carp qw(croak); |
|
15
|
|
|
|
|
22
|
|
|
15
|
|
|
|
|
639
|
|
8
|
15
|
|
|
15
|
|
5500
|
use Quantum::Superpositions::Lazy::Superposition; |
|
15
|
|
|
|
|
52
|
|
|
15
|
|
|
|
|
454
|
|
9
|
15
|
|
|
15
|
|
102
|
use Quantum::Superpositions::Lazy::Operation::Logical; |
|
15
|
|
|
|
|
26
|
|
|
15
|
|
|
|
|
355
|
|
10
|
15
|
|
|
15
|
|
70
|
use Quantum::Superpositions::Lazy::Util qw(is_collapsible); |
|
15
|
|
|
|
|
27
|
|
|
15
|
|
|
|
|
647
|
|
11
|
15
|
|
|
15
|
|
71
|
use Exporter qw(import); |
|
15
|
|
|
|
|
28
|
|
|
15
|
|
|
|
|
6929
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw( |
14
|
|
|
|
|
|
|
superpos |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
18
|
|
|
|
|
|
|
collapse |
19
|
|
|
|
|
|
|
any_state |
20
|
|
|
|
|
|
|
every_state |
21
|
|
|
|
|
|
|
one_state |
22
|
|
|
|
|
|
|
fetch_matches |
23
|
|
|
|
|
|
|
with_sources |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
27
|
|
|
|
|
|
|
all => [@EXPORT, @EXPORT_OK], |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $global_reducer_type = "any"; |
31
|
|
|
|
|
|
|
our $global_compare_bool = 1; |
32
|
|
|
|
|
|
|
our $global_sourced_calculations = 0; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub run_sub_as |
35
|
|
|
|
|
|
|
{ |
36
|
46
|
|
|
46
|
0
|
123
|
my ($sub, %env) = @_; |
37
|
|
|
|
|
|
|
|
38
|
46
|
|
66
|
|
|
167
|
local $global_reducer_type = $env{reducer_type} // $global_reducer_type; |
39
|
46
|
|
100
|
|
|
189
|
local $global_compare_bool = $env{compare_bool} // $global_compare_bool; |
40
|
46
|
|
66
|
|
|
140
|
local $global_sourced_calculations = $env{sourced_calculations} // $global_sourced_calculations; |
41
|
46
|
|
|
|
|
92
|
return $sub->(); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub superpos |
45
|
|
|
|
|
|
|
{ |
46
|
70
|
|
|
70
|
1
|
24664
|
my (@positions) = @_; |
47
|
70
|
|
|
|
|
116
|
my $positions_ref; |
48
|
|
|
|
|
|
|
|
49
|
70
|
50
|
66
|
|
|
280
|
if (@positions == 1 && ref $positions[0] eq ref []) { |
50
|
0
|
|
|
|
|
0
|
$positions_ref = $positions[0]; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
70
|
|
|
|
|
818
|
$positions_ref = [@positions]; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
70
|
|
|
|
|
1117
|
return Quantum::Superpositions::Lazy::Superposition->new( |
57
|
|
|
|
|
|
|
states => $positions_ref |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub collapse |
62
|
|
|
|
|
|
|
{ |
63
|
1
|
|
|
1
|
1
|
60
|
my (@superpositions) = @_; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return map { |
66
|
1
|
50
|
|
|
|
2
|
croak "Element not collapsible" |
|
3
|
|
|
|
|
38
|
|
67
|
|
|
|
|
|
|
unless is_collapsible($_); |
68
|
3
|
|
|
|
|
52
|
$_->collapse; |
69
|
|
|
|
|
|
|
} @superpositions; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub any_state(&) |
73
|
|
|
|
|
|
|
{ |
74
|
4
|
|
|
4
|
1
|
9
|
my ($sub) = @_; |
75
|
|
|
|
|
|
|
|
76
|
4
|
|
|
|
|
9
|
return run_sub_as $sub, reducer_type => "any"; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub every_state(&) |
80
|
|
|
|
|
|
|
{ |
81
|
14
|
|
|
14
|
1
|
227
|
my ($sub) = @_; |
82
|
|
|
|
|
|
|
|
83
|
14
|
|
|
|
|
40
|
return run_sub_as $sub, reducer_type => "all"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub one_state(&) |
87
|
|
|
|
|
|
|
{ |
88
|
9
|
|
|
9
|
1
|
92
|
my ($sub) = @_; |
89
|
|
|
|
|
|
|
|
90
|
9
|
|
|
|
|
17
|
return run_sub_as $sub, reducer_type => "one"; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub fetch_matches(&) |
94
|
|
|
|
|
|
|
{ |
95
|
13
|
|
|
13
|
1
|
23355
|
my ($sub) = @_; |
96
|
|
|
|
|
|
|
|
97
|
13
|
|
|
|
|
50
|
return run_sub_as $sub, compare_bool => 0; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub with_sources(&) |
101
|
|
|
|
|
|
|
{ |
102
|
6
|
|
|
6
|
1
|
8397
|
my ($sub) = @_; |
103
|
|
|
|
|
|
|
|
104
|
6
|
|
|
|
|
22
|
return run_sub_as $sub, sourced_calculations => 1; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
__END__ |