|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.Name.AdHocPrefixCache<TerminusKey>
TerminusKey - type of key for prefix of Name instances
must be immutable and support consistent hashCode() and equals()private static final class Name.AdHocPrefixCache<TerminusKey extends java.lang.Number>
Contains lookup cache by prefix for all Name instances. This is used to try to find a prefix for a newly-constructed Name where no prefix has been supplied at all.
This looks up in a short list of recent/useful Name values with the same fixed-length prefix for something of the same concrete type and the longest available prefix match, returning the candidate 'prev' item (or null if none) which then can be used in the usual way.
The Name instances are held via WeakReference wrappers which should ensure that the cache does not keep them from being garbage collected.
This would usually be invoked by the factory method or constructor where no 'prev' has been supplied.
This cache should grow as needed to get a decent hit rate, and shrink to release memory when the hit rate is high or the memory subsystem is stressed.
Thread-safe but does not support concurrency (fully synchronized).
A lock can be held on instances of this object to make compound operations atomic.
| Field Summary | |
|---|---|
private static int |
MAX_LIST_LEN
Maximum list length under normal circumstances; strictly positive. |
private static int |
MAX_SECONDARY_LIST_LEN
Maximum secondary list length under normal circumstances; strictly positive. |
private MemoryTools.CacheMiniMap<TerminusKey,java.util.LinkedList<java.lang.ref.WeakReference<Name>>> |
prefixStore
The lookup from prefix key to list of candidate same-prefix instances; never null. |
private static int |
STRESSED_LIST_LEN
Maximum list length under memory stress; strictly positive, less than MAX_LIST_LEN. |
private MemoryTools.CacheMiniMap<TerminusKey,java.util.LinkedList<java.lang.ref.WeakReference<Name>>> |
suffixStore
The lookup from suffix key to list of candidate same-suffix instances; never null. |
| Constructor Summary | |
|---|---|
private |
Name.AdHocPrefixCache()
|
| Method Summary | ||
|---|---|---|
private static int |
computeCacheMaxSize()
Compute maximum (prefix) cache size, partly based on heap size; strictly positive. |
|
(package private) Name |
findPrev(java.lang.CharSequence putativeName)
Returns a suitable prev (with a shared prefix/suffix) for the supplied non-null Name of any Name subclass, else null if none found. |
|
(package private) int |
getMaxListLen(boolean isPrefix)
Maximum same-prefix list length; strictly positive. |
|
(package private)
|
offerNewInstance(N name)
Offer a newly constructed Name instance to the cache; returns the value passed in. |
|
private void |
trimDeadRefs(java.util.List<java.lang.ref.WeakReference<Name>> l)
Trim dead references from the supplied non-null list. |
|
private void |
trimListLength(java.util.LinkedList<java.lang.ref.WeakReference<Name>> l,
boolean isPrefix)
Trim the supplied non-null list to size if too long. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private final MemoryTools.CacheMiniMap<TerminusKey extends java.lang.Number,java.util.LinkedList<java.lang.ref.WeakReference<Name>>> prefixStore
Empty lists (or those effectively empty because all the WeakReferences have been dropped) will be purged (ie empty lists are not retained).
The lists values are of type LinkedList, with 'best' items first.
(In future, where a list is of length 1 and where the maximum length is currently 1, a list may be stored as a singleton for efficiency.)
We hope for a reasonable minimum size to have a sensible chance of any match at all across a large text base.
We size the maximum based on total heap capacity, and allow everything to be discarded in case of extreme memory stress.
private final MemoryTools.CacheMiniMap<TerminusKey extends java.lang.Number,java.util.LinkedList<java.lang.ref.WeakReference<Name>>> suffixStore
private static final int MAX_LIST_LEN
private static final int MAX_SECONDARY_LIST_LEN
private static final int STRESSED_LIST_LEN
Under stress, any entries we touch are capped to this length, thus allowing us to gracefully and incrementally free space.
Borrowing from GZIP '-1/'-fast' experience a good value might be 1.
| Constructor Detail |
|---|
private Name.AdHocPrefixCache()
| Method Detail |
|---|
private static int computeCacheMaxSize()
Name findPrev(java.lang.CharSequence putativeName)
<N extends Name> N offerNewInstance(N name)
private void trimDeadRefs(java.util.List<java.lang.ref.WeakReference<Name>> l)
private void trimListLength(java.util.LinkedList<java.lang.ref.WeakReference<Name>> l,
boolean isPrefix)
int getMaxListLen(boolean isPrefix)
|
DHD Multimedia Gallery V1.57.21 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||