line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Coder::Many::Scheduler::UniquenessScheduler; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
43
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
41
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
5
|
use List::MoreUtils qw( first_index ); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
10
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
581
|
use base 'Geo::Coder::Many::Scheduler'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
636
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Geo::Coder::Many::Scheduler::UniquenessScheduler - Scheduler base class which |
15
|
|
|
|
|
|
|
ensures uniqueness |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
A base class for enforcing correct behaviour of get_next_unique (and the other |
20
|
|
|
|
|
|
|
methods) even when a scheduling scheme might not take this into account. Note: |
21
|
|
|
|
|
|
|
this may alter the properties of the scheduling scheme! |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Subclasses should |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 new |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Creates a UniquenessScheduler object and returns it. This should not be called |
30
|
|
|
|
|
|
|
directly, but by any subclasses, via SUPER. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
280
|
|
|
280
|
1
|
225
|
my $class = shift; |
36
|
280
|
|
|
|
|
196
|
my $args = shift; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# (Map from geocoder+weight hash, for the time being) |
39
|
280
|
|
|
|
|
186
|
my @items_copy = map { $_->{name} } @{$args->{items}}; |
|
420
|
|
|
|
|
732
|
|
|
280
|
|
|
|
|
349
|
|
40
|
|
|
|
|
|
|
|
41
|
280
|
|
|
|
|
403
|
my $self = { items => \@items_copy}; |
42
|
280
|
|
|
|
|
293
|
bless $self, $class; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Initialize available_items |
45
|
280
|
|
|
|
|
354
|
$self->reset_available(); |
46
|
280
|
|
|
|
|
497
|
return $self; |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 reset_available |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Update the set of currently available items to the full set of items initially |
52
|
|
|
|
|
|
|
provided. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub reset_available { |
57
|
1680
|
|
|
1680
|
1
|
1176
|
my $self = shift; |
58
|
1680
|
|
|
|
|
1018
|
@{$self->{available_items}} = @{$self->{items}}; |
|
1680
|
|
|
|
|
2525
|
|
|
1680
|
|
|
|
|
1512
|
|
59
|
1680
|
|
|
|
|
2032
|
return; |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 get_next_unique |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Uses _get_next (which has been overridden) to obtain the next scheduled item, |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub get_next_unique { |
69
|
3290
|
|
|
3290
|
1
|
2454
|
my $self = shift; |
70
|
|
|
|
|
|
|
|
71
|
3290
|
|
|
|
|
2041
|
my ($item, $item_pos); |
72
|
3290
|
|
|
|
|
2260
|
while ( 0 < @{$self->{available_items}} ) { |
|
3929
|
|
|
|
|
5950
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Get the next element (possibly one we've seen before) |
75
|
3372
|
|
|
|
|
5650
|
$item = $self->_get_next(); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Return undef if _get_next has no more items |
78
|
3372
|
50
|
|
|
|
4249
|
return if !defined $item; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Check whether we've seen this item before |
81
|
3372
|
|
|
3756
|
|
5520
|
$item_pos = first_index { $_ eq $item } @{$self->{available_items}}; |
|
3756
|
|
|
|
|
3519
|
|
|
3372
|
|
|
|
|
5442
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Finish if we haven't seen it |
84
|
3372
|
100
|
|
|
|
7032
|
last if ($item_pos > -1); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# If we ran out of items, return undef. |
88
|
3290
|
100
|
|
|
|
2239
|
if ( !@{$self->{available_items}} ) { |
|
3290
|
|
|
|
|
4363
|
|
89
|
557
|
|
|
|
|
764
|
return; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Remember that we've seen this item, by removing it from the list of those |
93
|
|
|
|
|
|
|
# available |
94
|
2733
|
50
|
|
|
|
3431
|
if ( $item_pos > -1 ) { |
95
|
2733
|
|
|
|
|
1622
|
splice @{$self->{available_items}},$item_pos,1; |
|
2733
|
|
|
|
|
2904
|
|
96
|
|
|
|
|
|
|
} |
97
|
2733
|
|
|
|
|
4447
|
return $item; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 next_available |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Zero if there are items remaining; undef if there aren't. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub next_available { |
107
|
3253
|
|
|
3253
|
1
|
2327
|
my $self = shift; |
108
|
3253
|
100
|
|
|
|
2184
|
if ( 0 == @{$self->{available_items}} ) { |
|
3253
|
|
|
|
|
4192
|
|
109
|
825
|
|
|
|
|
1273
|
return; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else { |
112
|
2428
|
|
|
|
|
3930
|
return 0; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 _get_next |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Shoudl be implemented by a subclass |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _get_next { |
123
|
0
|
|
|
0
|
|
0
|
die "This method must be over-ridden.\n"; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 process_feedback |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Does nothing by default; may be overridden |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub process_feedback { |
133
|
1347
|
|
|
1347
|
1
|
1844
|
return; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|