Skip to content

Commit

Permalink
Speed up orbit computations on integer sets and tuples by providing a…
Browse files Browse the repository at this point in the history
… better hash function for lists of small integers (gap-system#5783)
  • Loading branch information
reiniscirpons authored Aug 31, 2024
1 parent 2b475a8 commit 5c88406
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/dicthf.gi
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,20 @@ end);
##
InstallMethod(SparseIntKey,"for bounded tuples",true,
[ IsList,IsList and IsCyclotomicCollection ], 0,
function(m,v)
local c;
if Length(m)<>3 or m[1]<>"BoundedTuples" then
function(m, v)
if Length(m) <> 3 or m[1] <> "BoundedTuples" then
TryNextMethod();
fi;
c:=[1,Maximum(m[2])+1];
return function(a)
return a*c;
# Due to the way BoundedTuples are presently implemented we expect the input
# to the hash function to always be a list of positive immediate integers. This means
# that using HashKeyWholeBag should be safe.
return function(x)
Assert(1, IsPositionsList(x));
if not IsPlistRep(x) then
x := AsPlist(x);
fi;
return HashKeyWholeBag(x, 1);
end;

end);

BindGlobal( "SparseIntKeyVecListAndMatrix", function(d,m)
Expand Down
4 changes: 4 additions & 0 deletions tst/teststandard/hash2.tst
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ gap> Length(Orbit(h,h.1[1],OnRight));
2079
gap> Length(Orbit(h,h.2^5,OnPoints));
693
gap> Length(Orbit(SymmetricGroup(14), [1 .. 7], OnSets));
3432
gap> Length(Orbit(SymmetricGroup(16), [1 .. 8], OnSets));
12870
gap> STOP_TEST( "hash2.tst", 1);

0 comments on commit 5c88406

Please sign in to comment.