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:
- java.io.Serializable, java.lang.Cloneable, java.util.Map<K,V>
public final class FastMap<K,V>
- extends java.lang.Object
- implements java.util.Map<K,V>, java.io.Serializable, java.lang.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 |
java.util.Map.Entry<K,V> |
Constructor Summary |
FastMap()
Creates a new with default capacity. |
FastMap(int size)
|
FastMap(int size,
int maxSize)
Creates a new whose capacity can accommodate the given number of entries without
rehash. |
FastMap(java.util.Map<K,V> other)
|
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
NO_MAX_SIZE
public static final int NO_MAX_SIZE
- See Also:
- Constant Field Values
FastMap
public FastMap()
- Creates a new with default capacity.
FastMap
public FastMap(int size)
FastMap
public FastMap(java.util.Map<K,V> other)
FastMap
public FastMap(int size,
int maxSize)
- Creates a new whose capacity can accommodate the given number of entries without
rehash.
- Parameters:
size
- desired capacitymaxSize
- max capacity
- Throws:
java.lang.IllegalArgumentException
- if size is less than 0, maxSize is less than 1, or at least half of
RandomUtils.MAX_INT_SMALLER_TWIN_PRIME
get
public V get(java.lang.Object key)
- Specified by:
get
in interface java.util.Map<K,V>
size
public int size()
- Specified by:
size
in interface java.util.Map<K,V>
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interface java.util.Map<K,V>
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKey
in interface java.util.Map<K,V>
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValue
in interface java.util.Map<K,V>
put
public V put(K key,
V value)
- Specified by:
put
in interface java.util.Map<K,V>
- Throws:
java.lang.NullPointerException
- if key or value is null
putAll
public void putAll(java.util.Map<? extends K,? extends V> map)
- Specified by:
putAll
in interface java.util.Map<K,V>
remove
public V remove(java.lang.Object key)
- Specified by:
remove
in interface java.util.Map<K,V>
clear
public void clear()
- Specified by:
clear
in interface java.util.Map<K,V>
keySet
public java.util.Set<K> keySet()
- Specified by:
keySet
in interface java.util.Map<K,V>
values
public java.util.Collection<V> values()
- Specified by:
values
in interface java.util.Map<K,V>
entrySet
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
- Specified by:
entrySet
in interface java.util.Map<K,V>
rehash
public void rehash()
clone
public FastMap<K,V> clone()
- Overrides:
clone
in class java.lang.Object
hashCode
public int hashCode()
- Specified by:
hashCode
in interface java.util.Map<K,V>
- Overrides:
hashCode
in class java.lang.Object
equals
public boolean equals(java.lang.Object other)
- Specified by:
equals
in interface java.util.Map<K,V>
- Overrides:
equals
in class java.lang.Object
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
Copyright © 2008-2010 The Apache Software Foundation. All Rights Reserved.