tatami_chunked
Helpers to create custom chunked tatami matrices
Loading...
Searching...
No Matches
Public Member Functions | List of all members
tatami_chunked::LruSlabCache< Id_, Slab_ > Class Template Reference

Least-recently-used cache for slabs. More...

#include <LruSlabCache.hpp>

Public Member Functions

 LruSlabCache (size_t max_slabs)
 
 LruSlabCache (const LruSlabCache &)=delete
 
LruSlabCacheoperator= (const LruSlabCache &)=delete
 
template<class Cfunction_ , class Pfunction_ >
const Slab_find (Id_ id, Cfunction_ create, Pfunction_ populate)
 
size_t get_max_slabs () const
 
size_t get_num_slabs () const
 

Detailed Description

template<typename Id_, class Slab_>
class tatami_chunked::LruSlabCache< Id_, Slab_ >

Least-recently-used cache for slabs.

Template Parameters
Id_Type of cache identifier, typically integer.
Slab_Class for a single slab.

Implements a least-recently-used (LRU) cache, typically containing one or more "slabs" from a chunked matrix representation. Each slab is defined as the set of chunks required to read an element of the target dimension (or a contiguous block/indexed subset thereof) from a tatami::Matrix. The LRU cache can be used for chunked tatami::Matrix representations where the data is costly to load (e.g., from file) and no oracle is provided to predict future accesses on the target dimension. In such cases, chunks of data can be loaded and cached such that any possible future request for an already-loaded slab will just fetch it from cache.

Constructor & Destructor Documentation

◆ LruSlabCache() [1/2]

template<typename Id_ , class Slab_ >
tatami_chunked::LruSlabCache< Id_, Slab_ >::LruSlabCache ( size_t  max_slabs)
inline
Parameters
max_slabsMaximum number of slabs to store in the cache.

◆ LruSlabCache() [2/2]

template<typename Id_ , class Slab_ >
tatami_chunked::LruSlabCache< Id_, Slab_ >::LruSlabCache ( const LruSlabCache< Id_, Slab_ > &  )
delete

Deleted as the cache holds persistent iterators.

Member Function Documentation

◆ operator=()

Deleted as the cache holds persistent iterators.

◆ find()

template<typename Id_ , class Slab_ >
const Slab_ & tatami_chunked::LruSlabCache< Id_, Slab_ >::find ( Id_  id,
Cfunction_  create,
Pfunction_  populate 
)
inline

This method should only be called if m > 0 in the constructor.

Template Parameters
Cfunction_Function to create a new Slab_ object.
Pfunction_Function to populate a Slab_ object with the contents of a slab.
Parameters
idIdentifier for the cached slab. This is typically defined as the index of the slab on the target dimension. For example, if each chunk takes up 10 rows, attempting to access row 21 would require retrieval of slab 2.
createFunction that accepts no arguments and returns a Slab_ object.
populateFunction that accepts a slab ID and a reference to a Slab_ object, and populates the latter with the contents of the former.
Returns
Reference to a slab. If the slab already exists in the cache, it is returned directly. If the slab does not exist and there is still space in the cache, a new slab is created and populated with the contents of slab id. If the slab does not exist and there is no space in the cache, the least recently used slab is evicted and its Slab_ is populated with the contents of slab id.

◆ get_max_slabs()

template<typename Id_ , class Slab_ >
size_t tatami_chunked::LruSlabCache< Id_, Slab_ >::get_max_slabs ( ) const
inline
Returns
Maximum number of slabs in the cache.

◆ get_num_slabs()

template<typename Id_ , class Slab_ >
size_t tatami_chunked::LruSlabCache< Id_, Slab_ >::get_num_slabs ( ) const
inline
Returns
Number of slabs currently in the cache.

The documentation for this class was generated from the following file: