Ejemplo n.º 1
0
 /// <summary>
 /// Possibly prunes the cache to remove some of the least recently accessed nodes.
 /// </summary>
 /// <param name="store"></param>
 public void PossiblyPruneCache(MCTSNodeStore store)
 {
     if (numCachePrunesInProgress == 0 && nodeCache.Count > MaxCacheSize)
     {
         // Reduce to 80% of prior size
         Task.Run(() =>
         {
             //using (new TimingBlock("Prune"))
             {
                 Interlocked.Increment(ref numCachePrunesInProgress);
                 DictionaryUtils.PruneDictionary(nodeCache, a => a.LastAccessedSequenceCounter,
                                                 (MaxCacheSize * 8) / 10);
                 Interlocked.Decrement(ref numCachePrunesInProgress);
             };
         });
     }
 }