| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package String::Lookup::PurePerl; # fake |
|
2
|
|
|
|
|
|
|
package String::Lookup; |
|
3
|
|
|
|
|
|
|
$VERSION= 0.13; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# what runtime features we need |
|
6
|
6
|
|
|
6
|
|
79
|
use 5.014; |
|
|
6
|
|
|
|
|
18
|
|
|
7
|
6
|
|
|
6
|
|
69
|
use warnings; |
|
|
6
|
|
|
|
|
10
|
|
|
|
6
|
|
|
|
|
167
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# constants we need |
|
10
|
6
|
|
|
6
|
|
29
|
use constant OFFSET => 0; # initial / current offset |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
570
|
|
|
11
|
6
|
|
|
6
|
|
33
|
use constant INCREMENT => 1; # increment value between ID's |
|
|
6
|
|
|
|
|
8
|
|
|
|
6
|
|
|
|
|
313
|
|
|
12
|
6
|
|
|
6
|
|
32
|
use constant THEHASH => 2; # hash ref with string -> id mapping |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
226
|
|
|
13
|
6
|
|
|
6
|
|
27
|
use constant THELIST => 3; # list ref with id -> string mapping |
|
|
6
|
|
|
|
|
10
|
|
|
|
6
|
|
|
|
|
240
|
|
|
14
|
6
|
|
|
6
|
|
31
|
use constant INDEX => 4; # keys() index |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
293
|
|
|
15
|
6
|
|
|
6
|
|
31
|
use constant FLUSH => 5; # code that does the flush |
|
|
6
|
|
|
|
|
11
|
|
|
|
6
|
|
|
|
|
318
|
|
|
16
|
6
|
|
|
6
|
|
30
|
use constant TODO => 6; # id's added |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
236
|
|
|
17
|
6
|
|
|
6
|
|
30
|
use constant AUTOFLUSH => 7; # code that determines when to autoflush |
|
|
6
|
|
|
|
|
7
|
|
|
|
6
|
|
|
|
|
259
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# modules that we need |
|
20
|
6
|
|
|
6
|
|
35
|
use Scalar::Util qw( reftype ); |
|
|
6
|
|
|
|
|
12
|
|
|
|
6
|
|
|
|
|
349
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# synonyms |
|
23
|
|
|
|
|
|
|
do { |
|
24
|
6
|
|
|
6
|
|
55
|
no warnings 'once'; |
|
|
6
|
|
|
|
|
15
|
|
|
|
6
|
|
|
|
|
7561
|
|
|
25
|
|
|
|
|
|
|
*DESTROY= \&flush; |
|
26
|
|
|
|
|
|
|
*UNTIE= \&flush; |
|
27
|
|
|
|
|
|
|
}; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# actions we cannot do on a lookup hash |
|
30
|
0
|
|
|
0
|
|
0
|
sub CLEAR { die "Cannot clear a lookup hash" } #CLEAR |
|
31
|
0
|
|
|
0
|
|
0
|
sub DELETE { die "Cannot delete strings from a lookup hash" } #DELETE |
|
32
|
1
|
|
|
1
|
|
10
|
sub STORE { die "Cannot assign values to a lookup hash" } #STORE |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# satisfy -require- |
|
35
|
|
|
|
|
|
|
1; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
38
|
|
|
|
|
|
|
# |
|
39
|
|
|
|
|
|
|
# Standard Perl functionality |
|
40
|
|
|
|
|
|
|
# |
|
41
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
42
|
|
|
|
|
|
|
# TIEHASH |
|
43
|
|
|
|
|
|
|
# |
|
44
|
|
|
|
|
|
|
# IN: 1 class |
|
45
|
|
|
|
|
|
|
# 2 .. N parameters |
|
46
|
|
|
|
|
|
|
# OUT: 1 blessed object |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub TIEHASH { |
|
49
|
24
|
|
|
24
|
|
3786
|
my ( $class, %param )= @_; |
|
50
|
24
|
|
|
|
|
40
|
my @errors; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# create object |
|
53
|
24
|
|
|
|
|
52
|
my $self= bless [], $class; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# overrides |
|
56
|
24
|
|
100
|
|
|
111
|
$self->[OFFSET]= delete $param{offset} || 0; |
|
57
|
24
|
|
100
|
|
|
78
|
$self->[INCREMENT]= delete $param{increment} || 1; |
|
58
|
24
|
|
|
|
|
37
|
my $storage= delete $param{storage}; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# sanity check |
|
61
|
24
|
50
|
|
|
|
58
|
push @errors, "Offset may not be negative" if $self->[OFFSET] < 0; |
|
62
|
24
|
50
|
|
|
|
54
|
push @errors, "Increment may not be negative" if $self->[INCREMENT] < 0; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# need to initialize the lookup hash |
|
65
|
24
|
100
|
|
|
|
54
|
if ( my $init= delete $param{init} ) { |
|
66
|
5
|
50
|
|
|
|
11
|
push @errors, "Cannot have 'init' as well as a 'storage' parameter" |
|
67
|
|
|
|
|
|
|
if $storage; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# fill the hash |
|
70
|
5
|
100
|
|
|
|
26
|
$self->init( reftype($init) eq 'HASH' ? $init : $init->() ); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# start afresh |
|
74
|
|
|
|
|
|
|
else { |
|
75
|
19
|
|
|
|
|
33
|
$self->[THEHASH]= {}; |
|
76
|
19
|
|
|
|
|
34
|
$self->[THELIST]= []; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# need to have our own flush |
|
80
|
24
|
100
|
|
|
|
52
|
if ( my $flush= delete $param{flush} ) { |
|
81
|
7
|
50
|
|
|
|
14
|
push @errors, "Cannot have 'flush' as well as a 'storage' parameter" |
|
82
|
|
|
|
|
|
|
if $storage; |
|
83
|
7
|
|
|
|
|
15
|
$self->[FLUSH]= $flush; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# we have a persistent backend |
|
87
|
24
|
100
|
|
|
|
49
|
if ($storage) { |
|
88
|
8
|
|
|
|
|
13
|
my $tag= delete $param{tag}; |
|
89
|
8
|
|
|
|
|
12
|
my $fork= delete $param{fork}; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# make sure we have the code |
|
92
|
8
|
50
|
|
|
|
29
|
my $storage_class= $storage =~ m#::# ? $storage : "${class}::$storage"; |
|
93
|
8
|
50
|
|
1
|
|
482
|
eval "use $storage_class; 1" or die $@; |
|
|
1
|
|
|
1
|
|
423
|
|
|
|
1
|
|
|
1
|
|
3
|
|
|
|
1
|
|
|
1
|
|
16
|
|
|
|
1
|
|
|
1
|
|
7
|
|
|
|
1
|
|
|
1
|
|
2
|
|
|
|
1
|
|
|
1
|
|
12
|
|
|
|
1
|
|
|
1
|
|
5
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
11
|
|
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
10
|
|
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
11
|
|
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
11
|
|
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
10
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# set up the options hash for the closures |
|
96
|
8
|
|
|
|
|
26
|
my %options= ( tag => $tag ); # in closure |
|
97
|
8
|
|
|
|
|
24
|
foreach my $name ( $storage_class->parameters_ok ) { |
|
98
|
8
|
100
|
|
|
|
26
|
$options{$name}= delete $param{$name} if exists $param{$name}; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# some sanity checks |
|
102
|
8
|
50
|
33
|
|
|
33
|
push @errors, "Must specify a 'tag'" if !defined $tag or !length $tag; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# perform the initialization |
|
105
|
8
|
|
|
|
|
19
|
$self->init( $storage_class->init( \%options ) ); |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# need to fork for a flush |
|
108
|
8
|
50
|
|
|
|
16
|
if ($fork) { |
|
109
|
|
|
|
|
|
|
$self->[FLUSH]= sub { |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# in the parent |
|
112
|
0
|
|
|
0
|
|
0
|
my $pid= fork; |
|
113
|
0
|
0
|
|
|
|
0
|
return 1 if $pid; |
|
114
|
0
|
0
|
|
|
|
0
|
return 0 if !defined $pid; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# in the child process |
|
117
|
0
|
|
|
|
|
0
|
exit !$storage_class->flush( \%options, @_ ); |
|
118
|
0
|
|
|
|
|
0
|
}; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# need to flush in this process |
|
122
|
|
|
|
|
|
|
else { |
|
123
|
|
|
|
|
|
|
$self->[FLUSH]= sub { |
|
124
|
6
|
|
|
6
|
|
26
|
return $storage_class->flush( \%options, @_ ); |
|
125
|
8
|
|
|
|
|
35
|
}; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# do we flush? |
|
130
|
24
|
100
|
|
|
|
73
|
if ( my $autoflush= delete $param{autoflush} ) { |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# huh? |
|
133
|
6
|
50
|
|
|
|
40
|
if ( !$self->[FLUSH] ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
0
|
push @errors, "Doesn't make sense to autoflush without flush"; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# autoflushing by seconds |
|
138
|
|
|
|
|
|
|
elsif ( $autoflush =~ m#^([0-9]+)s$# ) { |
|
139
|
1
|
|
|
|
|
3
|
my $seconds= $1; |
|
140
|
1
|
|
|
|
|
3
|
my $epoch= time + $seconds; |
|
141
|
|
|
|
|
|
|
$self->[AUTOFLUSH]= sub { |
|
142
|
2
|
100
|
|
2
|
|
13
|
$epoch += $seconds, $_[0]->flush if time >= $epoch; |
|
143
|
1
|
|
|
|
|
4
|
}; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# autoflushing by number of new ID's |
|
147
|
|
|
|
|
|
|
elsif ( $autoflush =~ m#^[0-9]+$# ) { |
|
148
|
|
|
|
|
|
|
$self->[AUTOFLUSH]= sub { |
|
149
|
10
|
100
|
|
10
|
|
12
|
$_[0]->flush if @{ $_[0]->[TODO] } == $autoflush; |
|
|
10
|
|
|
|
|
34
|
|
|
150
|
5
|
|
|
|
|
21
|
}; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# huh? |
|
154
|
|
|
|
|
|
|
else { |
|
155
|
0
|
|
|
|
|
0
|
push @errors, "Don't know what to do with autoflush '$autoflush'"; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# huh? |
|
160
|
24
|
50
|
|
|
|
79
|
if ( my @huh= sort keys %param ) { |
|
161
|
0
|
|
|
|
|
0
|
push @errors, "Don't know what to do with: @huh"; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# sorry |
|
165
|
24
|
50
|
|
|
|
49
|
die join "\n", "Found the following problems:", @errors if @errors; |
|
166
|
|
|
|
|
|
|
|
|
167
|
24
|
|
|
|
|
89
|
return $self; |
|
168
|
|
|
|
|
|
|
} #TIEHASH |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
171
|
|
|
|
|
|
|
# FETCH |
|
172
|
|
|
|
|
|
|
# |
|
173
|
|
|
|
|
|
|
# IN: 1 underlying object |
|
174
|
|
|
|
|
|
|
# 2 key to fetch (id or ref to string) |
|
175
|
|
|
|
|
|
|
# OUT: 1 id or string |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub FETCH { |
|
178
|
78
|
|
|
78
|
|
2021484
|
my $self= shift; |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# string lookup |
|
181
|
78
|
100
|
|
|
|
172
|
if ( ref $_[0] ) { |
|
182
|
50
|
|
100
|
|
|
72
|
return $self->[THEHASH]->{ ${ $_[0] } } || do { |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# store string and index |
|
185
|
|
|
|
|
|
|
my $index= $self->[OFFSET] += $self->[INCREMENT]; |
|
186
|
|
|
|
|
|
|
$self->[THEHASH]->{ |
|
187
|
|
|
|
|
|
|
$self->[THELIST]->[$index]= ${ $_[0] } # premature optimization |
|
188
|
|
|
|
|
|
|
}= $index; |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# flushing |
|
191
|
|
|
|
|
|
|
return $index if !$self->[FLUSH]; |
|
192
|
|
|
|
|
|
|
push @{ $self->[TODO] }, $index; |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# autoflushing |
|
195
|
|
|
|
|
|
|
return $index if !$self->[AUTOFLUSH]; |
|
196
|
|
|
|
|
|
|
$self->[AUTOFLUSH]->($self); |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
return $index; |
|
199
|
|
|
|
|
|
|
}; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# id lookup |
|
203
|
28
|
|
|
|
|
102
|
return $self->[THELIST]->[ $_[0] ]; |
|
204
|
|
|
|
|
|
|
} #FETCH |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
207
|
|
|
|
|
|
|
# EXISTS |
|
208
|
|
|
|
|
|
|
# |
|
209
|
|
|
|
|
|
|
# IN: 1 underlying object |
|
210
|
|
|
|
|
|
|
# 2 key to fetch (id or ref to string) |
|
211
|
|
|
|
|
|
|
# OUT: 1 boolean |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub EXISTS { |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
return ref $_[1] |
|
216
|
12
|
100
|
|
12
|
|
459
|
? exists $_[0]->[THEHASH]->{ ${ $_[1] } } # string exists |
|
|
6
|
|
|
|
|
27
|
|
|
217
|
|
|
|
|
|
|
: defined $_[0]->[THELIST]->[ $_[1] ]; # id exists |
|
218
|
|
|
|
|
|
|
} #EXISTS |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
221
|
|
|
|
|
|
|
# FIRSTKEY |
|
222
|
|
|
|
|
|
|
# |
|
223
|
|
|
|
|
|
|
# IN: 1 underlying object |
|
224
|
|
|
|
|
|
|
# OUT: 1 first key |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub FIRSTKEY { |
|
227
|
10
|
|
|
10
|
|
539
|
my $self= shift; |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# initializations |
|
230
|
10
|
|
|
|
|
20
|
my $index= $self->[INDEX]= 0; |
|
231
|
10
|
|
|
|
|
14
|
my $list= $self->[THELIST]; |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
# find the next |
|
234
|
|
|
|
|
|
|
$list->[$index] and $self->[INDEX]= $index and return $list->[$index] |
|
235
|
10
|
|
33
|
|
|
15
|
while ++$index < @{$list}; |
|
|
10
|
|
50
|
|
|
69
|
|
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# alas |
|
238
|
3
|
|
|
|
|
12
|
return undef; |
|
239
|
|
|
|
|
|
|
} #FIRSTKEY |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
242
|
|
|
|
|
|
|
# NEXTKEY |
|
243
|
|
|
|
|
|
|
# |
|
244
|
|
|
|
|
|
|
# IN: 1 underlying object |
|
245
|
|
|
|
|
|
|
# OUT: 1 next key |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
sub NEXTKEY { |
|
248
|
12
|
|
|
12
|
|
19
|
my $self= shift; |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
# initializations |
|
251
|
12
|
|
|
|
|
15
|
my $index= $self->[INDEX]; |
|
252
|
12
|
|
|
|
|
15
|
my $list= $self->[THELIST]; |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
# find the next |
|
255
|
|
|
|
|
|
|
$list->[$index] and $self->[INDEX]= $index and return $list->[$index] |
|
256
|
12
|
|
33
|
|
|
15
|
while ++$index < @{$list}; |
|
|
12
|
|
50
|
|
|
51
|
|
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
# alas |
|
259
|
6
|
|
|
|
|
31
|
return undef; |
|
260
|
|
|
|
|
|
|
} #NEXTKEY |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
263
|
|
|
|
|
|
|
# SCALAR |
|
264
|
|
|
|
|
|
|
# |
|
265
|
|
|
|
|
|
|
# IN: 1 underlying object |
|
266
|
|
|
|
|
|
|
# OUT: 1 underlying hash (for fast lookups) |
|
267
|
|
|
|
|
|
|
|
|
268
|
2
|
|
|
2
|
|
968
|
sub SCALAR { $_[0]->[THEHASH] } #SCALAR |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
271
|
|
|
|
|
|
|
# |
|
272
|
|
|
|
|
|
|
# Instance Methods |
|
273
|
|
|
|
|
|
|
# |
|
274
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
275
|
|
|
|
|
|
|
# flush (and DESTROY and UNTIE) |
|
276
|
|
|
|
|
|
|
# |
|
277
|
|
|
|
|
|
|
# IN: 1 underlying object |
|
278
|
|
|
|
|
|
|
# OUT: 1 return value from flush sub |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
sub flush { |
|
281
|
33
|
|
|
33
|
1
|
8609
|
my $self= shift; |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
# nothing to do |
|
284
|
33
|
100
|
|
|
|
222
|
my $flush= $self->[FLUSH] or return; |
|
285
|
24
|
100
|
|
|
|
438
|
my $todo= $self->[TODO] or return; |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
# perform the flush |
|
288
|
14
|
50
|
|
|
|
35
|
undef $self->[TODO] |
|
289
|
|
|
|
|
|
|
if my $return= $flush->( $self->[THELIST], $todo ); |
|
290
|
|
|
|
|
|
|
|
|
291
|
14
|
|
|
|
|
14632
|
return $return; |
|
292
|
|
|
|
|
|
|
} #flush |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
295
|
|
|
|
|
|
|
# init |
|
296
|
|
|
|
|
|
|
# |
|
297
|
|
|
|
|
|
|
# IN: 1 underlying object |
|
298
|
|
|
|
|
|
|
# 2 hash ref to start with |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
sub init { |
|
301
|
13
|
|
|
13
|
1
|
27
|
my ( $self, $hash )= @_; |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
# set the internal hash |
|
304
|
13
|
|
|
|
|
53
|
$self->[THEHASH]= $hash; |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
# make sure the internal list is set up as well |
|
307
|
13
|
|
|
|
|
20
|
my @list; |
|
308
|
13
|
|
|
|
|
17
|
$list[ $hash->{$_} ]= $_ foreach keys %{$hash}; |
|
|
13
|
|
|
|
|
52
|
|
|
309
|
13
|
|
|
|
|
27
|
$self->[THELIST]= \@list; |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
# make sure offset is correct with potentially incorrectly filled hash |
|
312
|
13
|
100
|
|
|
|
47
|
$self->[OFFSET]= |
|
313
|
|
|
|
|
|
|
$#list + |
|
314
|
|
|
|
|
|
|
$#list % $self->[INCREMENT] + |
|
315
|
|
|
|
|
|
|
$self->[OFFSET] % $self->[INCREMENT] |
|
316
|
|
|
|
|
|
|
if $#list > $self->[OFFSET]; |
|
317
|
|
|
|
|
|
|
|
|
318
|
13
|
|
|
|
|
20
|
return; |
|
319
|
|
|
|
|
|
|
} #init |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
__END__ |