Exemple #1
0
        public void put(K key, T value)
        {
            CacheNode <K, T> newNode = new CacheNode <K, T>(key, value);
            int placementSet         = hashKey(key);
            CacheNode <K, T> head    = setHeads[placementSet];

            // Check to see if the cache already contains that value.
            if (isInCache(key, value))
            {
                return;
            }

            // If the set is at capacity a node is evicted, otherwise the new
            // node is set as the head node.
            if (head.count() >= setSize)
            {
                KeyValuePair <K, T> pairToEvict = alg(head);
                evictNode(pairToEvict, newNode);
            }
            else
            {
                head.prev              = newNode;
                newNode.next           = head;
                setHeads[placementSet] = newNode;
            }
        }