public Map<Long, V> getLatestAccessedItems(int n) { Map<Long, V> result = new LinkedHashMap<Long, V>(); if (n <= 0) return result; TreeSet<CacheEntry<Long, V>> tree = new TreeSet<CacheEntry<Long, V>>(); // we need to grab the lock since we are changing lastAccessedCopy markAndSweepLock.lock(); try { for (Map.Entry<Long, CacheEntry<Long, V>> entry : map.entrySet()) { CacheEntry<Long, V> ce = entry.getValue(); ce.lastAccessedCopy = ce.lastAccessed; if (tree.size() < n) { tree.add(ce); } else { if (ce.lastAccessedCopy > tree.last().lastAccessedCopy) { tree.remove(tree.last()); tree.add(ce); } } } } finally { markAndSweepLock.unlock(); } for (CacheEntry<Long, V> e : tree) { result.put(e.key, e.value); } return result; }
markAndSweepLock.lock(); try { for (Map.Entry<Long, CacheEntry<Long, V>> entry : map.entrySet()) { CacheEntry<Long, V> ce = entry.getValue(); ce.lastAccessedCopy = ce.lastAccessed;
public Map<Long, V> getLatestAccessedItems(int n) { final Map<Long, V> result = new LinkedHashMap<>(); if (n <= 0) return result; final TreeSet<CacheEntry<Long, V>> tree = new TreeSet<>(); // we need to grab the lock since we are changing lastAccessedCopy markAndSweepLock.lock(); try { for (Map.Entry<Long, CacheEntry<Long, V>> entry : map.entrySet()) { final CacheEntry<Long, V> ce = entry.getValue(); ce.lastAccessedCopy = ce.lastAccessed; if (tree.size() < n) { tree.add(ce); } else { if (ce.lastAccessedCopy > tree.last().lastAccessedCopy) { tree.remove(tree.last()); tree.add(ce); } } } } finally { markAndSweepLock.unlock(); } for (CacheEntry<Long, V> e : tree) { result.put(e.key, e.value); } return result; }
markAndSweepLock.lock(); try { for (Map.Entry<Long, CacheEntry<Long, V>> entry : map.entrySet()) { CacheEntry<Long, V> ce = entry.getValue(); ce.lastAccessedCopy = ce.lastAccessed;
@Override public Iterable<Map.Entry<Long, S>> entries() { return vertexStates.entrySet(); }
@Override public boolean contains(long address, long size) { for (Map.Entry<Long, Long> entry : allocatedMemories.entrySet()) { long startAddress = entry.getKey(); long endAddress = startAddress + entry.getValue(); if (address >= startAddress && (address + size) <= endAddress) { return true; } } return false; }
@Override public boolean contains(long address) { for (Map.Entry<Long, Long> entry : allocatedMemories.entrySet()) { long startAddress = entry.getKey(); long endAddress = startAddress + entry.getValue(); if (address >= startAddress && address <= endAddress) { return true; } } return false; }
@Override public void iterate(AllocatedMemoryIterator iterator) { for (Map.Entry<Long, Long> entry : allocatedMemories.entrySet()) { long address = entry.getKey(); long size = entry.getValue(); iterator.onAllocatedMemory(address, size); } }
public Map<Long, V> getLatestAccessedItems(int n) { Map<Long, V> result = new LinkedHashMap<Long, V>(); if (n <= 0) return result; TreeSet<CacheEntry<Long, V>> tree = new TreeSet<CacheEntry<Long, V>>(); // we need to grab the lock since we are changing lastAccessedCopy markAndSweepLock.lock(); try { for (Map.Entry<Long, CacheEntry<Long, V>> entry : map.entrySet()) { CacheEntry<Long, V> ce = entry.getValue(); ce.lastAccessedCopy = ce.lastAccessed; if (tree.size() < n) { tree.add(ce); } else { if (ce.lastAccessedCopy > tree.last().lastAccessedCopy) { tree.remove(tree.last()); tree.add(ce); } } } } finally { markAndSweepLock.unlock(); } for (CacheEntry<Long, V> e : tree) { result.put(e.key, e.value); } return result; }
public Map<Long, V> getLatestAccessedItems(int n) { Map<Long, V> result = new LinkedHashMap<Long, V>(); if (n <= 0) return result; TreeSet<CacheEntry<Long, V>> tree = new TreeSet<CacheEntry<Long, V>>(); // we need to grab the lock since we are changing lastAccessedCopy markAndSweepLock.lock(); try { for (Map.Entry<Long, CacheEntry<Long, V>> entry : map.entrySet()) { CacheEntry<Long, V> ce = entry.getValue(); ce.lastAccessedCopy = ce.lastAccessed; if (tree.size() < n) { tree.add(ce); } else { if (ce.lastAccessedCopy > tree.last().lastAccessedCopy) { tree.remove(tree.last()); tree.add(ce); } } } } finally { markAndSweepLock.unlock(); } for (CacheEntry<Long, V> e : tree) { result.put(e.key, e.value); } return result; }
markAndSweepLock.lock(); try { for (Map.Entry<Long, CacheEntry<Long, V>> entry : map.entrySet()) { CacheEntry<Long, V> ce = entry.getValue(); ce.lastAccessedCopy = ce.lastAccessed;
markAndSweepLock.lock(); try { for (Map.Entry<Long, CacheEntry<Long, V>> entry : map.entrySet()) { CacheEntry<Long, V> ce = entry.getValue(); ce.lastAccessedCopy = ce.lastAccessed;