Skip to content

Commit

Permalink
Speed up converting permutations to strings
Browse files Browse the repository at this point in the history
Remove old O(n^2) algorithm with O(n) algorithm
  • Loading branch information
ChrisJefferson authored and fingolfin committed Nov 14, 2019
1 parent 264dc17 commit 1fd0e1a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/permutat.g
Original file line number Diff line number Diff line change
Expand Up @@ -735,20 +735,22 @@ end );
#m String( <perm> ) . . . . . . . . . . . . . . . . . . . for a permutation
##
BIND_GLOBAL("DoStringPerm",function( perm,hint )
local str, i, j;
local str, i, j, maxpnt, blist;

if IsOne( perm ) then
str := "()";
else
str := "";
maxpnt := LargestMovedPoint( perm );
blist := BlistList([1..maxpnt], []);
for i in [ 1 .. LargestMovedPoint( perm ) ] do
j := i ^ perm;
while j > i do j := j ^ perm; od;
if j = i and i ^ perm <> i then
if not blist[i] and i ^ perm <> i then
blist[i] := true;
Append( str, "(" );
Append( str, String( i ) );
j := i ^ perm;
while j > i do
blist[j] := true;
Append( str, "," );
if hint then Append(str,"\<\>"); fi;
Append( str, String( j ) );
Expand Down

0 comments on commit 1fd0e1a

Please sign in to comment.