For caching function evaluations.
This is based on the cache module from NumDiff.
It has been modified to cache integers (int64) instead of reals.
an [x,f(x)] cached pair. x is a vector and f is a vector.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=ip), | private, | dimension(:), allocatable | :: | x |
vector of input values |
||
| integer(kind=ip), | private, | dimension(:), allocatable | :: | f |
output functions |
a vector function cache.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| type(fx), | private, | dimension(:), allocatable | :: | c |
the cache of |
||
| integer, | private | :: | chunk_size | = | 100 |
for resizing vectors in the unique function |
| procedure, public :: initialize => initialize_cache | |
| procedure, public :: get => get_from_cache | |
| procedure, public :: put => put_in_cache | |
| procedure, public :: destroy => destroy_cache |
DJB hash algorithm for a integer(ip) vector.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=ip), | intent(in), | dimension(:) | :: | r |
the vector |
the hash value
Initialize the cache. Must be called first before use.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(function_cache), | intent(inout) | :: | me | |||
| integer, | intent(in) | :: | isize |
the size of the hash table |
||
| integer, | intent(in), | optional | :: | chunk_size |
chunk size to speed up reallocation
of arrays. A good value is a guess for
the actual number of elements of |
Check if the x vector is in the cache, if so return f.
Note that only some of the elements may be present, so it will return
the ones there are there, and indicate which ones were found.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(function_cache), | intent(inout) | :: | me | |||
| integer(kind=ip), | intent(in), | dimension(:) | :: | x |
independant variable vector |
|
| integer(kind=ip), | intent(out) | :: | i |
index in the hash table |
||
| integer(kind=ip), | intent(out), | dimension(:), allocatable | :: | f |
|
|
| logical, | intent(out) | :: | found |
if |
Put a value into the cache.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(function_cache), | intent(inout) | :: | me | |||
| integer(kind=ip), | intent(in) | :: | i |
index in the hash table |
||
| integer(kind=ip), | intent(in), | dimension(:) | :: | x |
independant variable vector |
|
| integer(kind=ip), | intent(in), | dimension(:) | :: | f |
function |
Destroy a cache.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(function_cache), | intent(out) | :: | me |