Exemplo n.º 1
0
        /// <summary>
        /// Cache constructor when a custom cache replacement algorithm is supplied
        /// </summary>
        /// <param name="cacheSize">Size of the cache</param>
        /// <param name="nItems">Number of cache items in a Set</param>
        /// <param name="custAlgorithm">Custom replacement algorithm</param>
        public Cache(int cacheSize, int nItems, ICacheAlgorithms <K, V> custAlgorithm)
        {
            this.cacheSize = cacheSize;
            this.nItems    = nItems;
            this.nSets     = this.cacheSize / this.nItems;

            for (int i = 0; i < nSets; i++)
            {
                cache.Add(new Set <K, V>(nItems, custAlgorithm));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor for Set, instantiates the ICacheAlgorithms interfaced based on which algorithm was supplied
        /// </summary>
        /// <param name="nItems">Number of cache items in a Set</param>
        /// <param name="algorithm">Default replacement algorithm (LRU/MRU)</param>
        public Set(int nItems, Algorithm algorithm)
        {
            this.nItems = nItems;

            if (algorithm == Algorithm.LRU)
            {
                cacheAlgo = new LRU <K, V>(nItems);
            }

            else if (algorithm == Algorithm.MRU)
            {
                cacheAlgo = new MRU <K, V>(nItems);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor for Set when a custom cache replacement algorithm is supplied
 /// </summary>
 /// <param name="nItems">Number of cache items in a Set</param>
 /// <param name="algorithm">Custom replacement algorithm</param>
 public Set(int nItems, ICacheAlgorithms <K, V> algorithm)
 {
     this.nItems = nItems;
     cacheAlgo   = algorithm;
 }