diff options
author | Cedric Nugteren <web@cedricnugteren.nl> | 2017-02-26 14:51:45 +0100 |
---|---|---|
committer | Cedric Nugteren <web@cedricnugteren.nl> | 2017-02-26 14:51:45 +0100 |
commit | ea6790665d228e9ff9ba39983a60cd91611ee1fe (patch) | |
tree | 043ca277a867507f97f804cc4057fe50e548b9b1 /src/cache.cpp | |
parent | a145890aaac0087d36b414bd59c247ae4b70b3e5 (diff) | |
parent | 0643a29af51f9eb13e2b276d0a0e74590c699d3b (diff) |
Merge branch 'development' into triangular_solvers
Diffstat (limited to 'src/cache.cpp')
-rw-r--r-- | src/cache.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/cache.cpp b/src/cache.cpp index c5cc6a4d..4b74b0a1 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -65,6 +65,37 @@ void Cache<Key, Value>::Store(Key &&key, Value &&value) { } template <typename Key, typename Value> +void Cache<Key, Value>::Remove(const Key &key) { + std::lock_guard<std::mutex> lock(cache_mutex_); +#if __cplusplus >= 201402L + cache_.erase(key); +#else + auto it = cache_.begin(); + while (it != cache_.end()) { + if ((*it).first == key) { + it = cache_.erase(it); + } + else ++it; + } +#endif +} + +template <typename Key, typename Value> +template <int I1, int I2> +void Cache<Key, Value>::RemoveBySubset(const Key &key) { + std::lock_guard<std::mutex> lock(cache_mutex_); + auto it = cache_.begin(); + while (it != cache_.end()) { + const auto current_key = (*it).first; + if ((std::get<I1>(key) == std::get<I1>(current_key)) && + (std::get<I2>(key) == std::get<I2>(current_key))) { + it = cache_.erase(it); + } + else ++it; + } +} + +template <typename Key, typename Value> void Cache<Key, Value>::Invalidate() { std::lock_guard<std::mutex> lock(cache_mutex_); @@ -88,6 +119,7 @@ template std::string BinaryCache::Get(const BinaryKeyRef &, bool *) const; template class Cache<ProgramKey, Program>; template Program ProgramCache::Get(const ProgramKeyRef &, bool *) const; +template void ProgramCache::RemoveBySubset<1, 2>(const ProgramKey &); // precision and routine name // ================================================================================================= |