line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# vim:ts=4 sw=4 |
2
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
# Name : Class::STL::Containers.pm |
4
|
|
|
|
|
|
|
# Created : 22 February 2006 |
5
|
|
|
|
|
|
|
# Author : Mario Gaffiero (gaffie) |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright 2006-2007 Mario Gaffiero. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# This file is part of Class::STL::Containers(TM). |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Class::STL::Containers is free software; you can redistribute it and/or modify |
12
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
13
|
|
|
|
|
|
|
# the Free Software Foundation; version 2 of the License. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# Class::STL::Containers is distributed in the hope that it will be useful, |
16
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
|
|
|
|
# GNU General Public License for more details. |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
21
|
|
|
|
|
|
|
# along with Class::STL::Containers; if not, write to the Free Software |
22
|
|
|
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
23
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
# Modification History |
25
|
|
|
|
|
|
|
# When Version Who What |
26
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
27
|
|
|
|
|
|
|
# TO DO: |
28
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
29
|
|
|
|
|
|
|
package Class::STL::Containers; |
30
|
|
|
|
|
|
|
require 5.005_62; |
31
|
7
|
|
|
7
|
|
89
|
use strict; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
259
|
|
32
|
7
|
|
|
7
|
|
35
|
use warnings; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
224
|
|
33
|
7
|
|
|
7
|
|
36
|
use vars qw( $VERSION $BUILD @EXPORT_OK %EXPORT_TAGS ); |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
479
|
|
34
|
7
|
|
|
7
|
|
33
|
use Exporter; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
900
|
|
35
|
|
|
|
|
|
|
@EXPORT_OK = qw( vector list deque queue priority_queue stack tree ); |
36
|
|
|
|
|
|
|
%EXPORT_TAGS = ( all => [qw( vector list deque queue priority_queue stack tree )] ); |
37
|
|
|
|
|
|
|
$VERSION = '0.35'; |
38
|
|
|
|
|
|
|
$BUILD = 'Tue April 3 19:33:14 GMT 2007'; |
39
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
40
|
|
|
|
|
|
|
{ |
41
|
|
|
|
|
|
|
package Class::STL::Containers; |
42
|
7
|
|
|
7
|
|
36
|
use vars qw( $AUTOLOAD ); |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
2114
|
|
43
|
|
|
|
|
|
|
sub AUTOLOAD |
44
|
|
|
|
|
|
|
{ |
45
|
0
|
|
|
0
|
|
|
(my $func = $AUTOLOAD) =~ s/.*:://; |
46
|
0
|
0
|
|
|
|
|
return Class::STL::Containers::Vector->new(@_) if ($func eq 'vector'); |
47
|
0
|
0
|
|
|
|
|
return Class::STL::Containers::List->new(@_) if ($func eq 'list'); |
48
|
0
|
0
|
|
|
|
|
return Class::STL::Containers::Deque->new(@_) if ($func eq 'deque'); |
49
|
0
|
0
|
|
|
|
|
return Class::STL::Containers::Queue->new(@_) if ($func eq 'queue'); |
50
|
0
|
0
|
|
|
|
|
return Class::STL::Containers::PriorityQueue->new(@_) if ($func eq 'priority_queue'); |
51
|
0
|
0
|
|
|
|
|
return Class::STL::Containers::Stack->new(@_) if ($func eq 'stack'); |
52
|
0
|
0
|
|
|
|
|
return Class::STL::Containers::Tree->new(@_) if ($func eq 'tree'); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
package Class::STL::Containers::Abstract; |
58
|
7
|
|
|
7
|
|
44
|
use base qw(Class::STL::Element); # container is also an element |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
5108
|
|
59
|
7
|
|
|
7
|
|
14261
|
use overload '+' => 'append', '+=' => 'append', '=' => 'clone', '""' => 'str', '==' => 'eq', '!=' => 'ne'; |
|
7
|
|
|
|
|
10200
|
|
|
7
|
|
|
|
|
129
|
|
60
|
7
|
|
|
7
|
|
6042
|
use Class::STL::Iterators qw(:all); |
|
7
|
|
|
|
|
105
|
|
|
7
|
|
|
|
|
108
|
|
61
|
7
|
|
|
7
|
|
306
|
use UNIVERSAL qw(isa can); |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
36
|
|
62
|
7
|
|
|
7
|
|
4262
|
use Carp qw(confess); |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
487
|
|
63
|
|
|
|
|
|
|
use Class::STL::ClassMembers |
64
|
7
|
|
|
|
|
56
|
Class::STL::ClassMembers::DataMember->new( |
65
|
7
|
|
|
7
|
|
43
|
name => 'element_type', default => 'Class::STL::Element'); |
|
7
|
|
|
|
|
13
|
|
66
|
7
|
|
|
7
|
|
43
|
use Class::STL::ClassMembers::Constructor; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
56
|
|
67
|
|
|
|
|
|
|
# new(named-argument-list); |
68
|
|
|
|
|
|
|
# new(container-ref); -- copy ctor |
69
|
|
|
|
|
|
|
# new(element [, ...]); -- initialise new container with element(s). |
70
|
|
|
|
|
|
|
# new(iterator-start); -- initialise new container with copy of elments from other container. |
71
|
|
|
|
|
|
|
# new(iterator-start, iterator-finish); -- initialise new container with copy of elments from other container. |
72
|
|
|
|
|
|
|
# new(raw-data, [...]); -- |
73
|
|
|
|
|
|
|
sub new_extra # static function |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
0
|
|
|
my $self = shift; |
76
|
7
|
|
|
7
|
|
37
|
use vars qw(@ISA); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
20983
|
|
77
|
0
|
|
|
|
|
|
my @copy_elements; |
78
|
|
|
|
|
|
|
my @copy_iterators; |
79
|
0
|
|
|
|
|
|
my @raw_data; |
80
|
0
|
|
|
|
|
|
my @params; |
81
|
0
|
|
|
|
|
|
while (@_) |
82
|
|
|
|
|
|
|
{ |
83
|
0
|
|
|
|
|
|
my $p = shift; |
84
|
0
|
0
|
0
|
|
|
|
if (!ref($p) && int(@_) && (exists(${$self->members()}{$p}) || $self->can($p))) |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
85
|
|
|
|
|
|
|
{ |
86
|
0
|
|
|
|
|
|
shift; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
elsif (ref($p) && $p->isa('Class::STL::Iterators::Abstract')) |
89
|
|
|
|
|
|
|
{ |
90
|
0
|
|
|
|
|
|
CORE::push(@copy_iterators, $p); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
elsif (ref($p) && $p->isa(__PACKAGE__)) |
93
|
|
|
|
|
|
|
{ |
94
|
|
|
|
|
|
|
#? shift; # ??? why??? |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
elsif (ref($p) && $p->isa('Class::STL::Element')) |
97
|
|
|
|
|
|
|
{ |
98
|
0
|
|
|
|
|
|
CORE::push(@copy_elements, $p); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
0
|
|
|
|
|
|
CORE::push(@raw_data, $p); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
0
|
0
|
|
|
|
|
confess "element_type (@{[ $self->element_type() ]}) must be derived from Class::STL::Element!" |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
unless (UNIVERSAL::isa($self->element_type(), 'Class::STL::Element')); |
106
|
0
|
|
|
|
|
|
$self->data_type('array'); |
107
|
0
|
|
|
|
|
|
$self->data([]); # Array of (base) type Class::STL::Element |
108
|
0
|
|
|
|
|
|
foreach (@copy_elements) { $self->push($_); } |
|
0
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
while (@raw_data) { $self->push($self->factory(data => shift(@raw_data))); } |
|
0
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
if (@copy_iterators) { |
111
|
0
|
0
|
|
|
|
|
@copy_iterators >= 2 |
112
|
|
|
|
|
|
|
? $self->insert($self->begin(), $copy_iterators[0], $copy_iterators[1]) |
113
|
|
|
|
|
|
|
: $self->insert($self->begin(), $copy_iterators[0]); |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
return $self; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
sub append # (container-ref) -- append other to this container; |
118
|
|
|
|
|
|
|
{ |
119
|
0
|
|
|
0
|
|
|
my $self = shift; |
120
|
0
|
|
|
|
|
|
my $other = shift; |
121
|
0
|
|
|
|
|
|
$self->push($other->to_array()); |
122
|
0
|
|
|
|
|
|
return $self; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
sub factory # (@params) -- construct an element object and return it; |
125
|
|
|
|
|
|
|
{ |
126
|
0
|
|
|
0
|
|
|
my $self = shift; |
127
|
0
|
0
|
|
|
|
|
return Class::STL::Element->new(@_) if ($self->element_type() eq 'Class::STL::Element'); |
128
|
0
|
|
|
|
|
|
our %__factfun; |
129
|
0
|
0
|
|
|
|
|
if (!exists($__factfun{$self->element_type()})) |
130
|
|
|
|
|
|
|
{ |
131
|
0
|
|
|
|
|
|
$__factfun{$self->element_type()} = eval(" |
132
|
|
|
|
|
|
|
{ |
133
|
0
|
|
|
|
|
|
package @{[ ref($self) ]}\::Factory::__@{[ do{my $f=uc($self->element_type());$f=~s/\W+/_/g;$f} ]}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
use base qw(Class::STL::Element); |
135
|
|
|
|
|
|
|
sub _FACTORY |
136
|
|
|
|
|
|
|
{ |
137
|
|
|
|
|
|
|
my \$self = shift; |
138
|
0
|
|
|
|
|
|
return @{[ $self->element_type() ]}\->new(\@_); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
0
|
|
|
|
|
|
@{[ ref($self) ]}\::Factory::__@{[ do{my $f=uc($self->element_type());$f=~s/\W+/_/g;$f} ]}->new(); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
"); |
143
|
0
|
0
|
|
|
|
|
confess "**Error in eval for @{[ __PACKAGE__ ]} ptr_fun dynamic class creation:\n$@" if ($@); |
|
0
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
} |
145
|
0
|
|
|
|
|
|
return $__factfun{$self->element_type()}->_FACTORY(@_); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
#< return Class::STL::Element->new(@_) if ($self->element_type() eq 'Class::STL::Element'); |
148
|
|
|
|
|
|
|
#< my $e = eval("@{[ $self->element_type() ]}->new(\@_);"); # TODO: pre-gen factory sub code instead! |
149
|
|
|
|
|
|
|
#< confess "**Error in eval for @{[ $self->element_type() ]} factory creation:\n$@" if ($@); |
150
|
|
|
|
|
|
|
#< return $e; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
sub push # (element [, ...] ) -- append elements to container... |
153
|
|
|
|
|
|
|
{ |
154
|
0
|
|
|
0
|
|
|
my $self = shift; |
155
|
0
|
|
|
|
|
|
my $curr_sz = $self->size(); |
156
|
0
|
|
0
|
|
|
|
CORE::push(@{$self->data()}, grep(ref && $_->isa('Class::STL::Element'), @_)); |
|
0
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
return $self->size() - $curr_sz; # number of new elements inserted. |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
sub pop # (void) |
160
|
|
|
|
|
|
|
{ |
161
|
0
|
|
|
0
|
|
|
my $self = shift; |
162
|
0
|
|
|
|
|
|
CORE::pop(@{$self->data()}); |
|
0
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
return; # void return |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
sub top # (void) -- top() and pop() refer to same element. |
166
|
|
|
|
|
|
|
{ |
167
|
0
|
|
|
0
|
|
|
my $self = shift; |
168
|
0
|
|
|
|
|
|
return ${$self->data()}[$self->size()-1]; |
|
0
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
sub clear # (void) |
171
|
|
|
|
|
|
|
{ |
172
|
0
|
|
|
0
|
|
|
my $self = shift; |
173
|
0
|
|
|
|
|
|
$self->data([]); |
174
|
0
|
|
|
|
|
|
return; # void return |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
sub insert # |
177
|
|
|
|
|
|
|
{ |
178
|
0
|
|
|
0
|
|
|
my $self = shift; |
179
|
0
|
|
|
|
|
|
my $position = shift; |
180
|
0
|
0
|
0
|
|
|
|
confess $self->_insert_errmsg() |
|
|
|
0
|
|
|
|
|
181
|
|
|
|
|
|
|
unless (defined($position) && ref($position) |
182
|
|
|
|
|
|
|
&& $position->isa('Class::STL::Iterators::Abstract')); |
183
|
0
|
|
|
|
|
|
my $size = $self->size(); |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# insert(position, iterator-start, iterator-finish);# insert copies |
186
|
0
|
0
|
0
|
|
|
|
if (defined($_[0]) && ref($_[0]) && $_[0]->isa('Class::STL::Iterators::Abstract') |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
187
|
|
|
|
|
|
|
&& defined($_[1]) && ref($_[1]) && $_[1]->isa('Class::STL::Iterators::Abstract')) |
188
|
|
|
|
|
|
|
{ |
189
|
0
|
|
|
|
|
|
my $iter_start = shift; |
190
|
0
|
|
|
|
|
|
my $iter_finish = shift; |
191
|
0
|
0
|
|
|
|
|
my $pos = $self->size() ? $position->arr_idx() : 0; |
192
|
0
|
|
|
|
|
|
for (my $i = $iter_finish->new($iter_finish); $i >= $iter_start; --$i) |
193
|
|
|
|
|
|
|
{# insert copies |
194
|
0
|
|
|
|
|
|
$position->can('assign') |
195
|
|
|
|
|
|
|
? $position->assign($i->p_element()->clone()) |
196
|
0
|
0
|
|
|
|
|
: CORE::splice(@{$self->data()}, $pos, 0, $i->p_element()->clone()); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
# insert(position, iterator-start);# insert copies |
200
|
|
|
|
|
|
|
elsif (defined($_[0]) && ref($_[0]) && $_[0]->isa('Class::STL::Iterators::Abstract')) |
201
|
|
|
|
|
|
|
{ |
202
|
0
|
|
|
|
|
|
my $iter_start = shift; |
203
|
0
|
|
|
|
|
|
for (my $i = $iter_start->new($iter_start); !$i->at_end(); ++$i) |
204
|
|
|
|
|
|
|
{# insert copies |
205
|
0
|
0
|
0
|
|
|
|
if ($position->can('assign')) |
|
|
0
|
|
|
|
|
|
206
|
|
|
|
|
|
|
{ |
207
|
0
|
|
|
|
|
|
$position->assign($i->p_element()->clone()); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
#? elsif (!$size || !$position->at_end()) |
210
|
|
|
|
|
|
|
elsif (!$size || $position->at_end()) |
211
|
|
|
|
|
|
|
{ |
212
|
0
|
|
|
|
|
|
$self->push($i->p_element()->clone()); |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
else |
215
|
|
|
|
|
|
|
{ |
216
|
0
|
|
|
|
|
|
CORE::splice(@{$self->data()}, $position->arr_idx(), 0, $i->p_element()->clone()); |
|
0
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
$position++; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
# insert(position, element [, ...]); # insert references (not copies) |
222
|
|
|
|
|
|
|
elsif (defined($_[0]) && ref($_[0]) && $_[0]->isa('Class::STL::Element')) |
223
|
|
|
|
|
|
|
{ |
224
|
0
|
0
|
|
|
|
|
return $position->assign(@_) if ($position->can('assign')); |
225
|
0
|
|
|
|
|
|
!$size || $position->at_end() |
226
|
|
|
|
|
|
|
? $self->push(@_) |
227
|
0
|
0
|
0
|
|
|
|
: CORE::splice(@{$self->data()}, $position->arr_idx(), 0, |
|
|
|
0
|
|
|
|
|
228
|
|
|
|
|
|
|
grep(ref && $_->isa('Class::STL::Element'), @_)); |
229
|
0
|
0
|
|
|
|
|
$position->first() if (!$size); |
230
|
0
|
|
|
|
|
|
$position->next(); |
231
|
0
|
|
|
|
|
|
return $position->clone()-1; # iterator points to inserted element |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
# insert(position, size, element);# insert copies |
234
|
|
|
|
|
|
|
elsif (defined($_[0]) && defined($_[1]) && ref($_[1]) && $_[1]->isa('Class::STL::Element')) |
235
|
|
|
|
|
|
|
{ |
236
|
0
|
|
|
|
|
|
my $num_repeat = shift; |
237
|
0
|
|
|
|
|
|
my $element = shift; |
238
|
0
|
|
|
|
|
|
my @elems; |
239
|
0
|
|
|
|
|
|
foreach (1..$num_repeat) { CORE::push(@elems, $element->clone()); } # insert copies |
|
0
|
|
|
|
|
|
|
240
|
0
|
0
|
|
|
|
|
return $position->assign(@elems) if ($position->can('assign')); |
241
|
0
|
|
|
|
|
|
!$size || $position->at_end() |
242
|
|
|
|
|
|
|
? $self->push(@elems) |
243
|
0
|
0
|
0
|
|
|
|
: CORE::splice(@{$self->data()}, $position->arr_idx(), 0, @elems); |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
else |
246
|
|
|
|
|
|
|
{ |
247
|
0
|
|
|
|
|
|
confess $self->_insert_errmsg(); |
248
|
|
|
|
|
|
|
} |
249
|
0
|
0
|
|
|
|
|
$position->first() if (!$size); |
250
|
0
|
|
|
|
|
|
$position->next(); |
251
|
0
|
|
|
|
|
|
return; # void |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
sub erase # ( iterator | iterator-start, iterator-finish ) |
254
|
|
|
|
|
|
|
{ |
255
|
0
|
|
|
0
|
|
|
my $self = shift; |
256
|
0
|
|
|
|
|
|
my $iter_start = shift; |
257
|
0
|
|
0
|
|
|
|
my $iter_finish = shift || $iter_start->clone(); |
258
|
0
|
|
|
|
|
|
my $count=0; |
259
|
0
|
0
|
|
|
|
|
CORE::splice(@{$self->data()}, $iter_start->arr_idx(), $count) |
|
0
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
if (($count=distance($iter_start, $iter_finish)+1) > 0); |
261
|
0
|
0
|
|
|
|
|
$iter_start->last() if ($iter_start->at_end()); |
262
|
0
|
|
|
|
|
|
return $iter_start; # iterator |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
sub _insert_errmsg |
265
|
|
|
|
|
|
|
{ |
266
|
0
|
|
|
0
|
|
|
return "@{[ __PACKAGE__ ]}::insert usage:\ninsert( position, element [, ...] );\n" |
|
0
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
. "insert( position, iterator-start, iterator-finish );\n" |
268
|
|
|
|
|
|
|
. "insert( position, size, element );\n"; |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
sub begin # (void) |
271
|
|
|
|
|
|
|
{ |
272
|
0
|
|
|
0
|
|
|
my $self = shift; |
273
|
0
|
|
|
|
|
|
return iterator(p_container => $self)->first(); |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
sub end # (void) |
276
|
|
|
|
|
|
|
{ |
277
|
|
|
|
|
|
|
# WARNING: end() points to last element unlike C++/STL-end() which points to AFTER last element!! |
278
|
|
|
|
|
|
|
# See examples/iterator.pl for correct iterator traversal example. |
279
|
0
|
|
|
0
|
|
|
my $self = shift; |
280
|
0
|
|
|
|
|
|
return iterator(p_container => $self)->last(); |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
sub rbegin # (void) |
283
|
|
|
|
|
|
|
{ |
284
|
0
|
|
|
0
|
|
|
my $self = shift; |
285
|
0
|
|
|
|
|
|
return reverse_iterator(p_container => $self)->first(); |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
sub rend # (void) |
288
|
|
|
|
|
|
|
{ |
289
|
0
|
|
|
0
|
|
|
my $self = shift; |
290
|
0
|
|
|
|
|
|
return reverse_iterator(p_container => $self)->last(); |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
sub size # (void) |
293
|
|
|
|
|
|
|
{ |
294
|
0
|
|
|
0
|
|
|
my $self = shift; |
295
|
0
|
0
|
|
|
|
|
return defined($self->data()) ? int(@{$self->data()}) : 0; |
|
0
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
sub empty # return bool |
298
|
|
|
|
|
|
|
{ |
299
|
0
|
|
|
0
|
|
|
my $self = shift; |
300
|
0
|
0
|
|
|
|
|
return $self->size() ? 0 : 1; # 1==true; 0==false |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
sub to_array # (void) |
303
|
|
|
|
|
|
|
{ |
304
|
0
|
|
|
0
|
|
|
my $self = shift; |
305
|
0
|
|
0
|
|
|
|
my $level = shift || undef; |
306
|
|
|
|
|
|
|
|
307
|
0
|
0
|
|
|
|
|
return (@{$self->data()}) # array of data |
|
0
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
unless (defined($level)); |
309
|
|
|
|
|
|
|
|
310
|
0
|
|
|
|
|
|
my @nodes; |
311
|
0
|
|
|
|
|
|
foreach (@{$self->data()}) { # traverse tree... |
|
0
|
|
|
|
|
|
|
312
|
0
|
0
|
|
|
|
|
($_->isa('Class::STL::Containers::Abstract')) |
313
|
|
|
|
|
|
|
? CORE::push(@nodes, $_->to_array($level+1)) |
314
|
|
|
|
|
|
|
: CORE::push(@nodes, $_); |
315
|
|
|
|
|
|
|
} |
316
|
0
|
|
|
|
|
|
return @nodes; |
317
|
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
|
sub join # (delimiter) |
319
|
|
|
|
|
|
|
{ |
320
|
0
|
|
|
0
|
|
|
my $self = shift; |
321
|
0
|
|
0
|
|
|
|
my $delim = shift || ''; |
322
|
0
|
|
|
|
|
|
return CORE::join($delim, map($_->print(), $self->to_array())); # string |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
sub eq # (container-ref) |
325
|
|
|
|
|
|
|
{ |
326
|
0
|
|
|
0
|
|
|
my $self = shift; |
327
|
0
|
|
|
|
|
|
my $other = shift; |
328
|
0
|
0
|
|
|
|
|
return 0 unless $self->size() == $other->size(); |
329
|
0
|
|
0
|
|
|
|
for (my $i1=$self->begin(), my $i2=$other->begin(); !$i1->at_end() && !$i2->at_end(); ++$i1, ++$i2) |
330
|
|
|
|
|
|
|
{ |
331
|
0
|
0
|
|
|
|
|
return 0 unless ($i1->p_element()->eq($i2->p_element())); # not equal |
332
|
|
|
|
|
|
|
} |
333
|
0
|
|
|
|
|
|
return 1; # containers are equal |
334
|
|
|
|
|
|
|
} |
335
|
|
|
|
|
|
|
sub ne |
336
|
|
|
|
|
|
|
{ |
337
|
0
|
|
|
0
|
|
|
my $self = shift; |
338
|
0
|
0
|
|
|
|
|
return $self->eq(shift) ? 0 : 1; |
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
sub str |
341
|
0
|
|
|
0
|
|
|
{ |
342
|
|
|
|
|
|
|
} |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
345
|
|
|
|
|
|
|
{ |
346
|
|
|
|
|
|
|
package Class::STL::Containers::Vector; |
347
|
7
|
|
|
7
|
|
72
|
use base qw(Class::STL::Containers::Abstract); # vector is also an element |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
5124
|
|
348
|
7
|
|
|
7
|
|
66
|
use Class::STL::ClassMembers; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
237
|
|
349
|
7
|
|
|
7
|
|
45
|
use Class::STL::ClassMembers::Constructor; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
54
|
|
350
|
7
|
|
|
7
|
|
42
|
use Class::STL::ClassMembers::Disable qw(push_front); |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
65
|
|
351
|
|
|
|
|
|
|
sub push_back # (element [, ...]) |
352
|
|
|
|
|
|
|
{ |
353
|
0
|
|
|
0
|
|
|
my $self = shift; |
354
|
0
|
|
|
|
|
|
return $self->push(@_); # number of new elements inserted. |
355
|
|
|
|
|
|
|
} |
356
|
|
|
|
|
|
|
sub pop_back # (void) |
357
|
|
|
|
|
|
|
{ |
358
|
0
|
|
|
0
|
|
|
my $self = shift; |
359
|
0
|
|
|
|
|
|
$self->pop(); |
360
|
0
|
|
|
|
|
|
return; # void return |
361
|
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
sub back # (void) |
363
|
|
|
|
|
|
|
{ |
364
|
0
|
|
|
0
|
|
|
my $self = shift; |
365
|
0
|
|
|
|
|
|
return ${$self->data()}[$self->size()-1]; # element ref |
|
0
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
sub front # (void) |
368
|
|
|
|
|
|
|
{ |
369
|
0
|
|
|
0
|
|
|
my $self = shift; |
370
|
0
|
|
|
|
|
|
return ${$self->data()}[0]; # element ref |
|
0
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
} |
372
|
|
|
|
|
|
|
sub at # (idx) |
373
|
|
|
|
|
|
|
{ |
374
|
0
|
|
|
0
|
|
|
my $self = shift; |
375
|
0
|
|
0
|
|
|
|
my $idx = shift || 0; |
376
|
0
|
|
|
|
|
|
return ${$self->data()}[$idx]; # element ref |
|
0
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
} |
379
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
380
|
|
|
|
|
|
|
{ |
381
|
|
|
|
|
|
|
package Class::STL::Containers::Deque; |
382
|
7
|
|
|
7
|
|
47
|
use base qw(Class::STL::Containers::Vector); |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
3755
|
|
383
|
7
|
|
|
7
|
|
46
|
use Class::STL::ClassMembers; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
43
|
|
384
|
7
|
|
|
7
|
|
41
|
use Class::STL::ClassMembers::Constructor; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
49
|
|
385
|
|
|
|
|
|
|
sub push_front # (element [, ...]) |
386
|
|
|
|
|
|
|
{ |
387
|
0
|
|
|
0
|
|
|
my $self = shift; |
388
|
0
|
|
|
|
|
|
my $curr_sz = $self->size(); |
389
|
0
|
|
0
|
|
|
|
unshift(@{$self->data()}, grep(ref && $_->isa("Class::STL::Element"), @_)); |
|
0
|
|
|
|
|
|
|
390
|
0
|
|
|
|
|
|
return $self->size() - $curr_sz; # number of new elements inserted. |
391
|
|
|
|
|
|
|
} |
392
|
|
|
|
|
|
|
sub pop_front # (void) |
393
|
|
|
|
|
|
|
{ |
394
|
0
|
|
|
0
|
|
|
my $self = shift; |
395
|
0
|
|
|
|
|
|
my $front = shift(@{$self->data()}); |
|
0
|
|
|
|
|
|
|
396
|
0
|
|
|
|
|
|
return; # void return |
397
|
|
|
|
|
|
|
} |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
400
|
|
|
|
|
|
|
{ |
401
|
|
|
|
|
|
|
package Class::STL::Containers::Queue; |
402
|
7
|
|
|
7
|
|
46
|
use base qw(Class::STL::Containers::Abstract); |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
4375
|
|
403
|
7
|
|
|
7
|
|
53
|
use Class::STL::ClassMembers; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
48
|
|
404
|
7
|
|
|
7
|
|
40
|
use Class::STL::ClassMembers::Constructor; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
45
|
|
405
|
7
|
|
|
7
|
|
41
|
use Class::STL::ClassMembers::Disable qw(push_back); |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
56
|
|
406
|
7
|
|
|
7
|
|
40
|
use Class::STL::ClassMembers::Disable qw(pop_back); |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
36
|
|
407
|
|
|
|
|
|
|
sub back # (void) |
408
|
|
|
|
|
|
|
{ |
409
|
0
|
|
|
0
|
|
|
my $self = shift; |
410
|
0
|
|
|
|
|
|
return $self->SUPER::top(); |
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
sub front # (void) |
413
|
|
|
|
|
|
|
{ |
414
|
0
|
|
|
0
|
|
|
my $self = shift; |
415
|
0
|
|
|
|
|
|
return ${$self->data()}[0]; # element ref |
|
0
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
} |
417
|
|
|
|
|
|
|
sub push # (element [,...]) -- push to back |
418
|
|
|
|
|
|
|
{ |
419
|
0
|
|
|
0
|
|
|
my $self = shift; |
420
|
0
|
|
|
|
|
|
$self->SUPER::push(@_); |
421
|
0
|
|
|
|
|
|
return; # void return |
422
|
|
|
|
|
|
|
} |
423
|
|
|
|
|
|
|
sub pop # (void) -- pop from front |
424
|
|
|
|
|
|
|
{ |
425
|
0
|
|
|
0
|
|
|
my $self = shift; |
426
|
0
|
|
|
|
|
|
shift(@{$self->data()}); |
|
0
|
|
|
|
|
|
|
427
|
0
|
|
|
|
|
|
return; # void return |
428
|
|
|
|
|
|
|
} |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
431
|
|
|
|
|
|
|
{ |
432
|
|
|
|
|
|
|
package Class::STL::Containers::Stack; |
433
|
7
|
|
|
7
|
|
42
|
use base qw(Class::STL::Containers::Abstract); |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
3662
|
|
434
|
7
|
|
|
7
|
|
48
|
use Class::STL::ClassMembers; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
47
|
|
435
|
7
|
|
|
7
|
|
43
|
use Class::STL::ClassMembers::Constructor; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
48
|
|
436
|
7
|
|
|
7
|
|
45
|
use Class::STL::ClassMembers::Disable qw(push_back); |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
49
|
|
437
|
7
|
|
|
7
|
|
38
|
use Class::STL::ClassMembers::Disable qw(pop_back); |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
35
|
|
438
|
7
|
|
|
7
|
|
42
|
use Class::STL::ClassMembers::Disable qw(front); |
|
7
|
|
|
|
|
25
|
|
|
7
|
|
|
|
|
36
|
|
439
|
|
|
|
|
|
|
sub top # (void) |
440
|
|
|
|
|
|
|
{ |
441
|
0
|
|
|
0
|
|
|
my $self = shift; |
442
|
0
|
|
|
|
|
|
return $self->SUPER::top(); |
443
|
|
|
|
|
|
|
} |
444
|
|
|
|
|
|
|
sub push # (element [,...]) |
445
|
|
|
|
|
|
|
{ |
446
|
0
|
|
|
0
|
|
|
my $self = shift; |
447
|
0
|
|
|
|
|
|
$self->SUPER::push(@_); |
448
|
|
|
|
|
|
|
} |
449
|
|
|
|
|
|
|
sub pop # (void) |
450
|
|
|
|
|
|
|
{ |
451
|
0
|
|
|
0
|
|
|
my $self = shift; |
452
|
0
|
|
|
|
|
|
$self->SUPER::pop(); |
453
|
|
|
|
|
|
|
} |
454
|
|
|
|
|
|
|
} |
455
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
456
|
|
|
|
|
|
|
{ |
457
|
|
|
|
|
|
|
package Class::STL::Containers::Tree; |
458
|
7
|
|
|
7
|
|
141
|
use base qw(Class::STL::Containers::Deque); |
|
7
|
|
|
|
|
31
|
|
|
7
|
|
|
|
|
4186
|
|
459
|
7
|
|
|
7
|
|
129
|
use Class::STL::ClassMembers; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
52
|
|
460
|
7
|
|
|
7
|
|
39
|
use Class::STL::ClassMembers::Constructor; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
129
|
|
461
|
|
|
|
|
|
|
sub new_extra |
462
|
|
|
|
|
|
|
{ |
463
|
0
|
|
|
0
|
|
|
my $self = shift; |
464
|
0
|
|
|
|
|
|
$self->element_type(__PACKAGE__); |
465
|
0
|
|
|
|
|
|
return $self; |
466
|
|
|
|
|
|
|
} |
467
|
|
|
|
|
|
|
sub to_array # (void) |
468
|
|
|
|
|
|
|
{ |
469
|
0
|
|
|
0
|
|
|
my $self = shift; |
470
|
0
|
|
|
|
|
|
$self->SUPER::to_array(1); |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
} |
473
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
474
|
|
|
|
|
|
|
{ |
475
|
|
|
|
|
|
|
package Class::STL::Containers::List; |
476
|
7
|
|
|
7
|
|
50
|
use base qw(Class::STL::Containers::Deque); |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
3871
|
|
477
|
7
|
|
|
7
|
|
52
|
use Class::STL::ClassMembers; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
46
|
|
478
|
7
|
|
|
7
|
|
5789
|
use Class::STL::ClassMembers::Constructor; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
47
|
|
479
|
7
|
|
|
7
|
|
42
|
use Class::STL::ClassMembers::Disable qw(at); |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
57
|
|
480
|
|
|
|
|
|
|
sub reverse # (void) |
481
|
|
|
|
|
|
|
{ |
482
|
0
|
|
|
0
|
|
|
my $self = shift; |
483
|
0
|
|
|
|
|
|
$self->data([ CORE::reverse(@{$self->data()}) ]); |
|
0
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
} |
485
|
|
|
|
|
|
|
sub sort # (void | cmp) |
486
|
|
|
|
|
|
|
{ |
487
|
0
|
|
|
0
|
|
|
my $self = shift; |
488
|
0
|
|
|
|
|
|
$self->data([ CORE::sort { $a->cmp($b) } (@{$self->data()}) ]); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
# sort according to cmp |
490
|
|
|
|
|
|
|
} |
491
|
|
|
|
|
|
|
sub splice |
492
|
0
|
|
|
0
|
|
|
{ |
493
|
|
|
|
|
|
|
#TODO |
494
|
|
|
|
|
|
|
} |
495
|
|
|
|
|
|
|
sub merge |
496
|
0
|
|
|
0
|
|
|
{ |
497
|
|
|
|
|
|
|
#TODO |
498
|
|
|
|
|
|
|
} |
499
|
|
|
|
|
|
|
sub remove # (element) |
500
|
0
|
|
|
0
|
|
|
{ |
501
|
|
|
|
|
|
|
#TODO |
502
|
|
|
|
|
|
|
} |
503
|
|
|
|
|
|
|
sub unique # (void | predicate) |
504
|
0
|
|
|
0
|
|
|
{ |
505
|
|
|
|
|
|
|
#TODO |
506
|
|
|
|
|
|
|
#Erases consecutive elements matching a true condition of the binary_pred. The first occurrence is not removed. |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
} |
509
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
510
|
|
|
|
|
|
|
{ |
511
|
|
|
|
|
|
|
package Class::STL::Element::Priority; |
512
|
7
|
|
|
7
|
|
71
|
use base qw(Class::STL::Element); |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
657
|
|
513
|
7
|
|
|
7
|
|
49
|
use Class::STL::ClassMembers qw(priority); |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
39
|
|
514
|
7
|
|
|
7
|
|
43
|
use Class::STL::ClassMembers::Constructor; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
47
|
|
515
|
|
|
|
|
|
|
sub cmp |
516
|
|
|
|
|
|
|
{ |
517
|
0
|
|
|
0
|
|
|
my $self = shift; |
518
|
0
|
|
|
|
|
|
my $other = shift; |
519
|
0
|
0
|
|
|
|
|
return $self->eq($other) ? 0 : $self->lt($other) ? -1 : 1; |
|
|
0
|
|
|
|
|
|
520
|
|
|
|
|
|
|
} |
521
|
|
|
|
|
|
|
sub eq # (element) |
522
|
|
|
|
|
|
|
{ |
523
|
0
|
|
|
0
|
|
|
my $self = shift; |
524
|
0
|
|
|
|
|
|
my $other = shift; |
525
|
0
|
|
|
|
|
|
return $self->priority() == $other->priority(); |
526
|
|
|
|
|
|
|
} |
527
|
|
|
|
|
|
|
sub ne # (element) |
528
|
|
|
|
|
|
|
{ |
529
|
0
|
|
|
0
|
|
|
my $self = shift; |
530
|
0
|
|
|
|
|
|
return !$self->eq(shift); |
531
|
|
|
|
|
|
|
} |
532
|
|
|
|
|
|
|
sub gt # (element) |
533
|
|
|
|
|
|
|
{ |
534
|
0
|
|
|
0
|
|
|
my $self = shift; |
535
|
0
|
|
|
|
|
|
my $other = shift; |
536
|
0
|
|
|
|
|
|
return $self->priority() > $other->priority(); |
537
|
|
|
|
|
|
|
} |
538
|
|
|
|
|
|
|
sub lt # (element) |
539
|
|
|
|
|
|
|
{ |
540
|
0
|
|
|
0
|
|
|
my $self = shift; |
541
|
0
|
|
|
|
|
|
my $other = shift; |
542
|
0
|
|
|
|
|
|
return $self->priority() < $other->priority(); |
543
|
|
|
|
|
|
|
} |
544
|
|
|
|
|
|
|
sub ge # (element) |
545
|
|
|
|
|
|
|
{ |
546
|
0
|
|
|
0
|
|
|
my $self = shift; |
547
|
0
|
|
|
|
|
|
my $other = shift; |
548
|
0
|
|
|
|
|
|
return $self->priority() >= $other->priority(); |
549
|
|
|
|
|
|
|
} |
550
|
|
|
|
|
|
|
sub le # (element) |
551
|
|
|
|
|
|
|
{ |
552
|
0
|
|
|
0
|
|
|
my $self = shift; |
553
|
0
|
|
|
|
|
|
my $other = shift; |
554
|
0
|
|
|
|
|
|
return $self->priority() <= $other->priority(); |
555
|
|
|
|
|
|
|
} |
556
|
|
|
|
|
|
|
} |
557
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
558
|
|
|
|
|
|
|
{ |
559
|
|
|
|
|
|
|
package Class::STL::Containers::PriorityQueue; |
560
|
7
|
|
|
7
|
|
43
|
use base qw(Class::STL::Containers::Vector); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
4919
|
|
561
|
7
|
|
|
7
|
|
57
|
use Class::STL::ClassMembers; |
|
7
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
53
|
|
562
|
7
|
|
|
7
|
|
49
|
use Class::STL::ClassMembers::Constructor; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
55
|
|
563
|
7
|
|
|
7
|
|
45
|
use Class::STL::ClassMembers::Disable qw(push_back); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
58
|
|
564
|
7
|
|
|
7
|
|
41
|
use Class::STL::ClassMembers::Disable qw(pop_back); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
34
|
|
565
|
7
|
|
|
7
|
|
40
|
use Class::STL::ClassMembers::Disable qw(front); |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
32
|
|
566
|
|
|
|
|
|
|
sub new_extra |
567
|
|
|
|
|
|
|
{ |
568
|
0
|
|
|
0
|
|
|
my $self = shift; |
569
|
0
|
|
|
|
|
|
$self->element_type('Class::STL::Element::Priority'); |
570
|
0
|
|
|
|
|
|
return $self; |
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
sub push |
573
|
|
|
|
|
|
|
{ |
574
|
0
|
|
|
0
|
|
|
my $self = shift; |
575
|
0
|
|
|
|
|
|
while (my $d = shift) |
576
|
|
|
|
|
|
|
{ |
577
|
0
|
0
|
0
|
|
|
|
if (!$self->size() || $d->ge($self->top())) |
578
|
|
|
|
|
|
|
{ |
579
|
0
|
|
|
|
|
|
$self->SUPER::push($d); |
580
|
0
|
|
|
|
|
|
next; |
581
|
|
|
|
|
|
|
} |
582
|
0
|
|
|
|
|
|
for (my $i=$self->begin(); !$i->at_end(); ++$i) |
583
|
|
|
|
|
|
|
{ |
584
|
0
|
0
|
|
|
|
|
if ($i->p_element()->gt($d)) |
585
|
|
|
|
|
|
|
{ |
586
|
0
|
|
|
|
|
|
$self->insert($i, $d); |
587
|
0
|
|
|
|
|
|
last; |
588
|
|
|
|
|
|
|
} |
589
|
|
|
|
|
|
|
} |
590
|
|
|
|
|
|
|
} |
591
|
|
|
|
|
|
|
} |
592
|
|
|
|
|
|
|
sub pop |
593
|
|
|
|
|
|
|
{ |
594
|
0
|
|
|
0
|
|
|
my $self = shift; |
595
|
0
|
|
|
|
|
|
$self->SUPER::pop(); |
596
|
|
|
|
|
|
|
} |
597
|
|
|
|
|
|
|
sub top |
598
|
|
|
|
|
|
|
{ |
599
|
0
|
|
|
0
|
|
|
my $self = shift; |
600
|
0
|
|
|
|
|
|
return $self->SUPER::top(); |
601
|
|
|
|
|
|
|
} |
602
|
|
|
|
|
|
|
sub refresh |
603
|
|
|
|
|
|
|
{ |
604
|
|
|
|
|
|
|
# If the priority values were modified then a refresh() is required to re-order the elements. |
605
|
0
|
|
|
0
|
|
|
my $self = shift; |
606
|
0
|
|
|
|
|
|
$self->data([ CORE::sort { $a->cmp($b) } (@{$self->data()}) ]); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
# sort according to cmp |
608
|
|
|
|
|
|
|
} |
609
|
|
|
|
|
|
|
} |
610
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
611
|
|
|
|
|
|
|
{ |
612
|
|
|
|
|
|
|
package Class::STL::Containers::Set; |
613
|
7
|
|
|
7
|
|
52
|
use base qw(Class::STL::Containers::Abstract); |
|
7
|
|
|
|
|
28
|
|
|
7
|
|
|
|
|
4450
|
|
614
|
|
|
|
|
|
|
#TODO |
615
|
|
|
|
|
|
|
} |
616
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
617
|
|
|
|
|
|
|
{ |
618
|
|
|
|
|
|
|
package Class::STL::Containers::MultiSet; |
619
|
7
|
|
|
7
|
|
44
|
use base qw(Class::STL::Containers::Set); |
|
7
|
|
|
|
|
28
|
|
|
7
|
|
|
|
|
3677
|
|
620
|
|
|
|
|
|
|
#TODO |
621
|
|
|
|
|
|
|
} |
622
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
623
|
|
|
|
|
|
|
{ |
624
|
|
|
|
|
|
|
package Class::STL::Containers::Map; |
625
|
7
|
|
|
7
|
|
47
|
use base qw(Class::STL::Containers::Abstract); |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
3847
|
|
626
|
|
|
|
|
|
|
#TODO |
627
|
|
|
|
|
|
|
} |
628
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
629
|
|
|
|
|
|
|
{ |
630
|
|
|
|
|
|
|
package Class::STL::Containers::MultiMap; |
631
|
7
|
|
|
7
|
|
45
|
use base qw(Class::STL::Containers::Map); |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
3603
|
|
632
|
|
|
|
|
|
|
#TODO |
633
|
|
|
|
|
|
|
} |
634
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
635
|
|
|
|
|
|
|
{ |
636
|
|
|
|
|
|
|
package Class::STL::Containers::MakeFind; |
637
|
7
|
|
|
7
|
|
135
|
use UNIVERSAL qw(isa can); |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
59
|
|
638
|
7
|
|
|
7
|
|
4551
|
use Carp qw(cluck confess); |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
2930
|
|
639
|
|
|
|
|
|
|
sub new # --> import... |
640
|
|
|
|
|
|
|
{ |
641
|
0
|
|
|
0
|
|
|
my $proto = shift; |
642
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
643
|
0
|
|
|
|
|
|
my $self = {}; |
644
|
0
|
|
|
|
|
|
bless($self, $class); |
645
|
0
|
|
|
|
|
|
my $package = (caller())[0]; |
646
|
0
|
0
|
|
|
|
|
confess "**Error: MakeFind is only available to classes derived from Class::STL::Containers::Abstract!\n" |
647
|
|
|
|
|
|
|
unless UNIVERSAL::isa($package, 'Class::STL::Containers::Abstract'); |
648
|
0
|
|
|
|
|
|
my $this = $package; |
649
|
0
|
|
|
|
|
|
$this =~ s/[:]+/_/g; |
650
|
0
|
|
|
|
|
|
my $member_name = shift; |
651
|
0
|
|
|
|
|
|
my $code = " |
652
|
0
|
|
|
|
|
|
sub $package\::find |
653
|
|
|
|
|
|
|
{ |
654
|
|
|
|
|
|
|
my \$self = shift; |
655
|
|
|
|
|
|
|
my \$what = shift; |
656
|
|
|
|
|
|
|
return Class::STL::Algorithms::find_if |
657
|
|
|
|
|
|
|
( |
658
|
|
|
|
|
|
|
\$self->begin(), \$self->end(), |
659
|
0
|
|
|
|
|
|
$package\::Find@{[ uc($member_name) ]}->new(what => \$what) |
660
|
|
|
|
|
|
|
); |
661
|
|
|
|
|
|
|
} |
662
|
|
|
|
|
|
|
{ |
663
|
|
|
|
|
|
|
package $package\::Find@{[ uc($member_name) ]}; |
664
|
|
|
|
|
|
|
use base qw(Class::STL::Utilities::FunctionObject::UnaryFunction); |
665
|
|
|
|
|
|
|
use Class::STL::ClassMembers qw(what); |
666
|
|
|
|
|
|
|
use Class::STL::ClassMembers::Constructor; |
667
|
|
|
|
|
|
|
sub function_operator |
668
|
|
|
|
|
|
|
{ |
669
|
|
|
|
|
|
|
my \$self = shift; |
670
|
|
|
|
|
|
|
my \$arg = shift; # element object |
671
|
|
|
|
|
|
|
return \$arg->$member_name() eq \$self->what() ? \$arg : 0; |
672
|
|
|
|
|
|
|
} |
673
|
|
|
|
|
|
|
}"; |
674
|
0
|
|
|
|
|
|
eval($code); |
675
|
0
|
0
|
|
|
|
|
cluck "**MakeFind Error:$@\n$code" if ($@); |
676
|
|
|
|
|
|
|
} |
677
|
|
|
|
|
|
|
} |
678
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------- |
679
|
|
|
|
|
|
|
1; |