line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gnuplot::Builder::PartiallyKeyedList; |
2
|
69
|
|
|
69
|
|
116512
|
use strict; |
|
69
|
|
|
|
|
131
|
|
|
69
|
|
|
|
|
1672
|
|
3
|
69
|
|
|
69
|
|
354
|
use warnings; |
|
69
|
|
|
|
|
132
|
|
|
69
|
|
|
|
|
1656
|
|
4
|
69
|
|
|
69
|
|
341
|
use Carp; |
|
69
|
|
|
|
|
132
|
|
|
69
|
|
|
|
|
61090
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
2247
|
|
|
2247
|
1
|
7760
|
my ($class) = @_; |
8
|
2247
|
|
|
|
|
8493
|
my $self = bless { |
9
|
|
|
|
|
|
|
index_for => {}, |
10
|
|
|
|
|
|
|
keys => [], |
11
|
|
|
|
|
|
|
values => [], |
12
|
|
|
|
|
|
|
}, $class; |
13
|
2247
|
|
|
|
|
14663
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub set { |
17
|
6074
|
|
|
6074
|
1
|
8997
|
my ($self, $key, $value) = @_; |
18
|
6074
|
50
|
|
|
|
11380
|
croak "key must be defined" if not defined $key; |
19
|
6074
|
|
|
|
|
9222
|
my $index = $self->{index_for}{$key}; |
20
|
6074
|
100
|
|
|
|
10079
|
if(defined($index)) { |
21
|
515
|
|
|
|
|
1678
|
$self->{values}[$index] = $value; |
22
|
|
|
|
|
|
|
}else { |
23
|
5559
|
|
|
|
|
6638
|
push(@{$self->{keys}}, $key); |
|
5559
|
|
|
|
|
11122
|
|
24
|
5559
|
|
|
|
|
6962
|
push(@{$self->{values}}, $value); |
|
5559
|
|
|
|
|
9241
|
|
25
|
5559
|
|
|
|
|
6413
|
$self->{index_for}{$key} = $#{$self->{keys}}; |
|
5559
|
|
|
|
|
20831
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get { |
30
|
211
|
|
|
211
|
1
|
6992
|
my ($self, $key) = @_; |
31
|
211
|
50
|
|
|
|
497
|
croak "key must be defined" if not defined $key; |
32
|
211
|
|
|
|
|
359
|
my $index = $self->{index_for}{$key}; |
33
|
211
|
100
|
|
|
|
916
|
return defined($index) ? $self->{values}[$index] : undef; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get_at { |
37
|
71
|
|
|
71
|
1
|
27429
|
my ($self, $index) = @_; |
38
|
71
|
50
|
33
|
|
|
264
|
croak "index out of bounds" if $index < 0 || $index >= $self->size; |
39
|
71
|
|
|
|
|
413
|
return ($self->{keys}[$index], $self->{values}[$index]); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_all_keys { |
43
|
172
|
|
|
172
|
1
|
4113
|
my ($self) = @_; |
44
|
172
|
|
|
|
|
221
|
return @{$self->{keys}}; |
|
172
|
|
|
|
|
1140
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub get_all_values { |
48
|
276
|
|
|
276
|
1
|
6718
|
my ($self) = @_; |
49
|
276
|
|
|
|
|
319
|
return @{$self->{values}}; |
|
276
|
|
|
|
|
1345
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub exists { |
53
|
1539
|
|
|
1539
|
1
|
2275
|
my ($self, $key) = @_; |
54
|
1539
|
50
|
|
|
|
2903
|
croak "key must be defined" if not defined $key; |
55
|
1539
|
|
|
|
|
7681
|
return defined($self->{index_for}{$key}); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub delete { |
59
|
33
|
|
|
33
|
1
|
93
|
my ($self, $key) = @_; |
60
|
33
|
50
|
|
|
|
97
|
croak "key must be defined" if not defined $key; |
61
|
33
|
|
|
|
|
75
|
my $index = delete $self->{index_for}{$key}; |
62
|
33
|
100
|
|
|
|
110
|
return undef if not defined $index; |
63
|
26
|
|
|
|
|
71
|
splice(@{$self->{keys}}, $index, 1); |
|
26
|
|
|
|
|
75
|
|
64
|
26
|
|
|
|
|
42
|
my $value = splice(@{$self->{values}}, $index, 1); |
|
26
|
|
|
|
|
58
|
|
65
|
|
|
|
|
|
|
|
66
|
26
|
|
|
|
|
46
|
foreach my $existing_index (values %{$self->{index_for}}) { |
|
26
|
|
|
|
|
78
|
|
67
|
66
|
100
|
|
|
|
168
|
$existing_index-- if $existing_index > $index; |
68
|
|
|
|
|
|
|
} |
69
|
26
|
|
|
|
|
101
|
return $value; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub add { |
73
|
100
|
|
|
100
|
1
|
298
|
my ($self, $entry) = @_; |
74
|
100
|
|
|
|
|
120
|
push(@{$self->{keys}}, undef); |
|
100
|
|
|
|
|
206
|
|
75
|
100
|
|
|
|
|
134
|
push(@{$self->{values}}, $entry); |
|
100
|
|
|
|
|
380
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub each { |
79
|
2127
|
|
|
2127
|
1
|
3079
|
my ($self, $code) = @_; |
80
|
2127
|
50
|
33
|
|
|
9957
|
croak "code must be a code-ref" if !defined($code) || ref($code) ne "CODE"; |
81
|
2127
|
|
|
|
|
2455
|
foreach my $index (0 .. $#{$self->{keys}}) { |
|
2127
|
|
|
|
|
11117
|
|
82
|
5554
|
|
|
|
|
13339
|
$code->($self->{keys}[$index], $self->{values}[$index]); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub merge { |
87
|
1535
|
|
|
1535
|
1
|
2173
|
my ($self, $another) = @_; |
88
|
1535
|
50
|
33
|
|
|
4989
|
croak "another_pkl must be an object" if !defined($another) || !ref($another); |
89
|
|
|
|
|
|
|
$another->each(sub { |
90
|
4723
|
|
|
4723
|
|
6412
|
my ($key, $value) = @_; |
91
|
4723
|
100
|
|
|
|
7279
|
if(defined($key)) { |
92
|
4676
|
|
|
|
|
8910
|
$self->set($key, $value); |
93
|
|
|
|
|
|
|
}else { |
94
|
47
|
|
|
|
|
96
|
$self->add($value); |
95
|
|
|
|
|
|
|
} |
96
|
1535
|
|
|
|
|
5824
|
}); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
103
|
|
|
103
|
1
|
19047
|
sub size { scalar(@{ $_[0]->{keys} }) } |
|
103
|
|
|
|
|
452
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |