Skip to content

Instantly share code, notes, and snippets.

@cwillu
Created March 3, 2016 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwillu/e44dd0699ed3b9810d5a to your computer and use it in GitHub Desktop.
Save cwillu/e44dd0699ed3b9810d5a to your computer and use it in GitHub Desktop.
void
Drawing::_pickItemsForCaching()
{
// we cache the objects with the highest score until the budget is exhausted
_candidate_items.sort(std::greater<CacheRecord>());
size_t used = 0;
CandidateList::iterator i;
for (i = _candidate_items.begin(); i != _candidate_items.end(); ++i) {
if (used + i->cache_size > _cache_budget) break;
used += i->cache_size;
}
std::set<DrawingItem*> to_cache;
for (i = _candidate_items.begin(); i != _candidate_items.end(); ++i) {
/* i->item->setCached(true);*/
to_cache.insert(i->item);
}
// Everything which is now in _cached_items but not in to_cache must be uncached
// Note that calling setCached on an item modifies _cached_items
// TODO: find a way to avoid the set copy
/* std::set<DrawingItem*> to_uncache;*/
/* std::set_difference(_cached_items.begin(), _cached_items.end(),*/
/* to_cache.begin(), to_cache.end(),*/
/* std::inserter(to_uncache, to_uncache.end()));*/
/* for (std::set<DrawingItem*>::iterator j = to_uncache.begin(); j != to_uncache.end(); ++j) {*/
/* (*j)->setCached(false);*/
/* }*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment