Skip to content

Instantly share code, notes, and snippets.

@XavierTalpe
Created July 7, 2013 12:52
Show Gist options
  • Select an option

  • Save XavierTalpe/5943369 to your computer and use it in GitHub Desktop.

Select an option

Save XavierTalpe/5943369 to your computer and use it in GitHub Desktop.
Hash-map that can be used as a LRU cache.
public final class LruCache<K, V> extends LinkedHashMap<K, V> {
private final int fSize;
public LruCache( int aSize ) {
super( aSize + 1, 1.0f, true );
fSize = aSize;
}
@Override
protected boolean removeEldestEntry( Entry<K, V> eldest ) {
return super.size() > fSize;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment