line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gnuplot::Builder::PartiallyKeyedList; |
2
|
68
|
|
|
68
|
|
118594
|
use strict; |
|
68
|
|
|
|
|
123
|
|
|
68
|
|
|
|
|
1710
|
|
3
|
68
|
|
|
68
|
|
361
|
use warnings; |
|
68
|
|
|
|
|
117
|
|
|
68
|
|
|
|
|
1536
|
|
4
|
68
|
|
|
68
|
|
335
|
use Carp; |
|
68
|
|
|
|
|
135
|
|
|
68
|
|
|
|
|
61220
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
2224
|
|
|
2224
|
1
|
5969
|
my ($class) = @_; |
8
|
2224
|
|
|
|
|
9559
|
my $self = bless { |
9
|
|
|
|
|
|
|
index_for => {}, |
10
|
|
|
|
|
|
|
keys => [], |
11
|
|
|
|
|
|
|
values => [], |
12
|
|
|
|
|
|
|
}, $class; |
13
|
2224
|
|
|
|
|
14294
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub set { |
17
|
6062
|
|
|
6062
|
1
|
8952
|
my ($self, $key, $value) = @_; |
18
|
6062
|
50
|
|
|
|
11085
|
croak "key must be defined" if not defined $key; |
19
|
6062
|
|
|
|
|
9005
|
my $index = $self->{index_for}{$key}; |
20
|
6062
|
100
|
|
|
|
9389
|
if(defined($index)) { |
21
|
515
|
|
|
|
|
1650
|
$self->{values}[$index] = $value; |
22
|
|
|
|
|
|
|
}else { |
23
|
5547
|
|
|
|
|
5676
|
push(@{$self->{keys}}, $key); |
|
5547
|
|
|
|
|
10748
|
|
24
|
5547
|
|
|
|
|
6639
|
push(@{$self->{values}}, $value); |
|
5547
|
|
|
|
|
9568
|
|
25
|
5547
|
|
|
|
|
6427
|
$self->{index_for}{$key} = $#{$self->{keys}}; |
|
5547
|
|
|
|
|
20718
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get { |
30
|
211
|
|
|
211
|
1
|
5243
|
my ($self, $key) = @_; |
31
|
211
|
50
|
|
|
|
451
|
croak "key must be defined" if not defined $key; |
32
|
211
|
|
|
|
|
406
|
my $index = $self->{index_for}{$key}; |
33
|
211
|
100
|
|
|
|
882
|
return defined($index) ? $self->{values}[$index] : undef; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get_at { |
37
|
71
|
|
|
71
|
1
|
27947
|
my ($self, $index) = @_; |
38
|
71
|
50
|
33
|
|
|
271
|
croak "index out of bounds" if $index < 0 || $index >= $self->size; |
39
|
71
|
|
|
|
|
469
|
return ($self->{keys}[$index], $self->{values}[$index]); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_all_keys { |
43
|
172
|
|
|
172
|
1
|
4067
|
my ($self) = @_; |
44
|
172
|
|
|
|
|
195
|
return @{$self->{keys}}; |
|
172
|
|
|
|
|
1200
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub get_all_values { |
48
|
276
|
|
|
276
|
1
|
6958
|
my ($self) = @_; |
49
|
276
|
|
|
|
|
346
|
return @{$self->{values}}; |
|
276
|
|
|
|
|
1468
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub exists { |
53
|
1537
|
|
|
1537
|
1
|
2127
|
my ($self, $key) = @_; |
54
|
1537
|
50
|
|
|
|
2983
|
croak "key must be defined" if not defined $key; |
55
|
1537
|
|
|
|
|
7345
|
return defined($self->{index_for}{$key}); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub delete { |
59
|
33
|
|
|
33
|
1
|
107
|
my ($self, $key) = @_; |
60
|
33
|
50
|
|
|
|
99
|
croak "key must be defined" if not defined $key; |
61
|
33
|
|
|
|
|
91
|
my $index = delete $self->{index_for}{$key}; |
62
|
33
|
100
|
|
|
|
121
|
return undef if not defined $index; |
63
|
26
|
|
|
|
|
45
|
splice(@{$self->{keys}}, $index, 1); |
|
26
|
|
|
|
|
84
|
|
64
|
26
|
|
|
|
|
116
|
my $value = splice(@{$self->{values}}, $index, 1); |
|
26
|
|
|
|
|
65
|
|
65
|
|
|
|
|
|
|
|
66
|
26
|
|
|
|
|
52
|
foreach my $existing_index (values %{$self->{index_for}}) { |
|
26
|
|
|
|
|
87
|
|
67
|
66
|
100
|
|
|
|
193
|
$existing_index-- if $existing_index > $index; |
68
|
|
|
|
|
|
|
} |
69
|
26
|
|
|
|
|
113
|
return $value; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub add { |
73
|
100
|
|
|
100
|
1
|
214
|
my ($self, $entry) = @_; |
74
|
100
|
|
|
|
|
122
|
push(@{$self->{keys}}, undef); |
|
100
|
|
|
|
|
256
|
|
75
|
100
|
|
|
|
|
135
|
push(@{$self->{values}}, $entry); |
|
100
|
|
|
|
|
400
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub each { |
79
|
2107
|
|
|
2107
|
1
|
3369
|
my ($self, $code) = @_; |
80
|
2107
|
50
|
33
|
|
|
9812
|
croak "code must be a code-ref" if !defined($code) || ref($code) ne "CODE"; |
81
|
2107
|
|
|
|
|
2343
|
foreach my $index (0 .. $#{$self->{keys}}) { |
|
2107
|
|
|
|
|
10976
|
|
82
|
5536
|
|
|
|
|
12543
|
$code->($self->{keys}[$index], $self->{values}[$index]); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub merge { |
87
|
1526
|
|
|
1526
|
1
|
2232
|
my ($self, $another) = @_; |
88
|
1526
|
50
|
33
|
|
|
5239
|
croak "another_pkl must be an object" if !defined($another) || !ref($another); |
89
|
|
|
|
|
|
|
$another->each(sub { |
90
|
4715
|
|
|
4715
|
|
6424
|
my ($key, $value) = @_; |
91
|
4715
|
100
|
|
|
|
7348
|
if(defined($key)) { |
92
|
4668
|
|
|
|
|
8421
|
$self->set($key, $value); |
93
|
|
|
|
|
|
|
}else { |
94
|
47
|
|
|
|
|
102
|
$self->add($value); |
95
|
|
|
|
|
|
|
} |
96
|
1526
|
|
|
|
|
5715
|
}); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
103
|
|
|
103
|
1
|
19280
|
sub size { scalar(@{ $_[0]->{keys} }) } |
|
103
|
|
|
|
|
449
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |