cdx
Class CHashMap

java.lang.Object
  extended by cdx.CHashMap

public class CHashMap
extends java.lang.Object

We note that the key and value of a map entry must not be null.


Constructor Summary
CHashMap(int initialCapacity)
          Constructs a new CHashMap with a specific initial capacity.
 
Method Summary
 java.lang.Object get(java.lang.Object key)
          Returns the value in this CHashMap associated with the supplied key, or null if no mapping for the key exists in the map.
 java.util.Set keySet()
          Returns all keys within the hash map as a Set.
 void put(java.lang.Object key, java.lang.Object value)
          Puts the supplied value into the Map, stored under the supplied key.
 java.lang.Object remove(java.lang.Object key)
          Removes an value from the map that is associated with a given key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CHashMap

public CHashMap(int initialCapacity)
Constructs a new CHashMap with a specific initial capacity. This pre-allocates memory for a respective number of entries.

Parameters:
initialCapacity - the initial capacity of this CHashMap
Method Detail

get

public java.lang.Object get(java.lang.Object key)
Returns the value in this CHashMap associated with the supplied key, or null if no mapping for the key exists in the map.

Parameters:
key - the key for which to fetch an associated value
Returns:
value that the key maps to, if present

put

public void put(java.lang.Object key,
                java.lang.Object value)
Puts the supplied value into the Map, stored under the supplied key.

Parameters:
key - the key under which the value is stored
value - the value to be stored in the HashMap

remove

public java.lang.Object remove(java.lang.Object key)
Removes an value from the map that is associated with a given key.

Parameters:
key - the key of the value to be remove from the map
Returns:
the removed value

keySet

public java.util.Set keySet()
Returns all keys within the hash map as a Set. The implementation is not very efficient here as it traverses the table array index by index. However, for the sake of our example this may be sufficient; a more efficient implementation would back the map by a key and value set. We note that this method allocates memory in whatever scope it is called, namely for the Set object returned.

Returns:
keys within the hash map viewed as a Set