@Test public void testPrecision() { LrfuEvictionQueue<?> q = new LrfuEvictionQueue<BaseCacheEntry>(new AtomicLong()); long value = 0; for (long i = Integer.MAX_VALUE; i < 10L + Integer.MAX_VALUE; i++) { long valueNext = q.computeNextOrderingValue(i, i-1, value); assertTrue(valueNext > value); value = valueNext; } }
long computeNextOrderingValue(long currentTime, long lastAccess, long orderingValue) { long delta = currentTime - lastAccess; if (delta > maxInterval) { return currentTime; } long increase = orderingValue + lastAccess; if (delta > halfLife) { while ((delta-=halfLife) > halfLife && (increase>>=1) > 0) { } } increase = Math.min(currentTime, increase); return currentTime + increase; }
LrfuEvictionQueue { long computeNextOrderingValue(long currentTime, long lastAccess, long orderingValue) { long delta = currentTime - lastAccess; if (delta > maxInterval) { return currentTime; } long increase = orderingValue + lastAccess; if (delta > halfLife) { while ((delta-=halfLife) > halfLife && (increase>>=1) > 0) { } } increase = Math.min(currentTime, increase); return currentTime + increase; } }
LrfuEvictionQueue { long computeNextOrderingValue(long currentTime, long lastAccess, long orderingValue) { long delta = currentTime - lastAccess; if (delta > maxInterval) { return currentTime; } long increase = orderingValue + lastAccess; if (delta > halfLife) { while ((delta-=halfLife) > halfLife && (increase>>=1) > 0) { } } increase = Math.min(currentTime, increase); return currentTime + increase; } LrfuEvictionQueue(AtomicLong clock); }
LrfuEvictionQueue { long computeNextOrderingValue(long currentTime, long lastAccess, long orderingValue) { long delta = currentTime - lastAccess; if (delta > maxInterval) { return currentTime; } long increase = orderingValue + lastAccess; if (delta > halfLife) { while ((delta-=halfLife) > halfLife && (increase>>=1) > 0) { } } increase = Math.min(currentTime, increase); return currentTime + increase; } LrfuEvictionQueue(AtomicLong clock); boolean remove(V value); boolean add(V value); void touch(V value); Collection<V> getEvictionQueue(); V firstEntry(boolean poll); void setHalfLife(long halfLife); int getSize(); @Override String toString(); }
LrfuEvictionQueue { long computeNextOrderingValue(long currentTime, long lastAccess, long orderingValue) { long delta = currentTime - lastAccess; if (delta > maxInterval) { return currentTime; } long increase = orderingValue + lastAccess; if (delta > halfLife) { while ((delta-=halfLife) > halfLife && (increase>>=1) > 0) { } } increase = Math.min(currentTime, increase); return currentTime + increase; } LrfuEvictionQueue(AtomicLong clock); boolean remove(V value); boolean add(V value); void touch(V value); Collection<V> getEvictionQueue(); V firstEntry(boolean poll); void setHalfLife(long halfLife); int getSize(); @Override String toString();  }