public final class FastMap<K,V> extends Object implements Map<K,V>, Serializable, Cloneable
This is an optimized Map
implementation, based on algorithms described in Knuth's "Art of Computer
Programming", Vol. 3, p. 529.
It should be faster than HashMap
in some cases, but not all. Its main feature is a
"max size" and the ability to transparently, efficiently and semi-intelligently evict old entries when max
size is exceeded.
This class is not a bit thread-safe.
This implementation does not allow null
as a key or value.
Modifier and Type | Field and Description |
---|---|
static int |
NO_MAX_SIZE |
Constructor and Description |
---|
FastMap()
Creates a new
FastMap with default capacity. |
FastMap(int size) |
FastMap(int size,
float loadFactor) |
FastMap(int size,
int maxSize) |
FastMap(int size,
int maxSize,
float loadFactor)
Creates a new whose capacity can accommodate the given number of entries without rehash.
|
FastMap(Map<K,V> other) |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
FastMap<K,V> |
clone() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
boolean |
equals(Object other) |
V |
get(Object key) |
int |
hashCode() |
boolean |
isEmpty() |
Set<K> |
keySet() |
V |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> map) |
void |
rehash() |
V |
remove(Object key) |
int |
size() |
String |
toString() |
Collection<V> |
values() |
public static final int NO_MAX_SIZE
public FastMap()
FastMap
with default capacity.public FastMap(int size)
public FastMap(int size, float loadFactor)
public FastMap(int size, int maxSize)
public FastMap(int size, int maxSize, float loadFactor)
size
- desired capacitymaxSize
- max capacityIllegalArgumentException
- if size is less than 0, maxSize is less than 1
or at least half of RandomUtils.MAX_INT_SMALLER_TWIN_PRIME
, or
loadFactor is less than 1public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
public V put(K key, V value)
put
in interface Map<K,V>
NullPointerException
- if key or value is nullpublic void rehash()
public int hashCode()
public boolean equals(Object other)
Copyright © 2008–2015 The Apache Software Foundation. All rights reserved.