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.Serializable
Simple 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.Object
FREE_KEY
private java.lang.Object[]
m_data_
Keys and valuesprivate float
m_fillFactor_
Fill factor, must be between (0 and 1)private int
m_mask_
Mask to calculate the original positionprivate int
m_mask2_
Mask to wrap the actual array pointerprivate int
m_size_
Current map sizeprivate int
m_threshold_
We will resize a map once it reaches this sizeprivate static java.lang.Object
REMOVED_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 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 )
.void
clear()
Clears the map, reuses the data structure by clearing it out.V
get(K key)
private int
getStartIndex(java.lang.Object key)
java.util.List<K>
keys()
static long
nextPowerOfTwo(long x)
Return the least power of two greater than or equal to the specified value.V
put(K key, V value)
private void
readObject(java.io.ObjectInputStream aInputStream)
We have to overwrite the import due to the use of static object as markerprivate void
rehash(int newCapacity)
V
remove(K key)
int
size()
java.util.List<V>
values()
private void
writeObject(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.IOException
We 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.IOException
We 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
-
-