Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Improve GAP's sort functions #609

Merged
merged 3 commits into from
Feb 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/basis.gd
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,6 @@ InstallGlobalFunction( "DeclareHandlingByNiceBasis", function( name, info )
od;
end );


#############################################################################
##
#F IsGenericFiniteSpace( <V> )
Expand Down Expand Up @@ -1187,4 +1186,3 @@ DeclareGlobalFunction( "BasisWithReplacedLeftModule" );
#############################################################################
##
#E

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