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:
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Object
private Object[]
Keys and valuesprivate final float
Fill factor, must be between (0 and 1)private int
Mask to calculate the original positionprivate int
Mask to wrap the actual array pointerprivate int
Current map sizeprivate int
We will resize a map once it reaches this sizeprivate static final Object
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.private int
getStartIndex
(Object key) keys()
static long
nextPowerOfTwo
(long x) Return the least power of two greater than or equal to the specified value.private void
readObject
(ObjectInputStream aInputStream) We have to overwrite the import due to the use of static object as markerprivate void
rehash
(int newCapacity) int
size()
values()
private void
writeObject
(ObjectOutputStream aOutputStream) We have to overwrite the export due to the use of static object as marker
-
Field Details
-
FREE_KEY
-
REMOVED_KEY
-
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
-
-
Constructor Details
-
FastHashMap
public FastHashMap() -
FastHashMap
public FastHashMap(int size, float fillFactor)
-
-
Method Details
-
get
-
put
-
remove
-
size
public int size() -
rehash
private void rehash(int newCapacity) -
keys
- Returns:
- a list of all keys
-
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
-
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:
IllegalArgumentException
- if the necessary size is larger than 230.
-
readObject
We have to overwrite the import due to the use of static object as marker- Parameters:
aInputStream
- the inputstream to read from- Throws:
IOException
- when the reading from the source failsClassNotFoundException
- in case we cannot restore a class
-
writeObject
We have to overwrite the export due to the use of static object as marker- Parameters:
aOutputStream
- the stream to write to- Throws:
IOException
- when a problem during writing occurs
-