58template <
typename content>
76 content &
data() {
return _data; }
78 element &operator=(
const content &rhs)
85 element &operator=(content &&rhs)
95 content().swap(_data);
109 : _cache_size{ cache_size }, _noop{ cache_size == data_size }
111 if (_cache_size > data_size)
112 throw std::range_error(
"cache_size cannot exceet data_size");
114 _data.resize(data_size);
131 void prune(
size_t keep = 0) noexcept
136 remove_dublicate_indices();
138 _used_indices.size() - (keep > _cache_size ? keep : _cache_size);
143 auto begin = _used_indices.begin();
144 std::advance(begin, delta);
146 std::for_each(begin, _used_indices.end(),
147 [&](
size_t index) { _data[index].reset(); });
157 if (
size > _data.size())
158 throw std::range_error(
"cache_size cannot exceet data_size");
163 _noop = (_cache_size == _data.size());
167 size_t size()
const {
return _cache_size; };
172 remove_dublicate_indices();
173 return _used_indices.size();
179 remove_dublicate_indices();
180 return _used_indices;
184 bool noop()
const {
return _noop; }
189 auto size = _data.size();
190 std::vector<element>().swap(_data);
192 _used_indices.clear();
198 std::vector<element> _data;
199 std::list<size_t> _used_indices;
202 void add_index(
const size_t index) { _used_indices.push_front(index); }
204 void remove_dublicate_indices()
206 std::vector<bool> found(_data.size(),
false);
207 _used_indices.remove_if([&](
size_t index) {
A container to hold cache elements.
void reset()
resets the element to the empty state
A simple integer indexed elastically cached wrapper around std::vector to hold container types conten...
void prune(size_t keep=0) noexcept
Remove excess elements from the cache The capacity can be temporarily readjusted to keep.
TrixelCache(const size_t data_size, const size_t cache_size)
Constructs a cache with data_size default constructed elements with an elastic ceiling capacity of ca...
void set_size(const size_t size)
Reset the cache size to size.
element & operator[](const size_t index) noexcept
Retrieve an element at index.
void clear() noexcept
Clear the cache without changing it's size.
std::list< size_t > primed_indices()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:45 by
doxygen 1.12.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.