|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Dictionary | +--de.spieleck.util.SpeedHashtable
A more efficient version of java.util.Hashtable
.
This is faster for the following reasons:
Note within larger projekts this class might have secondary benefits since it doesn't allocate objects unlike the sun implementation of Hashtable and HashMap.
Field Summary | |
protected int |
capacity
The current capacity of the array (half of table.length). |
protected int |
capacity1
capacity - 1. |
protected int |
lastGetIndex
This data allows nice threadunsafe optimizations. |
protected java.lang.Object |
lastKey
This data allows nice threadunsafe optimizations. |
protected int |
used
The actually number of used entries in the array. |
Constructor Summary | |
SpeedHashtable()
Creates a hash table with standard initial capacity. |
|
SpeedHashtable(double loadFactor)
Create hashtable with non standard load factor |
|
SpeedHashtable(int n)
Creates a hash table with the specified initial capacity. |
|
SpeedHashtable(int n,
double loadFactor)
Create hashtable with non standard load factor and special size |
Method Summary | |
void |
append(SpeedHashtable tab2)
Append contents from another SpeedHashtable. |
void |
clear()
Removes all objects from the hash table, so that the hash table becomes empty. |
boolean |
containsKey(java.lang.Object key)
This API is obviously useless :-) |
java.util.Enumeration |
elements()
|
java.lang.Object |
get(java.lang.Object key)
|
java.lang.Object[] |
getElementSnap()
Snapshot hashtable elements. |
java.lang.Object[] |
getKeySnap()
Snapshot hashtable keys. |
protected int |
hashCode(java.lang.Object key)
This is a customization API to replace hashCode() by more efficient methods. |
boolean |
isEmpty()
|
java.util.Enumeration |
keys()
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
|
java.lang.Object |
remove(java.lang.Object key)
Removes the object with the specified key from the table. |
java.lang.Object |
replaceLastGet(java.lang.Object value)
Slightly dirty solution to the double hash and search effect in the (very common sequence): SpeedHashtable fh = ... |
int |
size()
|
protected java.lang.Object |
unsafePut(java.lang.Object key,
java.lang.Object value)
Internal Version of the putter, not as fail safe... |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int capacity
protected int capacity1
protected int used
protected int lastGetIndex
protected java.lang.Object lastKey
Constructor Detail |
public SpeedHashtable()
public SpeedHashtable(int n)
public SpeedHashtable(double loadFactor)
public SpeedHashtable(int n, double loadFactor)
Method Detail |
public final int size()
size
in class java.util.Dictionary
public final boolean isEmpty()
isEmpty
in class java.util.Dictionary
protected int hashCode(java.lang.Object key)
public final boolean containsKey(java.lang.Object key)
public java.lang.Object get(java.lang.Object key)
get
in class java.util.Dictionary
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in class java.util.Dictionary
public java.lang.Object replaceLastGet(java.lang.Object value)
SpeedHashtable fh = ... Object something = fh.get(key); if ( something ... ) { Object somethingdifferent = ... fh.put(key, somethingdifferent); }This can now be written more efficient as
Object something = fh.get(key); if ( something ... ) { Object somethingdifferent = ... fh.replaceLastGet(somethingdifferent); }Caution: Due to rehashing can only be called once per get()! This is not at all a thread safe mechanism
protected final java.lang.Object unsafePut(java.lang.Object key, java.lang.Object value)
public void append(SpeedHashtable tab2)
XXX Could be a bit more optimized and avoid the tab2.get() ...
public java.lang.Object remove(java.lang.Object key)
remove
in class java.util.Dictionary
public java.lang.Object[] getKeySnap()
Looks like the fastest way to get fairly safe access to many keys in a fast changing SpeedHashtable. Still not synchronized according to SpeedHashtable principle, but obviously meaningless when certain changes happen in background.
public java.lang.Object[] getElementSnap()
getKeySnap()
public void clear()
public java.util.Enumeration keys()
keys
in class java.util.Dictionary
public java.util.Enumeration elements()
elements
in class java.util.Dictionary
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |