// // QCDLoop 2016 // // Authors: Stefano Carrazza: stefano.carrazza@cern.ch // Keith Ellis: keith.ellis@durham.ac.uk // Giulia Zanderighi: giulia.zanderighi@cern.ch #include "qcdloop/cache.h" namespace std { template inline void hash_combine(std::size_t & seed, const T & v) { hash hasher; seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } template <> struct hash : public __hash_base { inline size_t operator()(const ql::qdouble & x) const noexcept { return x != 0.0q ? std::_Hash_impl::hash(x) : 0; } }; template <> struct hash : public __hash_base { inline size_t operator()(const ql::complex & x) const noexcept { return x != ql::complex{0.0,0.0} ? std::_Hash_impl::hash(x) : 0; } }; template <> struct hash : public __hash_base { inline size_t operator()(const ql::qcomplex & x) const noexcept { return x != ql::qcomplex{0.0q,0.0q} ? std::_Hash_impl::hash(x) : 0; } }; } namespace ql { template ContainerHasher::ContainerHasher() { } template size_t ContainerHasher::genkey(TScale const& mu2, vector const& m, vector const& p) const { size_t seed = 0; std::hash_combine(seed, mu2); for (typename std::vector::const_iterator it = m.begin(), end = m.end(); it != end; ++it) std::hash_combine(seed, *it); for (typename std::vector::const_iterator it = p.begin(), end = p.end(); it != end; ++it) std::hash_combine(seed, *it); return seed; } // explicity template declaration template class ContainerHasher; template class ContainerHasher; template class ContainerHasher; template class ContainerHasher; /*! * The LRU Cache constructor */ template LRUCache::LRUCache(int const& size): _size(size) { } template LRUCache::LRUCache(const LRUCache &obj): _size(obj._size), _cache_list(obj._cache_list), _cache_map(obj._cache_map) { } template LRUCache::~LRUCache() { _cache_list.clear(); _cache_map.clear(); } template void LRUCache::setCacheSize(int const& size) { _size = size; _cache_list.clear(); _cache_map.clear(); } template void LRUCache::store(Tkey const& key, Tvalue const& value) { auto it = _cache_map.find(key); if (it != _cache_map.end()) { _cache_list.erase(it->second); _cache_map.erase(it); } _cache_list.push_front(key_value_pair_t(key, value)); _cache_map[key] = _cache_list.begin(); if ((int)_cache_map.size() > _size) { auto last = _cache_list.end(); last--; _cache_map.erase(last->first); _cache_list.pop_back(); } } template bool LRUCache::get(Tkey const& key, Tvalue & out) { auto it = _cache_map.find(key); if (it == _cache_map.end()) { return false; } else { _cache_list.splice(_cache_list.begin(), _cache_list, it->second); out = it->second->second; return true; } } // explicity template declaration template class LRUCache >; template class LRUCache >; }