Skip to content

Commit

Permalink
Code reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Feb 18, 2016
1 parent 25cfbbe commit 1d34563
Show file tree
Hide file tree
Showing 6 changed files with 709 additions and 268 deletions.
10 changes: 9 additions & 1 deletion lib/list.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,10 @@ DeclareOperation( "Sort", [ IsList and IsMutable ] );
DeclareOperation( "Sort", [ IsList and IsMutable, IsFunction ] );
DeclareOperation( "SortBy", [IsList and IsMutable, IsFunction ] );

DeclareOperation( "StableSort", [ IsList and IsMutable ] );
DeclareOperation( "StableSort", [ IsList and IsMutable, IsFunction ] );
DeclareOperation( "StableSortBy", [IsList and IsMutable, IsFunction ] );


#############################################################################
##
Expand Down Expand Up @@ -1663,6 +1667,11 @@ DeclareOperation( "SortParallel",
DeclareOperation( "SortParallel",
[ IsDenseList and IsMutable, IsDenseList and IsMutable, IsFunction ] );

DeclareOperation( "StableSortParallel",
[ IsDenseList and IsMutable, IsDenseList and IsMutable ] );
DeclareOperation( "StableSortParallel",
[ IsDenseList and IsMutable, IsDenseList and IsMutable, IsFunction ] );


#############################################################################
##
Expand Down Expand Up @@ -2310,4 +2319,3 @@ DeclareGlobalFunction("Median");
#############################################################################
##
#E

85 changes: 81 additions & 4 deletions lib/list.gi
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,11 @@ InstallMethod( Sort,
[ IsList and IsMutable and IsSmallList ],
SORT_LIST );

InstallMethod( StableSort,
"for a mutable small list",
[ IsList and IsMutable and IsSmallList ],
STABLE_SORT_LIST );

InstallMethod( Sort,
"for a mutable list",
[ IsList and IsMutable ],
Expand All @@ -2112,16 +2117,37 @@ InstallMethod( Sort,
fi;
end );

InstallMethod( StableSort,
"for a mutable list",
[ IsList and IsMutable ],
function( list )
if IsSmallList( list ) then
STABLE_SORT_LIST( list );
else
TryNextMethod();
fi;
end );

InstallMethod( Sort,
"for a mutable set",
[ IsList and IsMutable and IsSortedList ], SUM_FLAGS,
Ignore );

InstallMethod( StableSort,
"for a mutable set",
[ IsList and IsMutable and IsSortedList ], SUM_FLAGS,
Ignore );

InstallMethod( Sort,
"for a mutable small list and a function",
[ IsList and IsMutable and IsSmallList, IsFunction ],
SORT_LIST_COMP );

InstallMethod( StableSort,
"for a mutable small list and a function",
[ IsList and IsMutable and IsSmallList, IsFunction ],
STABLE_SORT_LIST_COMP );

InstallMethod( Sort,
"for a mutable list and a function",
[ IsList and IsMutable, IsFunction ],
Expand All @@ -2133,6 +2159,17 @@ InstallMethod( Sort,
fi;
end );

InstallMethod( StableSort,
"for a mutable list and a function",
[ IsList and IsMutable, IsFunction ],
function( list, func )
if IsSmallList( list ) then
STABLE_SORT_LIST_COMP( list, func );
else
TryNextMethod();
fi;
end );

#############################################################################
##
#M SortBy( <list>, <func> )
Expand All @@ -2147,7 +2184,14 @@ InstallMethod( SortBy, "for a mutable list and a function",
return;
end);


InstallMethod( StableSortBy, "for a mutable list and a function",
[IsList and IsMutable, IsFunction ],
function(list, func)
local images;
images := List(list, func);
StableSortParallel(images, list);
return;
end);

#############################################################################
##
Expand Down Expand Up @@ -2175,11 +2219,20 @@ InstallOtherMethod( Sort,
[ IsList ],
SORT_MUTABILITY_ERROR_HANDLER );

InstallOtherMethod( StableSort,
"for an immutable list",
[ IsList ],
SORT_MUTABILITY_ERROR_HANDLER );

InstallOtherMethod( Sort,
"for an immutable list and a function",
[ IsList, IsFunction ],
SORT_MUTABILITY_ERROR_HANDLER );

InstallOtherMethod( StableSort,
"for an immutable list and a function",
[ IsList, IsFunction ],
SORT_MUTABILITY_ERROR_HANDLER );

#############################################################################
##
Expand Down Expand Up @@ -2320,7 +2373,12 @@ InstallMethod( SortParallel,
IsDenseList and IsMutable ],
SORT_PARA_LIST );


InstallMethod( StableSortParallel,
"for two dense and mutable lists",
[ IsDenseList and IsMutable,
IsDenseList and IsMutable ],
STABLE_SORT_PARA_LIST );

#############################################################################
##
#M SortParallel( <sorted>, <list> )
Expand All @@ -2332,6 +2390,12 @@ InstallMethod( SortParallel,
SUM_FLAGS,
Ignore );

InstallMethod( StableSortParallel,
"for a mutable set and a dense mutable list",
[ IsDenseList and IsSortedList and IsMutable,
IsDenseList and IsMutable ],
SUM_FLAGS,
Ignore );

#############################################################################
##
Expand All @@ -2344,17 +2408,32 @@ InstallMethod( SortParallel,
IsFunction ],
SORT_PARA_LIST_COMP );

InstallMethod( StableSortParallel,
"for two dense and mutable lists, and function",
[ IsDenseList and IsMutable,
IsDenseList and IsMutable,
IsFunction ],
STABLE_SORT_PARA_LIST_COMP );

InstallOtherMethod( SortParallel,
"for two immutable lists",
[IsList,IsList],
SORT_MUTABILITY_ERROR_HANDLER);

InstallOtherMethod( StableSortParallel,
"for two immutable lists",
[IsList,IsList],
SORT_MUTABILITY_ERROR_HANDLER);

InstallOtherMethod( SortParallel,
"for two immutable lists and function",
[IsList,IsList,IsFunction],
SORT_MUTABILITY_ERROR_HANDLER);

InstallOtherMethod( StableSortParallel,
"for two immutable lists and function",
[IsList,IsList,IsFunction],
SORT_MUTABILITY_ERROR_HANDLER);

#############################################################################
##
Expand Down Expand Up @@ -3904,5 +3983,3 @@ end);
#############################################################################
##
#E


Loading

0 comments on commit 1d34563

Please sign in to comment.