File indexing completed on 2024-04-21 03:43:59
0001 /* 0002 SPDX-FileCopyrightText: 2015-2017 Pavel Mraz 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "pixcache.h" 0008 0009 static int qHash(const pixCacheKey_t &key, uint seed) 0010 { 0011 return qHash(QString("%1_%2_%3").arg(key.level).arg(key.pix).arg(key.uid), seed); 0012 } 0013 0014 inline bool operator<(const pixCacheKey_t &k1, const pixCacheKey_t &k2) 0015 { 0016 if (k1.uid != k2.uid) 0017 { 0018 return k1.uid < k2.uid; 0019 } 0020 0021 if (k1.level != k2.level) 0022 { 0023 return k1.level < k2.level; 0024 } 0025 0026 return k1.pix < k2.pix; 0027 } 0028 0029 inline bool operator==(const pixCacheKey_t &k1, const pixCacheKey_t &k2) 0030 { 0031 return (k1.uid == k2.uid) && (k1.level == k2.level) && (k1.pix == k2.pix); 0032 } 0033 0034 void PixCache::add(pixCacheKey_t &key, pixCacheItem_t *item, int cost) 0035 { 0036 Q_ASSERT(cost < m_cache.maxCost()); 0037 0038 m_cache.insert(key, item, cost); 0039 } 0040 0041 pixCacheItem_t *PixCache::get(pixCacheKey_t &key) 0042 { 0043 return m_cache.object(key); 0044 } 0045 0046 void PixCache::setMaxCost(int maxCost) 0047 { 0048 m_cache.setMaxCost(maxCost); 0049 } 0050 0051 void PixCache::printCache() 0052 { 0053 qDebug() << Q_FUNC_INFO << " -- cache ---------------"; 0054 qDebug() << Q_FUNC_INFO << m_cache.size() << m_cache.totalCost() << m_cache.maxCost(); 0055 } 0056 0057 int PixCache::used() 0058 { 0059 return m_cache.totalCost(); 0060 }