@Test public void test() throws InterruptedException { for (int i = 0; i < N; i++) { Item item = new Item(new Id(i)); item.okToEvict(i == 0); clock.addItem(item); } TestThread[] threads = new TestThread[THREADS]; for (int t = 0; t < THREADS; t++) { threads[t] = new TestThread(); } for (TestThread thread : threads) { thread.start(); } for (TestThread thread : threads) { thread.join(); } }
public void addItem(ITEM item) { assert item != null; assert !item.placeholder(); observer.adding(item); item.recentAccess(true); switch (size) { case 0: assert clockHand == null; assert previous == null; clockHand = item; item.next(clockHand); break; case 1: assert clockHand != null; assert previous == null; clockHand.next(item); item.next(clockHand); previous = item; break; default: assert clockHand != null; assert previous != null; item.next(clockHand); previous.next(item); previous = item; break; } size++; }
CacheEntryList { public void addItem(ITEM item) { assert item != null; assert !item.placeholder(); observer.adding(item); item.recentAccess(true); switch (size) { case 0: assert clockHand == null; assert previous == null; clockHand = item; item.next(clockHand); break; case 1: assert clockHand != null; assert previous == null; clockHand.next(item); item.next(clockHand); previous = item; break; default: assert clockHand != null; assert previous != null; item.next(clockHand); previous.next(item); previous = item; break; } size++; } }
CacheEntryList { public void addItem(ITEM item) { assert item != null; assert !item.placeholder(); observer.adding(item); item.recentAccess(true); switch (size) { case 0: assert clockHand == null; assert previous == null; clockHand = item; item.next(clockHand); break; case 1: assert clockHand != null; assert previous == null; clockHand.next(item); item.next(clockHand); previous = item; break; default: assert clockHand != null; assert previous != null; item.next(clockHand); previous.next(item); previous = item; break; } size++; } CacheEntryList(Observer<ID, ITEM> observer); }
CacheEntryList { public void addItem(ITEM item) { assert item != null; assert !item.placeholder(); observer.adding(item); item.recentAccess(true); switch (size) { case 0: assert clockHand == null; assert previous == null; clockHand = item; item.next(clockHand); break; case 1: assert clockHand != null; assert previous == null; clockHand.next(item); item.next(clockHand); previous = item; break; default: assert clockHand != null; assert previous != null; item.next(clockHand); previous.next(item); previous = item; break; } size++; } CacheEntryList(Observer<ID, ITEM> observer); int size(); void addItem(ITEM item); ITEM takeItemToEvict(); Map<Integer, Integer> referenceCountDistribution(); }
CacheEntryList { public void addItem(ITEM item) { assert item != null; assert !item.placeholder(); observer.adding(item); item.recentAccess(true); switch (size) { case 0: assert clockHand == null; assert previous == null; clockHand = item; item.next(clockHand); break; case 1: assert clockHand != null; assert previous == null; clockHand.next(item); item.next(clockHand); previous = item; break; default: assert clockHand != null; assert previous != null; item.next(clockHand); previous.next(item); previous = item; break; } size++; } CacheEntryList(Observer<ID, ITEM> observer); int size(); void addItem(ITEM item); ITEM takeItemToEvict(); Map<Integer, Integer> referenceCountDistribution();  }