Hello community,
here is the log from the commit of package perl-Set-Scalar
checked in at Fri Nov 2 01:37:27 CET 2007.
--------
--- perl-Set-Scalar/perl-Set-Scalar.changes 2007-10-08 09:58:25.000000000 +0200
+++ /mounts/work_src_done/STABLE/perl-Set-Scalar/perl-Set-Scalar.changes 2007-11-01 15:48:56.000000000 +0100
@@ -1,0 +2,14 @@
+Thu Nov 1 15:43:38 CET 2007 - anicka@suse.cz
+
+- update to 1.22
+ * Add cartesian_product() and power_set(), both as full
+ constructors and as iterators.
+ * Add empty_clone().
+ * Makefile.PL not requiring Test::More since we are not using it.
+ * Made to work with the upcoming Perl 5.005_05
+ (yes, you read that right), most importantly
+ Scalar::Util made optional (we fall back to
+ pure Perl emulations for blessed() and refaddr()
+ if necessary). Everything else already worked.
+
+-------------------------------------------------------------------
Old:
----
Set-Scalar-1.21.tar.bz2
New:
----
Set-Scalar-1.22.tar.bz2
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ perl-Set-Scalar.spec ++++++
--- /var/tmp/diff_new_pack.m25420/_old 2007-11-02 01:37:24.000000000 +0100
+++ /var/tmp/diff_new_pack.m25420/_new 2007-11-02 01:37:24.000000000 +0100
@@ -1,5 +1,5 @@
#
-# spec file for package perl-Set-Scalar (Version 1.21)
+# spec file for package perl-Set-Scalar (Version 1.22)
#
# Copyright (c) 2007 SUSE LINUX Products GmbH, Nuernberg, Germany.
# This file and all modifications and additions to the pristine
@@ -11,7 +11,7 @@
# norootforbuild
Name: perl-Set-Scalar
-Version: 1.21
+Version: 1.22
Release: 1
Requires: perl = %{perl_version}
AutoReqProv: on
@@ -60,6 +60,17 @@
%{perl_vendorarch}/auto/Set
/var/adm/perl-modules/%{name}
%changelog
+* Thu Nov 01 2007 - anicka@suse.cz
+- update to 1.22
+ * Add cartesian_product() and power_set(), both as full
+ constructors and as iterators.
+ * Add empty_clone().
+ * Makefile.PL not requiring Test::More since we are not using it.
+ * Made to work with the upcoming Perl 5.005_05
+ (yes, you read that right), most importantly
+ Scalar::Util made optional (we fall back to
+ pure Perl emulations for blessed() and refaddr()
+ if necessary). Everything else already worked.
* Mon Oct 08 2007 - anicka@suse.cz
- update to 1.21
* Made to work with the upcoming Perl 5.005_05, most importantly
++++++ Set-Scalar-1.21.tar.bz2 -> Set-Scalar-1.22.tar.bz2 ++++++
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/Set-Scalar-1.21/ChangeLog new/Set-Scalar-1.22/ChangeLog
--- old/Set-Scalar-1.21/ChangeLog 2007-10-05 05:12:09.000000000 +0200
+++ new/Set-Scalar-1.22/ChangeLog 2007-10-24 04:03:21.000000000 +0200
@@ -1,3 +1,14 @@
+2007-10-23 Jarkko Hietaniemi
+
+ * Add cartesian_product() and power_set(), both as full
+ constructors and as iterators.
+
+ * Add empty_clone().
+
+ * Makefile.PL not requiring Test::More since we are not using it.
+
+ * Released as 1.22.
+
2007-10-04 Jarkko Hietaniemi
* Made to work with the upcoming Perl 5.005_05
@@ -60,7 +71,7 @@
* Added is_empty() and empty() aliases for is_null()
and null(); from Peter Oliver.
- * In the display callack discussion show by example
+ * In the display callback discussion show by example
that one can use the same callback for several sets
(instead of generating a new anonymous subroutine each time),
and clarify the class versus object method wording.
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/Set-Scalar-1.21/lib/Set/Scalar/Base.pm new/Set-Scalar-1.22/lib/Set/Scalar/Base.pm
--- old/Set-Scalar-1.21/lib/Set/Scalar/Base.pm 2007-10-05 05:17:38.000000000 +0200
+++ new/Set-Scalar-1.22/lib/Set/Scalar/Base.pm 2007-10-24 04:01:31.000000000 +0200
@@ -17,7 +17,7 @@
import Scalar::Util qw(blessed refaddr);
} else {
# Use the pure Perl emulations (directly snagged from Scalar::Util).
- sub UNIVERSAL::a_sub_not_likely_to_be_here { ref($_[0]) }
+ eval 'sub UNIVERSAL::a_sub_not_likely_to_be_here { ref($_[0]) }';
*blessed = sub ($) {
local($@, $SIG{__DIE__}, $SIG{__WARN__});
length(ref($_[0]))
@@ -96,7 +96,7 @@
my $self = { };
- bless $self, $class;
+ bless $self, ref $class || $class;
$self->_new_hook( \@_ );
@@ -187,13 +187,19 @@
return $e;
}
-sub _clone {
+sub _empty_clone {
my $self = shift;
my $original = shift;
$self->{'universe'} = $original->{'universe'};
-
$self->{'null' } = $original->{'null' };
+}
+
+sub _clone {
+ my $self = shift;
+ my $original = shift;
+
+ $self->_empty_clone($original);
$self->_insert( $original->{'elements'} );
}
@@ -209,6 +215,15 @@
*copy = \&clone;
+sub empty_clone {
+ my $self = shift;
+ my $clone = (ref $self)->new;
+
+ $clone->_empty_clone( $self );
+
+ return $clone;
+}
+
sub clear {
my $self = shift;
@@ -464,6 +479,91 @@
return $this->_unique( @_ );
}
+sub _make_cartesian_product_iterator {
+ my @iter;
+ my @value;
+ for my $set (@_) {
+ return unless $set->isa('Set::Scalar');
+ my @member = $set->members;
+ my %member;
+ @member{@member} = @member;
+ push @iter, \%member;
+ push @value, scalar CORE::each(%{ $iter[-1] });
+ }
+ return sub {
+ return unless @iter;
+ my @now = @value;
+ my $ix;
+ for ($ix = $#iter; $ix >= 0; $ix--) {
+ my $next = CORE::each(%{ $iter[$ix] });
+ if (defined $next) {
+ $value[$ix] = $next;
+ last;
+ } else {
+ keys %{ $iter[$ix] }; # Reset the iterator.
+ $value[$ix] = CORE::each(%{ $iter[$ix] });
+ }
+ }
+ if ($ix < 0) {
+ @iter = (); # All done.
+ }
+ return @now;
+ };
+}
+
+sub cartesian_product_iterator {
+ shift unless ref $_[0];
+ return &_make_cartesian_product_iterator;
+}
+
+sub cartesian_product {
+ my $iterator = &cartesian_product_iterator;
+ return unless defined $iterator;
+ my $product = $_[0]->empty_clone;
+ while (my @member = $iterator->()) {
+ $product->insert(\@member);
+ }
+ return $product;
+}
+
+sub _make_power_set_iterator {
+ return unless $_[0]->isa('Set::Scalar');
+ my @member = $_[0]->members;
+ my @iter = (0) x @member;
+ return sub {
+ return unless @iter;
+ my $ix;
+ for ($ix = 0; $ix < @iter; $ix++) {
+ if ($iter[$ix]++ == 0) {
+ last;
+ } else {
+ $iter[$ix] = 0;
+ }
+ }
+ if ($ix == @iter) {
+ @iter = (); # All done.
+ }
+ return map { $member[$_] } grep { $iter[$_] } 0..$#iter;
+ };
+}
+
+sub power_set_iterator {
+ shift unless ref $_[0];
+ return &_make_power_set_iterator;
+}
+
+sub power_set {
+ my $iterator = &power_set_iterator;
+ return unless defined $iterator;
+ my $power = $_[0]->empty_clone;
+ my @member;
+ do {
+ @member = $iterator->();
+ $power->insert($_[0]->empty_clone->insert(@member));
+ } while (@member);
+ return $power;
+}
+
sub is_universal {
my $self = shift;
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/Set-Scalar-1.21/lib/Set/Scalar.pm new/Set-Scalar-1.22/lib/Set/Scalar.pm
--- old/Set-Scalar-1.21/lib/Set/Scalar.pm 2007-10-05 05:07:30.000000000 +0200
+++ new/Set-Scalar-1.22/lib/Set/Scalar.pm 2007-10-24 04:04:59.000000000 +0200
@@ -5,7 +5,7 @@
use vars qw($VERSION @ISA);
-$VERSION = '1.21';
+$VERSION = '1.22';
@ISA = qw(Set::Scalar::Real Set::Scalar::Null Set::Scalar::Base);
@@ -60,15 +60,16 @@
$s = Set::Scalar->new(@members);
$t = $s->clone;
- $t = $s->copy; # clone of clone
+ $t = $s->copy; # Clone of clone.
+ $t = $s->empty_clone; # Like clone() but with no members.
=head2 Modifying
$s->insert(@members);
$s->delete(@members);
- $s->invert(@members); # insert if hasn't, delete if has
+ $s->invert(@members); # Insert if hasn't, delete if has.
- $s->clear; # removes all the elements
+ $s->clear; # Removes all the elements.
Note that clear() only releases the memory used by the set to
be reused by Perl; it will not reduce the overall memory use.
@@ -87,25 +88,25 @@
=head2 Querying
@members = $s->members;
- @elements = $s->elements; # alias for members
+ @elements = $s->elements; # Alias for members.
- $size = $s->size; # the number of members
+ $size = $s->size; # The number of members.
- $s->has($m) # return true if has that member
- $s->contains($m) # alias for has
+ $s->has($m) # Return true if has that member.
+ $s->contains($m) # Alias for has().
if ($s->has($member)) { ... }
- $s->member($m) # returns the member if has that member
- $s->element($m) # alias for member
+ $s->member($m) # Returns the member if has that member.
+ $s->element($m) # Alias for member.
- $s->is_null # returns true if the set is empty
- $s->is_empty # alias for is_null
- $s->is_universal # returns true if the set is universal
-
- $s->null # the null set
- $s->empty # alias for null
- $s->universe # the universe of the set
+ $s->is_null # Returns true if the set is empty.
+ $s->is_empty # Alias for is_null.
+ $s->is_universal # Returns true if the set is universal.
+
+ $s->null # The null set.
+ $s->empty # Alias for null.
+ $s->universe # The universe of the set.
=head2 Deriving
@@ -118,12 +119,12 @@
These methods have operator overloads:
- $u = $s + $t; # union
- $i = $s * $t; # intersection
- $d = $s - $t; # difference
- $e = $s % $t; # symmetric_difference
- $v = $s / $t; # unique
- $c = -$s; # complement
+ $u = $s + $t; # union
+ $i = $s * $t; # intersection
+ $d = $s - $t; # difference
+ $e = $s % $t; # symmetric_difference
+ $v = $s / $t; # unique
+ $c = -$s; # complement
Both the C and C<unique> are symmetric on all
their arguments. For two sets they are identical but for more than
@@ -170,13 +171,13 @@
These methods have operator overloads:
- $eq = $s == $t; # is_equal
- $dj = $s != $t; # is_disjoint
+ $eq = $s == $t; # is_equal
+ $dj = $s != $t; # is_disjoint
# No operator overload for is_properly_intersecting.
- $ps = $s < $t; # is_proper_subset
- $pS = $s > $t; # is_proper_superset
- $is = $s <= $t; # is_subset
- $iS = $s >= $t; # is_superset
+ $ps = $s < $t; # is_proper_subset
+ $pS = $s > $t; # is_proper_superset
+ $is = $s <= $t; # is_subset
+ $iS = $s >= $t; # is_superset
$cmp = $s <=> $t;
@@ -216,11 +217,11 @@
When no more elements remain C<undef> is returned. Since you may one
day have elements named C<0> don't test just like this
- while (my $e = $s->each) { ... } # WRONG
+ while (my $e = $s->each) { ... } # WRONG!
but instead like this
- while (defined(my $e = $s->each)) { ... } # right
+ while (defined(my $e = $s->each)) { ... } # Right.
(An C<undef> as a set element doesn't really work, you get C<"">.)
@@ -242,6 +243,86 @@
=back
+=head2 Cartesian Product and Power Set
+
+=over 4
+
+=item *
+
+Cartesian product is a product of two or more sets. For two sets, it
+is the set consisting of B<ordered pairs> of members from each set.
+For example for the sets
+
+ (a b)
+ (c d e)
+
+The Cartesian product of the above is the set
+
+ ([a, c] [a, d] [a, e] [b, c] [b, d] [b, e])
+
+The [,] notation is for the ordered pairs, which sets are are not.
+This means two things: firstly, that [e, b] is B<not> in the above
+Cartesian product, and secondly, [b, b] is a possibility:
+
+ (a b)
+ (b c e)
+
+ ([a, b] [a, c] [a, e] [b, b] [b, c] [b, d])
+
+For example:
+
+ my $a = Set::Scalar->new(1..2);
+ my $b = Set::Scalar->new(3..5);
+ my $c = $a->cartesian_product($b); # As an object method.
+ my $d = Set::Scalar->cartesian_product($a, $b); # As a class method.
+
+The $c and $d will be of the same class as $a. The members of $c and
+$c in the above will be anonymous arrays (array references), not sets,
+since sets wouldn't be able to represent the ordering or that a member
+can be present more than once. Also note that since the members of
+the input sets are unordered, the ordered pairs themselves are
+unlikely to be in any particular order.
+
+If you don't want to construct the Cartesian product set, you can
+construct an iterator and call it while it returns more members:
+
+ my $iter = Set::Scalar->cartesian_product_iterator($a, $b, $c);
+ while (my @m = $iter->()) {
+ process(@m);
+ }
+
+=item *
+
+Power set is the set of all the subsets of a set. If the set has N
+members, its power set has 2**N members. For example for the set
+
+ (a b c)
+
+size 3, its power set is
+
+ (() (a) (b) (c) (a b) (a c) (b c) (a b c))
+
+size 8. Note that since the elements of the power set are sets, they
+are unordered, and therefore (b c) is equal to (c b). For example:
+
+ my $a = Set::Scalar->new(1..3);
+ my $b = $a->power_set; # As an object method.
+ my $c = Set::Scalar->power_set($a); # As a class method.
+
+Even the empty set has a power set, of size one.
+
+If you don't want to construct the power set, you can construct an
+iterator and call it until it returns no more members:
+
+ my $iter = Set::Scalar->power_set($a);
+ my @m;
+ do {
+ @m = $iter->();
+ process(@m);
+ } while (@m);
+
+=back
+
=head2 Customising Display
If you want to customise the display routine you will have to
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/Set-Scalar-1.21/Makefile.PL new/Set-Scalar-1.22/Makefile.PL
--- old/Set-Scalar-1.21/Makefile.PL 2007-10-05 05:05:57.000000000 +0200
+++ new/Set-Scalar-1.22/Makefile.PL 2007-10-24 02:56:05.000000000 +0200
@@ -11,20 +11,10 @@
PREREQ_PM =>
{
# 'Scalar::Util' => 0, # Not a requirement anymore.
- 'Test::More' => 0,
+ # 'Test::More' => 0,
},
)
and
print <<__EOF__;
Now issue 'make' and then 'make test', and if all looks good, 'make install'.
__EOF__
-eval 'use Test::More';
-if ($@) {
-print <<__EOF__;
-(Test::More not found means that you cannot run the tests, you can
-still go ahead and install without testing if you are feeling brave.)
-__EOF__
-}
-
-
-
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/Set-Scalar-1.21/MANIFEST new/Set-Scalar-1.22/MANIFEST
--- old/Set-Scalar-1.21/MANIFEST 2003-10-04 17:00:26.000000000 +0200
+++ new/Set-Scalar-1.22/MANIFEST 2007-10-24 03:32:10.000000000 +0200
@@ -13,6 +13,7 @@
t/basic.t
t/basic_overload.t
t/boolean.t
+t/cartesian.t
t/clear.t
t/compare.t
t/custom_display.t
@@ -24,6 +25,7 @@
t/member.t
t/misc.t
t/null.t
+t/power_set.t
t/set_set.t
t/symmdiff.t
t/union.t
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/Set-Scalar-1.21/META.yml new/Set-Scalar-1.22/META.yml
--- old/Set-Scalar-1.21/META.yml 2007-10-05 05:18:16.000000000 +0200
+++ new/Set-Scalar-1.22/META.yml 2007-10-24 04:05:06.000000000 +0200
@@ -1,11 +1,10 @@
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Set-Scalar
-version: 1.21
+version: 1.22
version_from: lib/Set/Scalar.pm
installdirs: site
requires:
- Test::More: 0
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.30
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/Set-Scalar-1.21/t/cartesian.t new/Set-Scalar-1.22/t/cartesian.t
--- old/Set-Scalar-1.21/t/cartesian.t 1970-01-01 01:00:00.000000000 +0100
+++ new/Set-Scalar-1.22/t/cartesian.t 2007-10-24 03:41:35.000000000 +0200
@@ -0,0 +1,65 @@
+use Set::Scalar;
+
+print "1..9\n";
+
+my $a = Set::Scalar->new(1..2);
+my $b = Set::Scalar->new(3..5);
+
+my $c = $a->cartesian_product($b);
+my $d = Set::Scalar->cartesian_product($a, $b);
+my $e = $a->cartesian_product($a);
+my $f = $a->cartesian_product();
+my $g = Set::Scalar->cartesian_product($a, $b, $b);
+my $h = Set::Scalar->cartesian_product($a, $c);
+
+print "not " unless $c->members == 6;
+print "ok 1\n";
+
+print "not " unless $d->members == 6;
+print "ok 2\n";
+
+print "not " unless $e->members == 4;
+print "ok 3\n";
+
+print "not " unless $f->members == 2;
+print "ok 4\n";
+
+sub verify {
+ my ($p, @q) = @_;
+ my @p = $p->members;
+ return unless @p == @q;
+ my %p; @p{ map { "@$_" } @p } = @p;
+ my %q; @q{ map { "@$_" } @q } = @q;
+ my %P = %p; delete @P{ keys %q };
+ my %Q = %q; delete @Q{ keys %p };
+ return keys %P == 0 && keys %Q == 0;
+}
+
+print "not " unless verify($c,
+ [1, 3], [1, 4], [1, 5],
+ [2, 3], [2, 4], [2, 5]);
+print "ok 5\n";
+
+print "not " unless verify($d,
+ [1, 3], [1, 4], [1, 5],
+ [2, 3], [2, 4], [2, 5]);
+print "ok 6\n";
+
+print "not " unless verify($e,
+ [1, 2], [1, 1],
+ [2, 1], [2, 2]);
+print "ok 7\n";
+
+print "not " unless verify($f,
+ [1], [2]);
+print "ok 8\n";
+
+print "not " unless verify($g,
+ [1, 3, 3], [1, 4, 3], [1, 5, 3],
+ [2, 3, 3], [2, 4, 3], [2, 5, 3],
+ [1, 3, 4], [1, 4, 4], [1, 5, 4],
+ [2, 3, 4], [2, 4, 4], [2, 5, 4],
+ [1, 3, 5], [1, 4, 5], [1, 5, 5],
+ [2, 3, 5], [2, 4, 5], [2, 5, 5]);
+print "ok 9\n";
+
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/Set-Scalar-1.21/t/clear.t new/Set-Scalar-1.22/t/clear.t
--- old/Set-Scalar-1.21/t/clear.t 2001-10-20 02:04:26.000000000 +0200
+++ new/Set-Scalar-1.22/t/clear.t 2007-10-24 02:53:46.000000000 +0200
@@ -1,6 +1,6 @@
use Set::Scalar;
-print "1..1\n";
+print "1..2\n";
my $s = Set::Scalar->new(0..99);
@@ -9,3 +9,6 @@
print "not " unless $s->is_null;
print "ok 1\n";
+print "not " unless $s->members == 0;
+print "ok 2\n";
+
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/Set-Scalar-1.21/t/laws.t new/Set-Scalar-1.22/t/laws.t
--- old/Set-Scalar-1.21/t/laws.t 2001-05-03 02:48:04.000000000 +0200
+++ new/Set-Scalar-1.22/t/laws.t 2007-10-24 03:53:38.000000000 +0200
@@ -4,7 +4,7 @@
$| = 1;
-print STDERR "(WARNING: this will take a while)...";
+print STDERR "(WARNING: this can take a while)...";
my $t = 1;
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/Set-Scalar-1.21/t/power_set.t new/Set-Scalar-1.22/t/power_set.t
--- old/Set-Scalar-1.21/t/power_set.t 1970-01-01 01:00:00.000000000 +0100
+++ new/Set-Scalar-1.22/t/power_set.t 2007-10-24 03:52:46.000000000 +0200
@@ -0,0 +1,53 @@
+use Set::Scalar;
+
+print "1..6\n";
+
+my $a = Set::Scalar->new(1..3);
+my $b = Set::Scalar->new();
+
+my $c = $a->power_set;
+my $d = Set::Scalar->power_set($a);
+my $e = $b->power_set;
+
+print "not " unless $c->members == 8;
+print "ok 1\n";
+
+print "not " unless $d->members == 8;
+print "ok 2\n";
+
+print "not " unless $e->members == 1;
+print "ok 3\n";
+
+sub verify {
+ my ($p, @q) = @_;
+ my @p = $p->members;
+ return unless @p == @q;
+ @q = map { Set::Scalar->new(@$_) } @q;
+ my %p; @p{ map { "$_" } @p } = @p;
+ my %q; @q{ map { "$_" } @q } = @q;
+ my %P = %p; delete @P{ keys %q };
+ my %Q = %q; delete @Q{ keys %p };
+ return keys %P == 0 && keys %Q == 0;
+}
+
+print "not " unless verify($c,
+ [],
+ [1], [2], [3],
+ [1, 2], [1, 3], [2, 3],
+ [1, 2, 3]);
+print "ok 4\n";
+
+print "not " unless verify($d,
+ [],
+ [1], [2], [3],
+ [1, 2], [1, 3], [2, 3],
+ [1, 2, 3]);
+print "ok 5\n";
+
+print "not " unless verify($e,
+ []);
+print "ok 6\n";
+
+
+
+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Remember to have fun...
---------------------------------------------------------------------
To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org
For additional commands, e-mail: opensuse-commit+help@opensuse.org