//keyを基に値の取得 DATA get(std::string key){ if (mCacheMap.count(key) == 1){ mutex.lock(); EntryPair value = *mCacheMap[key]; //現在の位置から削除し、最初の位置に変更 mCacheList.erase(mCacheMap[key]); mCacheList.push_front(value); //ポインタの位置を先頭に更新 mCacheMap[key] = mCacheList.begin(); mutex.unlock(); return value.second; } //キャッシュに求める値が入っていない場合 (エラーを投げる) else { throw "NOT IN YOUR CACHE"; //値を返すようにする場合はこちら //if (typeid(DATA) == typeid(cv::Mat)) //{ // cv::Mat mtx(cv::Size(100,100), CV_16U,cv::Scalar(0,0,0)); // return mtx; //} //if (typeid(DATA) == typeid(int)) //{ // return -1; //} } }
void addCache( unsigned int tid, CONTEXT* ctxt, int flags, void* v ) { if( tid >= caches.size() ) { caches.resize( tid + 1, nullptr ); } caches[tid] = new Cache( CACHE_SIZE, CACHE_LINE_SIZE, CACHE_ASSOCIATIVITY, &directorySet ); //cout << "Cache " << tid << " = " << hex << caches[tid] << endl; }
void Cache::add(const std::string& isp, int stamp, int num, const std::string& msg) { CacheList* list = NULL; std::map<std::string, CacheList*>::iterator it = m_mapCache.find(isp); if( it != m_mapCache.end() ) { list = it->second; list->add(stamp, num, msg); } else { list = new CacheList(); list->add(stamp, num, msg); m_mapCache[isp] = list; } }
bool GetLRUElement(CacheEntry& value, bool remove) { if (m_cache_list.empty()) { return false; } value = m_cache_list.back(); if (remove) { m_entry_map.erase(value.first); m_cache_list.pop_back(); } return true; }
bool Get(const key_type& key, value_type& value) { typename CacheEntryMap::iterator found = m_entry_map.find(key); if (found != m_entry_map.end()) { typename CacheList::iterator list_it = found->second; value = list_it->second; m_cache_list.erase(list_it); m_cache_list.push_front(std::make_pair(key, value)); m_entry_map[key] = m_cache_list.begin(); return true; } return false; }
bool GetLRUElement(value_type& value, bool remove) { if (m_cache_list.empty()) { return false; } CacheEntry & entry = m_cache_list.back(); value = entry.second; if (remove) { m_entry_map.erase(entry.first); m_cache_list.pop_back(); } return true; }
//キャッシュへの挿入 void insert(std::string key, DATA data){ mutex.lock(); //std::cout << "insert " << data << std::endl; //新データの場合(挿入しサイズをオーバーする場合は一番古いものを削除) if (mCacheMap.count(key) == 0) { //listの先頭にクエリ追加 mCacheList.push_front(std::make_pair(key, data)); //ポインタの位置を保持 mCacheMap[key] = mCacheList.begin(); entries++; if (entries > capacity) { //keyを基にlistの最後尾をさすポインタを消去 mCacheMap.erase(mCacheList.back().first); //キャッシュのLRU要素を削除 mCacheList.pop_back(); entries--; } } //既にあるデータの場合(位置を一番前にもってくるだけ) else { mCacheList.erase(mCacheMap[key]); mCacheList.push_front(std::make_pair(key, data)); //ポインタの位置を先頭に更新 mCacheMap[key] = mCacheList.begin(); } mutex.unlock(); }
bool Insert(const key_type& key, const value_type& value, value_type* erase_value) { typename CacheEntryMap::iterator found = m_entry_map.find(key); bool erased_old = false; if (found != m_entry_map.end()) { erased_old = true; if (NULL != erase_value) { (*erase_value) = (*found->second); } m_cache_list.erase(found->second); } m_cache_list.push_front(std::make_pair(key, value)); m_entry_map[key] = m_cache_list.begin(); if (m_entry_map.size() > m_max_size) { if (NULL != erase_value) { (*erase_value) = m_cache_list.back(); } m_entry_map.erase(m_cache_list.back().first); m_cache_list.pop_back(); erased_old = true; } return erased_old; }
bool Erase(const key_type& key, value_type& value) { typename CacheEntryMap::iterator found = m_entry_map.find(key); if (found != m_entry_map.end()) { typename CacheList::iterator list_it = found->second; value = list_it->second; m_cache_list.erase(list_it); m_entry_map.erase(found); return true; } return false; }
void Gpx::fileParserSucceeded(const CacheList &cacheList) { qDebug() << PLUGIN_NAME << __FUNCTION__ << cacheList.size(); m_cacheList = cacheList; emit notifyBusy(false); // request map to reload caches emit reload(); // check if parsing actually got us some results and only save // the file location then if(m_cacheList.size() > 0) { // save filename in settings QSettings settings; settings.beginGroup(PLUGIN_NAME); settings.setValue("File", m_fileName); settings.endGroup(); } else error(tr("File %1 does not contain any geocaches").arg(m_fileName)); }
void finish( int code, void* v ) { ofstream file( outputFile.Value().c_str() ); assert( file.good() ); file.precision(3); file << fixed; file << endl; file << setw(8) << "" << setw(10) << "Total Accesses" << setw(11) << "Hit Rate" << setw(12) << "Safe Rate" //<< setw(15) << "Multiline" << setw(13) << "Downgrades" << setw(13) << "RSC Flushes" << endl; unsigned long int totalAccesses = 0; unsigned long int totalHits = 0; unsigned long int totalSafe = 0; unsigned long int totalDowngrades = 0; unsigned long int totalRscFlushes = 0; map<uintptr_t, unsigned long int> totalDowngradeCount; uintptr_t totalTopAddr; unsigned long int totalTopCount = 0; for( unsigned int i = 0; i < caches.size(); ++i ) { file << "Cache " << i; const Cache& c = *caches[i]; totalAccesses += c.accesses(); totalHits += c.hitRate() * c.accesses(); totalSafe += c.safeRate() * c.accesses(); totalDowngrades += c.downgrades(); totalRscFlushes += c.rscFlushes(); file << setw(15) << c.accesses() << setw(10) << 100.0*c.hitRate() << "%" << setw(11) << 100.0*c.safeRate() << "%" //<< setw(15) << c.multilineAccesses() << setw(13) << c.downgrades() << setw(13) << c.rscFlushes() /*<< endl*/; // Print the most common downgrades from this cache const auto& dm = c.downgradeMap( 3 ); for( auto it = dm.rbegin(); it != dm.rend(); ++it ) { file << " (" << hex << it->second << " : " << fixed << (100.0*it->first/c.downgrades()) << "%)"; } // Add all downgrades into total const auto& dc = c.downgradeCount(); for( auto it = dc.begin(); it != dc.end(); ++it ) { auto curCount = totalDowngradeCount[it->first]; curCount += it->second; if( curCount > totalTopCount ) { totalTopAddr = it->first; totalTopCount = curCount; } totalDowngradeCount[it->first] = curCount; } file << dec << endl; delete caches[i]; } caches.clear(); file << "Totals "; file << setw(15) << totalAccesses << setw(10) << 100.0*totalHits/totalAccesses << "%" << setw(11) << 100.0*totalSafe/totalAccesses << "%" << setw(13) << totalDowngrades << setw(13) << totalRscFlushes; file << " (" << hex << totalTopAddr << " : " << fixed << (100.0*totalTopCount/totalDowngrades) << "%)"; file << dec << endl << endl; directorySet.printStats( file ); file.close(); }
void Clear() { m_cache_list.clear(); m_entry_map.clear(); }
~LRUCache(){ mCacheList.clear(); mCacheMap.clear(); }