GAP (ToolsForHomalg) - Chapter 3: Caches

Goto Chapter: Top 1 2 3 4 5 6 7 8 9 Bib Ind
[Top of Book] [Contents] [Previous Chapter] [Next Chapter]

[MathJax on]

3 Caches
3.1 Object constructors
3.1-1 CachingObject
3.1-2 CachingObject
3.2 Setters, getters
3.2-1 CacheValue
3.2-2 SetCacheValue
3.2-3 IsEqualForCache
3.3 Managing functions
3.3-1 SetCachingObjectCrisp
3.3-2 SetCachingObjectWeak
3.3-3 DeactivateCachingObject
3.4 Install functions
3.4-1 InstallMethodWithCache
3.4-2 InstallMethodWithCrispCache
3.4-3 InstallMethodWithCacheFromObject
3.4-4 FunctionWithCache

### 3 Caches

#### 3.1 Object constructors

Caches are objects which store for a fixed number of keys a value, so they are a map Obj^k -> Obj, while the k is fixed. A cache ususally stores the result in a weak pointer list, which means that if the value which the cache should store is not referenced in the system anymore, it will not be remembered by the cache. However, caches can be set to store the value permanently (crisp), or not to store any new value at all (inaktive). In that case, already stored values are still in the cache and can be accessed once the cache is set active again.

##### 3.1-1 CachingObject

`‣ CachingObject`( [k, ][is_crisp] ) | ( operation )

`‣ CachingObject`( arg ) | ( operation )

`‣ CachingObject`( arg1, arg2 ) | ( operation )

Returns: a cache

If no argument is given, the function returns a weak cache with key length one, if an integer k is given, a weak cache with key length k, and if the bool is_crisp is true, a crisp cache with the corresponding length.

##### 3.1-2 CachingObject

`‣ CachingObject`( object, cache_name, length[, is_crisp] ) | ( operation )

`‣ CachingObject`( arg1, arg2, arg3, arg4 ) | ( operation )

This methods are not installed, they serve as an interface for InstallMethodWithCacheFromObject.

#### 3.2 Setters, getters

##### 3.2-1 CacheValue

`‣ CacheValue`( cache, key ) | ( operation )

Returns: stored value

If there is a value stored in the cache for key, which can be a single key for caches with key length one or a list of keys depending on the key length of the cache, this method returns a list only contraining the value, otherwise an empty list.

##### 3.2-2 SetCacheValue

`‣ SetCacheValue`( cache, key, value ) | ( operation )

Sets the value of key of the cache to value.

##### 3.2-3 IsEqualForCache

`‣ IsEqualForCache`( obj1, obj2 ) | ( operation )

Returns: true or false

This function is used to compare objects for the caches. The standard way is IsIdenticalObj, and lists are compared recursive with this function. It is possible and recommended to overload this function as needed.

#### 3.3 Managing functions

##### 3.3-1 SetCachingObjectCrisp

`‣ SetCachingObjectCrisp`( cache ) | ( function )

Returns: nothing

Sets the caching to crisp, weak, or deativates the cache completely.

##### 3.3-2 SetCachingObjectWeak

`‣ SetCachingObjectWeak`( arg ) | ( function )

##### 3.3-3 DeactivateCachingObject

`‣ DeactivateCachingObject`( arg ) | ( function )

#### 3.4 Install functions

##### 3.4-1 InstallMethodWithCache

`‣ InstallMethodWithCache`( Like, InstallMethod ) | ( function )

Installs a method like InstallMethod, but additionally puts a cache layer around it so that the result is cached. It is possible to give the cache as the option Cache, to use the same cache for more than one method or store it somewhere to have access to the cache.

##### 3.4-2 InstallMethodWithCrispCache

`‣ InstallMethodWithCrispCache`( arg ) | ( function )

Like InstallMethodWithCache, but with a crisp cache.

##### 3.4-3 InstallMethodWithCacheFromObject

`‣ InstallMethodWithCacheFromObject`( Like, InstallMethod ) | ( function )

This works just like InstallMethodWithCache, but it extracts the cache via the CachingObject method from one of its arguments. The CachingObject must then be implemented for one of the arguments, and the option ArgumentNumber can specify which option to be used. As second argument for CachingObject a string is used, which can identify the cache. Standard is the name of the operation, for which the method is installed, but it can be specified using the CacheName option.

##### 3.4-4 FunctionWithCache

`‣ FunctionWithCache`( func ) | ( function )

Returns: a function

Creates a cached function out of a given function func. If the option Cache is a cache, this cache is used. If the option Cache is the string crisp, a crisp cache is used. All other values for this option lead to a single weak cache.

[Top of Book] [Contents] [Previous Chapter] [Next Chapter]
Goto Chapter: Top 1 2 3 4 5 6 7 8 9 Bib Ind

generated by GAPDoc2HTML