| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package List::DoubleLinked; |
|
2
|
|
|
|
|
|
|
$List::DoubleLinked::VERSION = '0.004'; |
|
3
|
1
|
|
|
1
|
|
29922
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
29
|
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings FATAL => 'all'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
40
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Carp qw/carp croak/; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
43
|
|
|
7
|
1
|
|
|
1
|
|
3
|
use Scalar::Util 'weaken'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
41
|
|
|
8
|
1
|
|
|
1
|
|
431
|
use namespace::clean 0.20; |
|
|
1
|
|
|
|
|
11789
|
|
|
|
1
|
|
|
|
|
5
|
|
|
9
|
|
|
|
|
|
|
#no autovivication; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
|
12
|
1
|
|
|
1
|
1
|
16
|
my ($class, @items) = @_; |
|
13
|
1
|
|
|
|
|
8
|
my $self = bless { |
|
14
|
|
|
|
|
|
|
head => undef, |
|
15
|
|
|
|
|
|
|
tail => undef, |
|
16
|
|
|
|
|
|
|
head => { prev => undef }, |
|
17
|
|
|
|
|
|
|
tail => { tail => undef }, |
|
18
|
|
|
|
|
|
|
}, $class; |
|
19
|
1
|
|
|
|
|
7
|
$self->{head}{next} = $self->{tail}; |
|
20
|
1
|
|
|
|
|
2
|
$self->{tail}{prev} = $self->{head}; |
|
21
|
1
|
|
|
|
|
5
|
$self->push(@items); |
|
22
|
1
|
|
|
|
|
2
|
return $self; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitBuiltinHomonyms, ControlStructures::ProhibitCStyleForLoops) |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub push { |
|
28
|
3
|
|
|
3
|
1
|
737
|
my ($self, @items) = @_; |
|
29
|
3
|
|
|
|
|
8
|
for my $item (@items) { |
|
30
|
|
|
|
|
|
|
my $new_tail = { |
|
31
|
|
|
|
|
|
|
item => $item, |
|
32
|
|
|
|
|
|
|
prev => $self->{tail}{prev}, |
|
33
|
|
|
|
|
|
|
next => $self->{tail}, |
|
34
|
4
|
|
|
|
|
12
|
}; |
|
35
|
4
|
|
|
|
|
5
|
$self->{tail}{prev}{next} = $new_tail; |
|
36
|
4
|
|
|
|
|
5
|
$self->{tail}{prev} = $new_tail; |
|
37
|
4
|
50
|
|
|
|
11
|
$self->{head}{next} = $new_tail if $self->{head}{next} == $self->{tail}; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
3
|
|
|
|
|
5
|
return; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub pop { |
|
43
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
|
44
|
1
|
50
|
|
|
|
5
|
croak 'No items to pop from the list' if $self->{tail}{prev} == $self->{head}; |
|
45
|
1
|
|
|
|
|
2
|
my $ret = $self->{tail}{prev}; |
|
46
|
1
|
|
|
|
|
2
|
$self->{tail}{prev} = $ret->{prev}; |
|
47
|
1
|
|
|
|
|
2
|
$ret->{prev}{next} = $self->{tail}; |
|
48
|
1
|
|
|
|
|
3
|
return $ret->{item}; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub unshift { |
|
52
|
1
|
|
|
1
|
1
|
2
|
my ($self, @items) = @_; |
|
53
|
1
|
|
|
|
|
3
|
for my $item (reverse @items) { |
|
54
|
|
|
|
|
|
|
my $new_head = { |
|
55
|
|
|
|
|
|
|
item => $item, |
|
56
|
|
|
|
|
|
|
prev => $self->{head}, |
|
57
|
|
|
|
|
|
|
next => $self->{head}{next}, |
|
58
|
1
|
|
|
|
|
4
|
}; |
|
59
|
1
|
|
|
|
|
3
|
$self->{head}{next}{prev} = $new_head; |
|
60
|
1
|
|
|
|
|
1
|
$self->{head}{next} = $new_head; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
1
|
|
|
|
|
2
|
return; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub shift { |
|
66
|
0
|
|
|
0
|
1
|
0
|
my $self = CORE::shift; |
|
67
|
0
|
0
|
|
|
|
0
|
croak 'No items to shift from the list' if $self->{head}{next} == $self->{tail}; |
|
68
|
0
|
|
|
|
|
0
|
my $ret = $self->{head}{next}; |
|
69
|
0
|
|
|
|
|
0
|
$self->{head}{next} = $ret->{next}; |
|
70
|
0
|
|
|
|
|
0
|
$ret->{next}{prev} = $$self->{head}; |
|
71
|
0
|
|
|
|
|
0
|
return $ret->{item}; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub flatten { |
|
75
|
7
|
|
|
7
|
1
|
9
|
my $self = CORE::shift; |
|
76
|
7
|
|
|
|
|
28
|
my @ret; |
|
77
|
7
|
|
|
|
|
21
|
for (my $current = $self->{head}{next} ; $current != $self->{tail}; $current = $current->{next}) { |
|
78
|
23
|
|
|
|
|
43
|
CORE::push @ret, $current->{item}; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
7
|
|
|
|
|
42
|
return @ret; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub front { |
|
84
|
1
|
|
|
1
|
1
|
2
|
my $self = CORE::shift; |
|
85
|
1
|
|
|
|
|
5
|
return $self->{head}{next}{item}; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub back { |
|
89
|
1
|
|
|
1
|
1
|
3
|
my $self = CORE::shift; |
|
90
|
1
|
|
|
|
|
5
|
return $self->{tail}{prev}{item}; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub empty { |
|
94
|
2
|
|
|
2
|
1
|
7
|
my $self = CORE::shift; |
|
95
|
|
|
|
|
|
|
return $self->{head}{next} == $self->{tail} |
|
96
|
2
|
|
|
|
|
11
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub size { |
|
99
|
2
|
|
|
2
|
1
|
2
|
my $self = CORE::shift; |
|
100
|
2
|
|
|
|
|
2
|
my $ret = 0; |
|
101
|
2
|
|
|
|
|
9
|
for (my $current = $self->{head}{next} ; $current != $self->{tail}; $current = $current->{next}) { |
|
102
|
3
|
|
|
|
|
6
|
$ret++; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
2
|
|
|
|
|
8
|
return $ret; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub erase { |
|
108
|
1
|
|
|
1
|
1
|
1
|
my ($self, $iter) = @_; |
|
109
|
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
3
|
my $ret = $iter->next; |
|
111
|
1
|
|
|
|
|
1
|
my $node = $iter->[0]; |
|
112
|
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
2
|
$node->{prev}{next} = $node->{next}; |
|
114
|
1
|
|
|
|
|
2
|
$node->{next}{prev} = $node->{prev}; |
|
115
|
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
7
|
weaken $node; |
|
117
|
1
|
50
|
|
|
|
3
|
carp 'Node may be leaking' if $node; |
|
118
|
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
5
|
return $ret; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub begin { |
|
123
|
2
|
|
|
2
|
1
|
364
|
my $self = CORE::shift; |
|
124
|
2
|
|
|
|
|
588
|
require List::DoubleLinked::Iterator; |
|
125
|
|
|
|
|
|
|
|
|
126
|
2
|
|
|
|
|
8
|
return List::DoubleLinked::Iterator->new($self->{head}{next}); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub end { |
|
130
|
7
|
|
|
7
|
1
|
6
|
my $self = CORE::shift; |
|
131
|
7
|
|
|
|
|
15
|
require List::DoubleLinked::Iterator; |
|
132
|
|
|
|
|
|
|
|
|
133
|
7
|
|
|
|
|
11
|
return List::DoubleLinked::Iterator->new($self->{tail}); |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub DESTROY { |
|
137
|
1
|
|
|
1
|
|
7
|
my $self = CORE::shift; |
|
138
|
1
|
|
|
|
|
2
|
my $current = $self->{head}; |
|
139
|
1
|
|
|
|
|
6
|
while ($current) { |
|
140
|
9
|
|
|
|
|
9
|
delete $current->{prev}; |
|
141
|
9
|
|
|
|
|
12
|
$current = delete $current->{next}; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
1
|
|
|
|
|
3
|
return; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# ABSTRACT: Double Linked Lists for Perl |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
__END__ |