## ## Datastructures: GAP package providing common datastructures. ## ## Copyright (C) 2015-2017 The datastructures team. ## For list of the team members, please refer to the COPYRIGHT file. ## ## This package is licensed under the GPL 2 or later, please refer ## to the COPYRIGHT.md and LICENSE files for details. ##
## ## Memoisation with hash table ##
InstallGlobalFunction(MemoizeFunction, function ( func, extra... )
local cache, original, options, r;
options := rec( flush := true,
contract := ReturnTrue,
errorHandler := function(args...) return fail; end
); if Length( extra ) > 0then for r in RecNames( extra[1] ) do if IsBound( options.(r) ) then
options.(r) := extra[1].(r); else
ErrorNoReturn( "Invalid option: ", r ); fi;
od; fi;
cache := HashMap(); if options.flush then
InstallMethod( FlushCaches, [ ], function ( )
cache := HashMap();
TryNextMethod(); end ); fi;
return function ( args... )
local v; if not CallFuncList(options.contract, args) then
v := CallFuncListWrap(options.errorHandler, args); if v <> [] then
return v[1]; fi;
return; fi;
if args in cache then
v := cache[args]; else
v := CallFuncList(func, args);
cache[args] := v; fi;
return v; end; end);
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.