private void evict() { Node victim = null; for (Node head : headQ) { if (head.next != head) { victim = head.next; break; } } if (victim == null) { return; } victim.remove(); data.remove(victim.key); out.put(victim.key, victim); if (out.size() > maxOut) { out.remove(out.firstLongKey()); } }
@Override public void record(long key) { policyStats.recordOperation(); Node node = data.get(key); if (node == null) { policyStats.recordMiss(); node = out.remove(key); if (node == null) { node = new Node(key); } data.put(key, node); if (data.size() > maximumSize) { policyStats.recordEviction(); evict(); } } else { policyStats.recordHit(); node.remove(); } node.reference++; node.queueIndex = queueIndexFor(node); node.appendToTail(headQ[node.queueIndex]); node.expireTime = currentTime + lifetime; adjust(); }
public void removeExcess() { int currentSize = keyToValue.size(); while (currentSize > flushedSize) { long firstKey = timeStampToKey.firstLongKey(); Set<KEY> keys = timeStampToKey.get(firstKey); Iterator<KEY> keyIterator = keys.iterator(); while (keyIterator.hasNext() && currentSize > flushedSize) { KEY key = keyIterator.next(); VALUE value = keyToValue.remove(key); if (value == null) { continue; } currentSize--; changed.remove(key); keyToTimeStamp.remove(key); flushListener.flush(key, value); } if (keys.isEmpty()) { timeStampToKey.remove(firstKey); } } }
private void evict() { Node victim = null; for (Node head : headQ) { if (head.next != head) { victim = head.next; break; } } if (victim == null) { return; } victim.remove(); data.remove(victim.key); out.put(victim.key, victim); if (out.size() > maxOut) { out.remove(out.firstLongKey()); } }
/** * Removes a bucket. * * @param bucket the bucket to be removed. * @return false if the bucket was not present. */ @SuppressWarnings("unchecked") public boolean remove( final T bucket ) { if ( !sizes.containsKey( bucket ) ) return false; final XoRoShiRo128PlusRandomGenerator random = new XoRoShiRo128PlusRandomGenerator( bucket.hashCode() ); final int size = sizes.removeInt( bucket ); for ( int i = 0; i < size * REPLICAE_PER_BUCKET; i++ ) { final long point = random.nextLong(); final Object o = replicae.remove( point ); if ( o instanceof ObjectAVLTreeSet ) { if ( DEBUG ) System.err.println( "Removing from " + point + " conflict set..." ); final ObjectAVLTreeSet<T> conflictSet = (ObjectAVLTreeSet<T>)o; conflictSet.remove( bucket ); if ( conflictSet.size() > 1 ) replicae.put( point, conflictSet ); else replicae.put( point, conflictSet.first() ); } else if ( o != null && ( (T)o ).compareTo( bucket ) != 0 ) replicae.put( point, o ); } return true; }
@Override public void record(long key) { policyStats.recordOperation(); Node node = data.get(key); if (node == null) { policyStats.recordMiss(); node = out.remove(key); if (node == null) { node = new Node(key); } data.put(key, node); if (data.size() > maximumSize) { policyStats.recordEviction(); evict(); } } else { policyStats.recordHit(); node.remove(); } node.reference++; node.queueIndex = queueIndexFor(node); node.appendToTail(headQ[node.queueIndex]); node.expireTime = currentTime + lifetime; adjust(); }