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 class
OpenHashMap.AbstractObjectCollection<K>
static class
OpenHashMap.AbstractObjectSet<K>
private class
OpenHashMap.EntryIterator
private class
OpenHashMap.FastEntryIterator
private class
OpenHashMap.KeyIterator
private class
OpenHashMap.KeySet
(package private) class
OpenHashMap.MapEntry
private class
OpenHashMap.MapEntrySet
private class
OpenHashMap.MapIterator
private class
OpenHashMap.ValueIterator
-
Field Summary
Fields Modifier and Type Field Description protected boolean
containsNullKey
protected V
defRetValue
protected java.util.SortedSet<java.util.Map.Entry<K,V>>
entries
protected float
f
protected java.lang.Iterable<java.util.Map.Entry<K,V>>
fast
protected int
first
protected java.lang.Object[]
key
protected java.util.SortedSet<K>
keys
protected int
last
protected long[]
link
protected int
mask
protected int
maxFill
protected int
n
private static long
serialVersionUID
protected int
size
protected java.lang.Object[]
value
protected 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 int
arraySize(int expected, float f)
private void
checkTable()
void
clear()
OpenHashMap<K,V>
clone()
java.util.Comparator<? super K>
comparator()
protected V
compute(K k)
boolean
containsKey(java.lang.Object k)
boolean
containsValue(java.lang.Object v)
V
defaultReturnValue()
void
defaultReturnValue(V rv)
private void
ensureCapacity(int capacity)
java.util.SortedSet<java.util.Map.Entry<K,V>>
entrySet()
boolean
equals(java.lang.Object o)
java.lang.Iterable<java.util.Map.Entry<K,V>>
fast()
K
firstKey()
protected void
fixPointers(int i)
protected void
fixPointers(int s, int d)
V
get(java.lang.Object k)
V
getAndMoveToFirst(K k)
V
getAndMoveToLast(K k)
V
getOrCompute(K k)
int
hashCode()
java.util.SortedMap<K,V>
headMap(K to)
private int
insert(K k, V v)
boolean
isEmpty()
java.util.SortedSet<K>
keySet()
K
lastKey()
private static int
maxFill(int n, float f)
private static int
mix(int x)
private void
moveIndexToFirst(int i)
private void
moveIndexToLast(int i)
private static int
nextPowerOfTwo(int x)
private static long
nextPowerOfTwo(long x)
V
put(K k, V v)
void
putAll(java.util.Map<? extends K,? extends V> m)
V
putAndMoveToFirst(K k, V v)
V
putAndMoveToLast(K k, V v)
private void
readObject(java.io.ObjectInputStream s)
private int
realSize()
protected void
rehash(int newN)
Rehashes the map.V
remove(java.lang.Object k)
private V
removeEntry(int pos)
V
removeFirst()
V
removeLast()
private V
removeNullEntry()
private V
setValue(int pos, V v)
protected void
shiftKeys(int pos)
int
size()
java.util.SortedMap<K,V>
subMap(K from, K to)
java.util.SortedMap<K,V>
tailMap(K from)
java.lang.String
toString()
boolean
trim()
Rehashes the map, making the table as small as possible.boolean
trim(int n)
Rehashes this map if the table is too large.private void
tryCapacity(long capacity)
private static <K> int
unwrap(java.util.Iterator<? extends K> i, K[] array)
private static <K> int
unwrap(java.util.Iterator<? extends K> i, K[] array, int offset, int max)
java.util.Collection<V>
values()
private void
writeObject(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:
toString
in 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:
clone
in 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.IOException
java.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)
-
-