Skip to content

Commit

Permalink
Add cache to MakeIsPlistVectorRep
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jan 20, 2023
1 parent c0f63b1 commit d5d4390
Showing 1 changed file with 49 additions and 17 deletions.
66 changes: 49 additions & 17 deletions lib/matobjplist.gi
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,59 @@
# Constructors:
############################################################################

# TODO: experiment with making `MakeIsPlistVectorRep` an operation???
BindGlobal( "MakeIsPlistVectorRep",
function(basedomain, mutable, list )
local filter, typ;
# TODO: cache filter and type in the family obj;
# we need variants for mutable vs. immutable, and also for
# CanEasilyCompareElements true/false; we might reduce this
# by using CanEasilyCompareElementsFamily
filter := IsPlistVectorRep;
if mutable then
filter := filter and IsMutable;
fi;
if HasCanEasilyCompareElements(Representative(basedomain)) and
CanEasilyCompareElements(Representative(basedomain)) then
filter := filter and CanEasilyCompareElements;
local fam, types, typ;
fam := FamilyObj(basedomain);

# special case: integers
if IsIntegers(basedomain) then
if not IsBound(basedomain!.PlistVectorRepTypes) then
# initialize type cache
# TODO: make this thread safe for HPC-GAP
basedomain!.PlistVectorRepTypes := [
NewType(fam, IsPlistVectorRep and IsIntVector and CanEasilyCompareElements),
NewType(fam, IsPlistVectorRep and IsIntVector and CanEasilyCompareElements and IsMutable),
];
fi;
types := basedomain!.PlistVectorRepTypes;
elif IsFFECollection(basedomain) then
if not IsBound(basedomain!.PlistVectorRepTypes) then
# initialize type cache
# TODO: make this thread safe for HPC-GAP
basedomain!.PlistVectorRepTypes := [
NewType(fam, IsPlistVectorRep and IsFFEVector and CanEasilyCompareElements),
NewType(fam, IsPlistVectorRep and IsFFEVector and CanEasilyCompareElements and IsMutable),
];
fi;
types := basedomain!.PlistVectorRepTypes;
else
if not IsBound(fam!.PlistVectorRepTypes) then
# initialize type cache
# TODO: make this thread safe for HPC-GAP
fam!.PlistVectorRepTypes := [
NewType(fam, IsPlistVectorRep),
NewType(fam, IsPlistVectorRep and IsMutable),
];
fam!.PlistVectorRepTypesEasyCompare := [
NewType(fam, IsPlistVectorRep and CanEasilyCompareElements),
NewType(fam, IsPlistVectorRep and CanEasilyCompareElements and IsMutable),
];
fi;
if HasCanEasilyCompareElements(Representative(basedomain)) and
CanEasilyCompareElements(Representative(basedomain)) then
types := fam!.PlistVectorRepTypesEasyCompare;
else
types := fam!.PlistVectorRepTypes;
fi;
fi;
if IsIdenticalObj(basedomain, Integers) then
filter := filter and IsIntVector;
elif IsFinite(basedomain) and IsField(basedomain) then
filter := filter and IsFFEVector;
if mutable then
typ := types[2];
else
typ := types[1];
fi;
typ := NewType(FamilyObj(basedomain), filter);

return Objectify(typ, [ basedomain, list ]);
end );

Expand Down

0 comments on commit d5d4390

Please sign in to comment.