Skip to content

Commit

Permalink
lib: improve an AsList method for domains with ...
Browse files Browse the repository at this point in the history
... stored GeneratorsOfDomain.

The new version ensures that no copy of GeneratorsOfDomain is created if
GeneratorsOfDomain already is a duplicate free list.

Adds tests for this situation.
  • Loading branch information
ssiccha committed May 26, 2019
1 parent 4437e09 commit ea98daf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/domain.gi
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,18 @@ InstallImmediateMethod( Enumerator,
InstallMethod( AsList,
"for a domain with stored domain generators",
[ IsDomain and HasGeneratorsOfDomain ],
D -> DuplicateFreeList( GeneratorsOfDomain( D ) ) );
function( D )
if IsDuplicateFreeList( GeneratorsOfDomain( D ) ) then
return GeneratorsOfDomain( D );
else
return DuplicateFreeList( GeneratorsOfDomain( D ) );
fi;
end );

InstallMethod( Enumerator,
"for a domain with stored domain generators",
[ IsDomain and HasGeneratorsOfDomain ],
D -> DuplicateFreeList( GeneratorsOfDomain( D ) ) );
D -> AsList(D) );


#############################################################################
Expand Down
16 changes: 16 additions & 0 deletions tst/testinstall/domain.tst
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,21 @@ false
gap> M = J;
Error, no method found for comparing two infinite domains

# AsList and Enumerator for domains which know their GeneratorsOfDomain
gap> r := Immutable([1..3]);;
gap> d := Domain(r);;
gap> IsIdenticalObj(AsList(d), r);
true
gap> IsIdenticalObj(Enumerator(d), r);
true
gap> r := Immutable([1,2,3,1]);;
gap> d := Domain(r);;
gap> IsIdenticalObj(GeneratorsOfDomain(d), r);
true
gap> IsIdenticalObj(AsList(d), r);
false
gap> IsIdenticalObj(Enumerator(d), r);
false

#
gap> STOP_TEST("domain.tst");

0 comments on commit ea98daf

Please sign in to comment.