org.apache.cassandra.utils
Class FastHashMap<K,V>

java.lang.Object
  extended by org.apache.cassandra.utils.FastHash
      extended by org.apache.cassandra.utils.FastObjectHash<K>
          extended by org.apache.cassandra.utils.FastHashMap<K,V>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<K,V>
Direct Known Subclasses:
FastLinkedHashMap

public class FastHashMap<K,V>
extends FastObjectHash<K>
implements java.util.Map<K,V>, java.io.Serializable

An implementation of the Map interface which uses an open addressed hash table to store its contents

See Also:
Serialized Form

Nested Class Summary
protected  class FastHashMap.FastHashMapIterator<T>
           
protected  class FastHashMap.KeyView
          a view onto the keys of the map.
 
Field Summary
protected  V[] values_
          the values of the map
 
Fields inherited from class org.apache.cassandra.utils.FastObjectHash
FREE, REMOVED, set_
 
Fields inherited from class org.apache.cassandra.utils.FastHash
autoCompactionFactor_, autoCompactRemovesRemaining_, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, free_, loadFactor_, maxSize_, size_
 
Constructor Summary
FastHashMap()
          Creates a new FastHashMap instance with the default capacity and load factor.
FastHashMap(int initialCapacity)
          Creates a new FastHashMap instance with a prime capacity equal to or greater than initialCapacity and with the default load factor.
FastHashMap(int initialCapacity, float loadFactor)
          Creates a new FastHashMap instance with a prime capacity equal to or greater than initialCapacity and with the specified load factor.
FastHashMap(java.util.Map<K,V> map)
          Creates a new FastHashMap instance which contains the key/value pairs in map.
 
Method Summary
 void clear()
          Empties the map.
 FastHashMap<K,V> clone()
           
 boolean containsKey(java.lang.Object key)
          checks for the present of key in the keys of the map.
 boolean containsValue(java.lang.Object val)
          checks for the presence of val in the values of the map.
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
          Returns a Set view on the entries of the map.
 V get(java.lang.Object key)
          retrieves the value for key
 java.util.Set<K> keySet()
          returns a Set view on the keys of the map.
static void main(java.lang.String[] args)
           
 V put(K key, V value)
          Inserts a key/value pair into the map.
 void putAll(java.util.Map<? extends K,? extends V> map)
          copies the key/value mappings in map into this map.
protected  void rehash(int newCapacity)
          rehashes the map to the new capacity.
 V remove(java.lang.Object key)
          Deletes a key/value pair from the map.
protected  void removeAt(int index)
          removes the mapping at index from the map.
protected  int setUp(int initialCapacity)
          initialize the value array of the map.
 java.util.Collection<V> values()
          Returns a view on the values of the map.
 
Methods inherited from class org.apache.cassandra.utils.FastObjectHash
capacity, computeHashCode, contains, equals, index, insertionIndex, throwObjectContractViolation
 
Methods inherited from class org.apache.cassandra.utils.FastHash
calculateGrownCapacity, compact, ensureCapacity, getAutoCompactionFactor, isEmpty, postInsertHook, reenableAutoCompaction, setAutoCompactionFactor, size, tempDisableAutoCompaction, trimToSize
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode, isEmpty, size
 

Field Detail

values_

protected transient V[] values_
the values of the map

Constructor Detail

FastHashMap

public FastHashMap()
Creates a new FastHashMap instance with the default capacity and load factor.


FastHashMap

public FastHashMap(int initialCapacity)
Creates a new FastHashMap instance with a prime capacity equal to or greater than initialCapacity and with the default load factor.

Parameters:
initialCapacity - an int value

FastHashMap

public FastHashMap(int initialCapacity,
                   float loadFactor)
Creates a new FastHashMap instance with a prime capacity equal to or greater than initialCapacity and with the specified load factor.

Parameters:
initialCapacity - an int value
loadFactor - a float value

FastHashMap

public FastHashMap(java.util.Map<K,V> map)
Creates a new FastHashMap instance which contains the key/value pairs in map.

Parameters:
map - a Map value
Method Detail

clone

public FastHashMap<K,V> clone()
Overrides:
clone in class FastObjectHash<K>
Returns:
a shallow clone of this collection

setUp

protected int setUp(int initialCapacity)
initialize the value array of the map.

Overrides:
setUp in class FastObjectHash<K>
Parameters:
initialCapacity - an int value
Returns:
an int value

put

public V put(K key,
             V value)
Inserts a key/value pair into the map.

Specified by:
put in interface java.util.Map<K,V>
Parameters:
key - an Object value
value - an Object value
Returns:
the previous value associated with key, or null if none was found.

rehash

protected void rehash(int newCapacity)
rehashes the map to the new capacity.

Specified by:
rehash in class FastHash
Parameters:
newCapacity - an int value

get

public V get(java.lang.Object key)
retrieves the value for key

Specified by:
get in interface java.util.Map<K,V>
Parameters:
key - an Object value
Returns:
the value of key or null if no such mapping exists.

clear

public void clear()
Empties the map.

Specified by:
clear in interface java.util.Map<K,V>
Overrides:
clear in class FastHash

remove

public V remove(java.lang.Object key)
Deletes a key/value pair from the map.

Specified by:
remove in interface java.util.Map<K,V>
Parameters:
key - an Object value
Returns:
an Object value

removeAt

protected void removeAt(int index)
removes the mapping at index from the map.

Overrides:
removeAt in class FastObjectHash<K>
Parameters:
index - an int value

values

public java.util.Collection<V> values()
Returns a view on the values of the map.

Specified by:
values in interface java.util.Map<K,V>
Returns:
a Collection value

keySet

public java.util.Set<K> keySet()
returns a Set view on the keys of the map.

Specified by:
keySet in interface java.util.Map<K,V>
Returns:
a Set value

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Returns a Set view on the entries of the map.

Specified by:
entrySet in interface java.util.Map<K,V>
Returns:
a Set value

containsValue

public boolean containsValue(java.lang.Object val)
checks for the presence of val in the values of the map.

Specified by:
containsValue in interface java.util.Map<K,V>
Parameters:
val - an Object value
Returns:
a boolean value

containsKey

public boolean containsKey(java.lang.Object key)
checks for the present of key in the keys of the map.

Specified by:
containsKey in interface java.util.Map<K,V>
Parameters:
key - an Object value
Returns:
a boolean value

putAll

public void putAll(java.util.Map<? extends K,? extends V> map)
copies the key/value mappings in map into this map.

Specified by:
putAll in interface java.util.Map<K,V>
Parameters:
map - a Map value

main

public static void main(java.lang.String[] args)
                 throws java.lang.Throwable
Throws:
java.lang.Throwable


Copyright © 2009 The Apache Software Foundation