org.apache.mahout.cf.taste.impl.common
Class FastMap<K,V>
java.lang.Object
org.apache.mahout.cf.taste.impl.common.FastMap<K,V>
- All Implemented Interfaces:
- Serializable, Cloneable, Map<K,V>
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.
- See Also:
- Serialized Form
| Nested classes/interfaces inherited from interface java.util.Map |
Map.Entry<K,V> |
|
Constructor Summary |
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)
|
NO_MAX_SIZE
public static final int NO_MAX_SIZE
- See Also:
- Constant Field Values
FastMap
public FastMap()
- Creates a new
FastMap with default capacity.
FastMap
public FastMap(int size)
FastMap
public FastMap(Map<K,V> other)
FastMap
public FastMap(int size,
float loadFactor)
FastMap
public FastMap(int size,
int maxSize)
FastMap
public FastMap(int size,
int maxSize,
float loadFactor)
- Creates a new whose capacity can accommodate the given number of entries without rehash.
- Parameters:
size - desired capacitymaxSize - max capacity
- Throws:
IllegalArgumentException - 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 1
get
public V get(Object key)
- Specified by:
get in interface Map<K,V>
size
public int size()
- Specified by:
size in interface Map<K,V>
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty in interface Map<K,V>
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey in interface Map<K,V>
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue in interface Map<K,V>
put
public V put(K key,
V value)
- Specified by:
put in interface Map<K,V>
- Throws:
NullPointerException - if key or value is null
putAll
public void putAll(Map<? extends K,? extends V> map)
- Specified by:
putAll in interface Map<K,V>
remove
public V remove(Object key)
- Specified by:
remove in interface Map<K,V>
clear
public void clear()
- Specified by:
clear in interface Map<K,V>
keySet
public Set<K> keySet()
- Specified by:
keySet in interface Map<K,V>
values
public Collection<V> values()
- Specified by:
values in interface Map<K,V>
entrySet
public Set<Map.Entry<K,V>> entrySet()
- Specified by:
entrySet in interface Map<K,V>
rehash
public void rehash()
clone
public FastMap<K,V> clone()
- Overrides:
clone in class Object
hashCode
public int hashCode()
- Specified by:
hashCode in interface Map<K,V>- Overrides:
hashCode in class Object
equals
public boolean equals(Object other)
- Specified by:
equals in interface Map<K,V>- Overrides:
equals in class Object
toString
public String toString()
- Overrides:
toString in class Object
Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.