Skip to content

Commit

Permalink
Fix ShallowCopy for IteratorOfCartesianProduct
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Sep 19, 2018
1 parent 94ead70 commit a10763a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/combinat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ BindGlobal( "NextIterator_Cartesian",

BindGlobal( "ShallowCopy_Cartesian",
iter -> rec(
sets := iter!.sets,
sizes := iter!.sizes,
n := iter!.n,
next := ShallowCopy( iter!.next ) ) );
Expand All @@ -820,9 +821,8 @@ BindGlobal( "IteratorOfCartesianProduct2",
NextIterator := NextIterator_Cartesian,
ShallowCopy := ShallowCopy_Cartesian,
sets := s, # list of sets
sizes := List( s, Size ), # sizes of sets
sizes := MakeImmutable( List( s, Size ) ),
n := n, # number of sets
nextelts := List( s, x -> x[1] ), # list of 1st elements
next := 0 * [ 1 .. n ] + 1 ) ); # list of 1's
end);

Expand Down
20 changes: 20 additions & 0 deletions tst/testinstall/combinat.tst
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,26 @@ gap> Print(List( [0..3], k -> NrTuples( [1..3], k ) ),"\n");
gap> NrTuples( [1..8], 4 );
4096

#
# IteratorOfCartesianProduct
#

# empty cartesian product
gap> it:=IteratorOfCartesianProduct([[1,2],[]]);;
gap> IsDoneIterator(it);
true
gap> List(it);
[ ]

# non-empty cartesian product
gap> it:=IteratorOfCartesianProduct([1,2], [3,4]);;
gap> IsDoneIterator(it);
false
gap> List(it);
[ [ 1, 3 ], [ 1, 4 ], [ 2, 3 ], [ 2, 4 ] ]
gap> List(it); # do it again, to verify the original iterator was not modified
[ [ 1, 3 ], [ 1, 4 ], [ 2, 3 ], [ 2, 4 ] ]

#F PermutationsList( <mset> ) . . . . . . set of permutations of a multiset
gap> PermutationsList( [] );
[ [ ] ]
Expand Down

0 comments on commit a10763a

Please sign in to comment.