Package org.htmlunit.cyberneko.util
Class FastHashMap<K,V>
- java.lang.Object
-
- org.htmlunit.cyberneko.util.FastHashMap<K,V>
-
- Type Parameters:
K- the type of the keyV- the type of the value
- All Implemented Interfaces:
java.io.Serializable
public class FastHashMap<K,V> extends java.lang.Object implements java.io.SerializableSimple hash map implementation taken from here https://github.com/mikvor/hashmapTest/blob/master/src/main/java/map/objobj/ObjObjMap.java No concrete license specified at the source. The project is public domain. Not thread-safe! Null support was removed.- Since:
- 3.10.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.ObjectFREE_KEYprivate java.lang.Object[]m_data_Keys and valuesprivate floatm_fillFactor_Fill factor, must be between (0 and 1)private intm_mask_Mask to calculate the original positionprivate intm_mask2_Mask to wrap the actual array pointerprivate intm_size_Current map sizeprivate intm_threshold_We will resize a map once it reaches this sizeprivate static java.lang.ObjectREMOVED_KEY
-
Constructor Summary
Constructors Constructor Description FastHashMap()FastHashMap(int size, float fillFactor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static intarraySize(int expected, float f)Returns the least power of two smaller than or equal to 230 and larger than or equal toMath.ceil( expected / f ).voidclear()Clears the map, reuses the data structure by clearing it out.Vget(K key)private intgetStartIndex(java.lang.Object key)java.util.List<K>keys()static longnextPowerOfTwo(long x)Return the least power of two greater than or equal to the specified value.Vput(K key, V value)private voidreadObject(java.io.ObjectInputStream aInputStream)We have to overwrite the import due to the use of static object as markerprivate voidrehash(int newCapacity)Vremove(K key)intsize()java.util.List<V>values()private voidwriteObject(java.io.ObjectOutputStream aOutputStream)We have to overwrite the export due to the use of static object as marker
-
-
-
Field Detail
-
FREE_KEY
private static final java.lang.Object FREE_KEY
-
REMOVED_KEY
private static final java.lang.Object REMOVED_KEY
-
m_data_
private java.lang.Object[] m_data_
Keys and values
-
m_fillFactor_
private final float m_fillFactor_
Fill factor, must be between (0 and 1)
-
m_threshold_
private int m_threshold_
We will resize a map once it reaches this size
-
m_size_
private int m_size_
Current map size
-
m_mask_
private int m_mask_
Mask to calculate the original position
-
m_mask2_
private int m_mask2_
Mask to wrap the actual array pointer
-
-
Method Detail
-
size
public int size()
-
rehash
private void rehash(int newCapacity)
-
keys
public java.util.List<K> keys()
- Returns:
- a list of all keys
-
values
public java.util.List<V> values()
- Returns:
- a list of all values
-
clear
public void clear()
Clears the map, reuses the data structure by clearing it out. It won't shrink the underlying array!
-
getStartIndex
private int getStartIndex(java.lang.Object key)
-
nextPowerOfTwo
public static long nextPowerOfTwo(long x)
Return the least power of two greater than or equal to the specified value.Note that this function will return 1 when the argument is 0.
- Parameters:
x- a long integer smaller than or equal to 262.- Returns:
- the least power of two greater than or equal to the specified value.
-
arraySize
public static int arraySize(int expected, float f)Returns the least power of two smaller than or equal to 230 and larger than or equal toMath.ceil( expected / f ).- Parameters:
expected- the expected number of elements in a hash table.f- the load factor.- Returns:
- the minimum possible size for a backing array.
- Throws:
java.lang.IllegalArgumentException- if the necessary size is larger than 230.
-
readObject
private void readObject(java.io.ObjectInputStream aInputStream) throws java.lang.ClassNotFoundException, java.io.IOExceptionWe have to overwrite the import due to the use of static object as marker- Parameters:
aInputStream- the inputstream to read from- Throws:
java.io.IOException- when the reading from the source failsjava.lang.ClassNotFoundException- in case we cannot restore a class
-
writeObject
private void writeObject(java.io.ObjectOutputStream aOutputStream) throws java.io.IOExceptionWe have to overwrite the export due to the use of static object as marker- Parameters:
aOutputStream- the stream to write to- Throws:
java.io.IOException- when a problem during writing occurs
-
-