예제 #1
0
			void insert(const cache_key_type &key, const cache_value_type &val)
			{
				// Record k as most-recently-used key 
				list_iterator it = list_.insert(list_.end(), key); 

				// Create the key-value entry, linked to the usage record. 
				map_.insert(std::make_pair(key, std::make_pair(val, it))); 
			}
예제 #2
0
/// Inserts the given query, result pair into the cache.
void CachingSolver::cacheInsert(const Query& query,
                                IncompleteSolver::PartialValidity result) {
  bool negationUsed;
  ref<Expr> canonicalQuery = canonicalizeQuery(query.expr, negationUsed);

  CacheEntry ce(query.constraints, canonicalQuery);
  IncompleteSolver::PartialValidity cachedResult = 
    (negationUsed ? IncompleteSolver::negatePartialValidity(result) : result);
  
  cache.insert(std::make_pair(ce, cachedResult));
}
예제 #3
0
// returns the program cache for the context
inline boost::shared_ptr<program_cache> get_program_cache(const context &context)
{
    typedef lru_cache<cl_context, boost::shared_ptr<program_cache> > cache_map;

    static cache_map caches(8);

    boost::shared_ptr<program_cache> cache = caches.get(context.get());
    if(!cache){
        cache = boost::make_shared<program_cache>(64);

        caches.insert(context.get(), cache);
    }

    return cache;
}
예제 #4
0
 Result Cache<Result(Args...)>::operator()(Args... args) {
     argument_tuple tup{args...};
     auto map_iter = map.find(tup);
     bool insert = map_iter == map.end();
     log.push_back(nullptr);
     ScopeFailure guard([&] { log.pop_back(); });
     if (insert)
         map_iter = map.insert({tup, {tuple_invoke(fun, tup), {}}}).first;
     log.back() = &map_iter->first;
     if (! insert)
         log.erase(map_iter->second.log_iter);
     map_iter->second.log_iter = std::prev(log.end());
     if (insert && map.size() > cap) {
         map.erase(*log.front());
         log.pop_front();
     }
     return map_iter->second.result;
 }