Class OpenHashMap<K,V>
- java.lang.Object
-
- org.apache.felix.resolver.util.OpenHashMap<K,V>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.Map<K,V>,java.util.SortedMap<K,V>
- Direct Known Subclasses:
OpenHashMapList,OpenHashMapSet
public class OpenHashMap<K,V> extends java.lang.Object implements java.io.Serializable, java.lang.Cloneable, java.util.SortedMap<K,V>Based on fastutil Object2ObjectLinkedOpenHashMap- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOpenHashMap.AbstractObjectCollection<K>static classOpenHashMap.AbstractObjectSet<K>private classOpenHashMap.EntryIteratorprivate classOpenHashMap.FastEntryIteratorprivate classOpenHashMap.KeyIteratorprivate classOpenHashMap.KeySet(package private) classOpenHashMap.MapEntryprivate classOpenHashMap.MapEntrySetprivate classOpenHashMap.MapIteratorprivate classOpenHashMap.ValueIterator
-
Field Summary
Fields Modifier and Type Field Description protected booleancontainsNullKeyprotected VdefRetValueprotected java.util.SortedSet<java.util.Map.Entry<K,V>>entriesprotected floatfprotected java.lang.Iterable<java.util.Map.Entry<K,V>>fastprotected intfirstprotected java.lang.Object[]keyprotected java.util.SortedSet<K>keysprotected intlastprotected long[]linkprotected intmaskprotected intmaxFillprotected intnprivate static longserialVersionUIDprotected intsizeprotected java.lang.Object[]valueprotected java.util.Collection<V>values
-
Constructor Summary
Constructors Constructor Description OpenHashMap()OpenHashMap(int expected)OpenHashMap(int expected, float f)OpenHashMap(java.util.Map<? extends K,? extends V> m)OpenHashMap(java.util.Map<? extends K,? extends V> m, float f)OpenHashMap(K[] k, V[] v)OpenHashMap(K[] k, V[] v, float f)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static intarraySize(int expected, float f)private voidcheckTable()voidclear()OpenHashMap<K,V>clone()java.util.Comparator<? super K>comparator()protected Vcompute(K k)booleancontainsKey(java.lang.Object k)booleancontainsValue(java.lang.Object v)VdefaultReturnValue()voiddefaultReturnValue(V rv)private voidensureCapacity(int capacity)java.util.SortedSet<java.util.Map.Entry<K,V>>entrySet()booleanequals(java.lang.Object o)java.lang.Iterable<java.util.Map.Entry<K,V>>fast()KfirstKey()protected voidfixPointers(int i)protected voidfixPointers(int s, int d)Vget(java.lang.Object k)VgetAndMoveToFirst(K k)VgetAndMoveToLast(K k)VgetOrCompute(K k)inthashCode()java.util.SortedMap<K,V>headMap(K to)private intinsert(K k, V v)booleanisEmpty()java.util.SortedSet<K>keySet()KlastKey()private static intmaxFill(int n, float f)private static intmix(int x)private voidmoveIndexToFirst(int i)private voidmoveIndexToLast(int i)private static intnextPowerOfTwo(int x)private static longnextPowerOfTwo(long x)Vput(K k, V v)voidputAll(java.util.Map<? extends K,? extends V> m)VputAndMoveToFirst(K k, V v)VputAndMoveToLast(K k, V v)private voidreadObject(java.io.ObjectInputStream s)private intrealSize()protected voidrehash(int newN)Rehashes the map.Vremove(java.lang.Object k)private VremoveEntry(int pos)VremoveFirst()VremoveLast()private VremoveNullEntry()private VsetValue(int pos, V v)protected voidshiftKeys(int pos)intsize()java.util.SortedMap<K,V>subMap(K from, K to)java.util.SortedMap<K,V>tailMap(K from)java.lang.StringtoString()booleantrim()Rehashes the map, making the table as small as possible.booleantrim(int n)Rehashes this map if the table is too large.private voidtryCapacity(long capacity)private static <K> intunwrap(java.util.Iterator<? extends K> i, K[] array)private static <K> intunwrap(java.util.Iterator<? extends K> i, K[] array, int offset, int max)java.util.Collection<V>values()private voidwriteObject(java.io.ObjectOutputStream s)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
key
protected transient java.lang.Object[] key
-
value
protected transient java.lang.Object[] value
-
mask
protected transient int mask
-
containsNullKey
protected transient boolean containsNullKey
-
first
protected transient int first
-
last
protected transient int last
-
link
protected transient long[] link
-
n
protected transient int n
-
maxFill
protected transient int maxFill
-
size
protected int size
-
f
protected final float f
-
defRetValue
protected V defRetValue
-
keys
protected transient java.util.SortedSet<K> keys
-
values
protected transient java.util.Collection<V> values
-
-
Method Detail
-
defaultReturnValue
public void defaultReturnValue(V rv)
-
defaultReturnValue
public V defaultReturnValue()
-
equals
public boolean equals(java.lang.Object o)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
realSize
private int realSize()
-
ensureCapacity
private void ensureCapacity(int capacity)
-
tryCapacity
private void tryCapacity(long capacity)
-
removeEntry
private V removeEntry(int pos)
-
removeNullEntry
private V removeNullEntry()
-
shiftKeys
protected final void shiftKeys(int pos)
-
removeFirst
public V removeFirst()
-
removeLast
public V removeLast()
-
moveIndexToFirst
private void moveIndexToFirst(int i)
-
moveIndexToLast
private void moveIndexToLast(int i)
-
containsKey
public boolean containsKey(java.lang.Object k)
-
containsValue
public boolean containsValue(java.lang.Object v)
-
fixPointers
protected void fixPointers(int i)
-
fixPointers
protected void fixPointers(int s, int d)
-
comparator
public java.util.Comparator<? super K> comparator()
-
keySet
public java.util.SortedSet<K> keySet()
-
values
public java.util.Collection<V> values()
-
trim
public boolean trim()
Rehashes the map, making the table as small as possible.This method rehashes the table to the smallest size satisfying the load factor. It can be used when the set will not be changed anymore, so to optimize access speed and size.
If the table size is already the minimum possible, this method does nothing.
- Returns:
- true if there was enough memory to trim the map.
- See Also:
trim(int)
-
trim
public boolean trim(int n)
Rehashes this map if the table is too large.Let N be the smallest table size that can hold
max(n,entries, still satisfying the load factor. If the current table size is smaller than or equal to N, this method does nothing. Otherwise, it rehashes this map in a table of size N.size())This method is useful when reusing maps. Clearing a map leaves the table size untouched. If you are reusing a map many times, you can call this method with a typical size to avoid keeping around a very large table just because of a few large transient maps.
- Parameters:
n- the threshold for the trimming.- Returns:
- true if there was enough memory to trim the map.
- See Also:
trim()
-
rehash
protected void rehash(int newN)
Rehashes the map.This method implements the basic rehashing strategy, and may be overriden by subclasses implementing different rehashing strategies (e.g., disk-based rehashing). However, you should not override this method unless you understand the internal workings of this class.
- Parameters:
newN- the new size
-
clone
public OpenHashMap<K,V> clone()
- Overrides:
clonein classjava.lang.Object
-
hashCode
public int hashCode()
-
writeObject
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException- Throws:
java.io.IOException
-
readObject
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, java.lang.ClassNotFoundException- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
checkTable
private void checkTable()
-
arraySize
private static int arraySize(int expected, float f)
-
maxFill
private static int maxFill(int n, float f)
-
nextPowerOfTwo
private static int nextPowerOfTwo(int x)
-
nextPowerOfTwo
private static long nextPowerOfTwo(long x)
-
mix
private static int mix(int x)
-
unwrap
private static <K> int unwrap(java.util.Iterator<? extends K> i, K[] array, int offset, int max)
-
unwrap
private static <K> int unwrap(java.util.Iterator<? extends K> i, K[] array)
-
-