Krita Source Code Documentation
Loading...
Searching...
No Matches
KisRotatingCache.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef KISROTATINGCACHE_H
8#define KISROTATINGCACHE_H
9
10#include <optional>
11#include <utility>
12
13#include <boost/container/static_vector.hpp>
14
15
18template <typename Key, typename Value, size_t CacheSize>
20{
21public:
22 using CacheItem = std::pair<Key, Value>;
23public:
24 void push(Key key, Value value) {
25 if (m_storage.size() == m_storage.max_size()) {
26 m_storage.erase(m_storage.begin());
27 }
28 m_storage.emplace_back(std::move(key), std::move(value));
29 }
30
31 inline std::optional<Value> find(const Key &key) const {
32 for (auto it = m_storage.begin(); it != m_storage.end(); ++it) {
33 if (it->first == key) {
34 return it->second;
35 }
36 }
37 return std::nullopt;
38 }
39
40 void clear() {
41 m_storage.clear();
42 }
43
44private:
45 boost::container::static_vector<CacheItem, CacheSize> m_storage;
46};
47
48#endif // KISROTATINGCACHE_H
float value(const T *src, size_t ch)
void push(Key key, Value value)
std::optional< Value > find(const Key &key) const
boost::container::static_vector< CacheItem, CacheSize > m_storage
std::pair< Key, Value > CacheItem