public static class WeakTopicIndex.CacheList<E>
extends java.lang.Object
Cache list is a list of objects where the most used objects are at the top of the list and least used objects are at the bottom. New objects are added somewhere in the middle but near the bottom. Objects are accessed which either moves them up in the list or adds them at the specified add point if they are not in the list allready.
The idea is that a limited number of objects from a very large object pool are kept in memeory and it is prefered that objects that are used the most stay in the list while objects that are used little fall off the list. Objects are not added right at the bottom to avoid them being falling off the list straight away and not having any chance of moving up.
List is implemented as a linked list with pointers to the top, bottom and the marked add position.
Modifier and Type | Class and Description |
---|---|
private static class |
WeakTopicIndex.CacheList.ListItem<E> |
Modifier and Type | Field and Description |
---|---|
static int |
cacheSize
The maximum size of the list
|
private WeakTopicIndex.CacheList.ListItem<E> |
first |
private WeakTopicIndex.CacheList.ListItem<E> |
last |
private java.util.HashMap<E,WeakTopicIndex.CacheList.ListItem<E>> |
map |
private WeakTopicIndex.CacheList.ListItem<E> |
mark |
static int |
markPos
The position at which new objects are added
|
private int |
size |
Constructor and Description |
---|
CacheList() |
Modifier and Type | Method and Description |
---|---|
void |
access(E e)
Accesses an object moving it up in the list or adding it to the
list if it isn't in it yet.
|
private void |
addAtMark(E e) |
private void |
moveUp(WeakTopicIndex.CacheList.ListItem<E> item) |
void |
printDebugInfo() |
int |
size() |
public static final int cacheSize
public static final int markPos
private int size
private WeakTopicIndex.CacheList.ListItem<E> last
private WeakTopicIndex.CacheList.ListItem<E> first
private WeakTopicIndex.CacheList.ListItem<E> mark
private java.util.HashMap<E,WeakTopicIndex.CacheList.ListItem<E>> map
private void addAtMark(E e)
private void moveUp(WeakTopicIndex.CacheList.ListItem<E> item)
public void access(E e)
public int size()
public void printDebugInfo()
Copyright 2004-2015 Wandora Team