void BlockHashIndex::DropLastRange() { #ifdef WITH_THREADS boost::mutex::scoped_lock lock(m_mutex); #endif while(m_lastDropped != m_lastSaved) DropRange(++m_lastDropped); }
void BlockHashIndex::KeepNLastRanges(float ratio, float tolerance) { #ifdef WITH_THREADS boost::mutex::scoped_lock lock(m_mutex); #endif size_t n = m_hashes.size() * ratio; size_t max = n * (1 + tolerance); if(m_numLoadedRanges > max) { typedef std::vector<std::pair<clock_t, size_t> > LastLoaded; LastLoaded lastLoaded; for(size_t i = 0; i < m_hashes.size(); i++) if(m_hashes[i] != 0) lastLoaded.push_back(std::make_pair(m_clocks[i], i)); std::sort(lastLoaded.begin(), lastLoaded.end()); for(LastLoaded::reverse_iterator it = lastLoaded.rbegin() + size_t(n * (1 - tolerance)); it != lastLoaded.rend(); it++) DropRange(it->second); } }