[system] / trunk / pg / lib / Value / Union.pm Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

# Diff of /trunk/pg/lib/Value/Union.pm

Revision 3504 Revision 3505
184# 184#
185sub compare { 185sub compare {
186 my (\$l,\$r,\$flag) = @_; 186 my (\$l,\$r,\$flag) = @_;
187 if (\$l->promotePrecedence(\$r)) {return \$r->compare(\$l,!\$flag)} 187 if (\$l->promotePrecedence(\$r)) {return \$r->compare(\$l,!\$flag)}
188 \$r = promote(\$r); 188 \$r = promote(\$r);
189 if (\$l->getFlag('reduceUnionsForComparison')) {\$l = \$l->reduce; \$r = \$r->reduce} 189 if (\$l->getFlag('reduceUnionsForComparison')) {
190 \$l = \$l->reduce; \$l = \$pkg->make(\$l) unless \$l->type eq 'Union';
191 \$r = \$r->reduce; \$r = \$pkg->make(\$r) unless \$r->type eq 'Union';
192 }
190 if (\$flag) {my \$tmp = \$l; \$l = \$r; \$r = \$tmp}; 193 if (\$flag) {my \$tmp = \$l; \$l = \$r; \$r = \$tmp};
191 my @l = sort {\$a <=> \$b} \$l->value; 194 my @l = \$l->sort->value; my @r = \$r->sort->value;
192 my @r = sort {\$a <=> \$b} \$r->value;
193 while (scalar(@l) && scalar(@r)) { 195 while (scalar(@l) && scalar(@r)) {
194 my \$cmp = shift(@l) <=> shift(@r); 196 my \$cmp = shift(@l) <=> shift(@r);
195 return \$cmp if \$cmp; 197 return \$cmp if \$cmp;
196 } 198 }
197 return scalar(@l) - scalar(@r); 199 return scalar(@l) - scalar(@r);
210 if (\$x->type eq 'Set') {push(@singletons,\$x->value)} 212 if (\$x->type eq 'Set') {push(@singletons,\$x->value)}
211 elsif (\$x->{data}[0] == \$x->{data}[1]) {push(@singletons,\$x->{data}[0])} 213 elsif (\$x->{data}[0] == \$x->{data}[1]) {push(@singletons,\$x->{data}[0])}
212 else {push(@intervals,\$x)} 214 else {push(@intervals,\$x)}
213 } 215 }
214 my @union = (); my @set = (); my \$prevX; 216 my @union = (); my @set = (); my \$prevX;
215 @intervals = (sort {\$a <=> \$b} @intervals); 217 @intervals = (CORE::sort {\$a <=> \$b} @intervals);
216 ELEMENT: foreach my \$x (@singletons) { 218 ELEMENT: foreach my \$x (@singletons) {
217 next if defined(\$prevX) && \$prevX == \$x; \$prevX = \$x; 219 next if defined(\$prevX) && \$prevX == \$x; \$prevX = \$x;
218 foreach my \$I (@intervals) { 220 foreach my \$I (@intervals) {
219 my (\$a,\$b) = \$I->value; 221 my (\$a,\$b) = \$I->value;
220 last if \$x < \$a; 222 last if \$x < \$a;
243 return \$pkg->make(@union)->with(isReduced=>1); 245 return \$pkg->make(@union)->with(isReduced=>1);
244} 246}
245 247
246############################################ 248############################################
247# 249#
250# Sort a union lexicographically
251#
252sub sort {
253 my \$self = shift;
254 \$self->make(CORE::sort {\$a <=> \$b} \$self->value);
255}
256
257############################################
258#
248# Generate the various output formats 259# Generate the various output formats
249# 260#
250 261
251sub stringify { 262sub stringify {
252 my \$self = shift; 263 my \$self = shift;

Legend:
 Removed from v.3504 changed lines Added in v.3505