1#ifndef TATAMI_CHUNKED_LRU_SLAB_CACHE_HPP
2#define TATAMI_CHUNKED_LRU_SLAB_CACHE_HPP
4#include <unordered_map>
25template<
typename Id_,
class Slab_>
28 typedef std::pair<Slab_, Id_> Element;
29 std::list<Element> my_cache_data;
30 std::unordered_map<Id_, typename std::list<Element>::iterator> my_cache_exists;
85 template<
class Cfunction_,
class Pfunction_>
87 if (
id == my_last_id && my_last_slab) {
92 auto it = my_cache_exists.find(
id);
93 if (
it != my_cache_exists.end()) {
95 my_cache_data.splice(my_cache_data.end(), my_cache_data,
chosen);
96 my_last_slab = &(
chosen->first);
100 typename std::list<Element>::iterator
location;
101 if (my_cache_data.size() < my_max_slabs) {
102 my_cache_data.emplace_back(create(),
id);
103 location = std::prev(my_cache_data.end());
106 my_cache_exists.erase(
location->second);
108 my_cache_data.splice(my_cache_data.end(), my_cache_data,
location);
114 my_last_slab = &
slab;
130 return my_cache_data.size();
Least-recently-used cache for slabs.
Definition LruSlabCache.hpp:26
const Slab_ & find(Id_ id, Cfunction_ create, Pfunction_ populate)
Definition LruSlabCache.hpp:86
LruSlabCache(const LruSlabCache &)=delete
LruSlabCache & operator=(const LruSlabCache &)=delete
size_t get_num_slabs() const
Definition LruSlabCache.hpp:129
LruSlabCache(size_t max_slabs)
Definition LruSlabCache.hpp:39
size_t get_max_slabs() const
Definition LruSlabCache.hpp:122
Methods to handle chunked tatami matrices.
Definition ChunkDimensionStats.hpp:4
Statistics for regular chunks along a dimension.
Definition ChunkDimensionStats.hpp:35