// Initializer using the algorithms that are provided in the class. public NSACache(int cacheCapacity, int setNum, string alg) { this.setNum = setNum; this.cacheCapacity = cacheCapacity; // Every set is the same size, so the setSize is the quotient of // cacheCapacity / setNum. setSize = cacheCapacity / setNum; //cachedObjectsArray = new KeyValuePair<K, T>[setNum, setSize]; setHeads = new CacheNode <K, T> [setNum]; // The default algorithm is LRU. if (alg.ToLower() == "mru") { this.alg = mruAlgorithm; } else { this.alg = lruAlgorithm; } // The following loop instantiates the head node in each set. for (int i = 0; i < setNum; i++) { setHeads[i] = new CacheNode <K, T>(); } }
// Initializer using custom algorithms that are provided by the user. public NSACache(int cacheCapacity, int setNum, evictionAlgorithm customAlg) { this.setNum = setNum; this.cacheCapacity = cacheCapacity; setHeads = new CacheNode <K, T> [setNum]; alg = customAlg; for (int i = 0; i < setNum; i++) { setHeads[i] = new CacheNode <K, T>(); } setSize = cacheCapacity / setNum; }