activemq-cpp-3.6.0
|
Hash table based implementation of the Map interface. More...
#include <src/main/decaf/util/HashMap.h>
Public Member Functions | |
HashMap () | |
Creates a new empty HashMap with default configuration settings. | |
HashMap (int capacity) | |
Constructs a new HashMap instance with the specified capacity. | |
HashMap (int capacity, float loadFactor) | |
Constructs a new HashMap instance with the specified capacity. | |
HashMap (const HashMap< K, V > &map) | |
Creates a new HashMap with default configuration settings and fills it with the contents of the given source Map instance. | |
HashMap (const Map< K, V > &map) | |
Creates a new HashMap with default configuration settings and fills it with the contents of the given source Map instance. | |
virtual | ~HashMap () |
virtual void | clear () |
Removes all of the mappings from this map (optional operation). | |
virtual bool | isEmpty () const |
virtual int | size () const |
virtual bool | containsKey (const K &key) const |
Returns true if this map contains a mapping for the specified key. | |
virtual bool | containsValue (const V &value) const |
Returns true if this map maps one or more keys to the specified value. | |
virtual V & | get (const K &key) |
Gets the value mapped to the specified key in the Map. | |
virtual const V & | get (const K &key) const |
Gets the value mapped to the specified key in the Map. | |
virtual bool | put (const K &key, const V &value) |
Associates the specified value with the specified key in this map (optional operation). | |
virtual bool | put (const K &key, const V &value, V &oldValue) |
Associates the specified value with the specified key in this map (optional operation). | |
virtual void | putAll (const Map< K, V > &map) |
Copies all of the mappings from the specified map to this map (optional operation). | |
virtual V | remove (const K &key) |
Removes the value (key/value pair) for the specified key from the map, returns a copy of the value that was mapped to the key. | |
virtual Set< MapEntry< K, V > > & | entrySet () |
Returns a Set view of the mappings contained in this map. | |
virtual const Set< MapEntry< K, V > > & | entrySet () const |
virtual Set< K > & | keySet () |
Returns a Set view of the keys contained in this map. | |
virtual const Set< K > & | keySet () const |
virtual Collection< V > & | values () |
Returns a Collection view of the values contained in this map. | |
virtual const Collection< V > & | values () const |
virtual bool | equals (const Map< K, V > &source) const |
Compares the specified object with this map for equality. | |
virtual void | copy (const Map< K, V > &source) |
Copies the content of the source map into this map. | |
virtual std::string | toString () const |
![]() | |
AbstractMap () | |
AbstractMap (const Map< K, V > &map) | |
AbstractMap (const AbstractMap< K, V > &map) | |
virtual | ~AbstractMap () |
virtual void | lock () |
Locks the object. | |
virtual bool | tryLock () |
Attempts to Lock the object, if the lock is already held by another thread than this method returns false. | |
virtual void | unlock () |
Unlocks the object. | |
virtual void | wait () |
Waits on a signal from this object, which is generated by a call to Notify. | |
virtual void | wait (long long millisecs) |
Waits on a signal from this object, which is generated by a call to Notify. | |
virtual void | wait (long long millisecs, int nanos) |
Waits on a signal from this object, which is generated by a call to Notify. | |
virtual void | notify () |
Signals a waiter on this object that it can now wake up and continue. | |
virtual void | notifyAll () |
Signals the waiters on this object that it can now wake up and continue. | |
![]() | |
Map () | |
Default constructor - does nothing. | |
virtual | ~Map () |
![]() | |
virtual | ~Synchronizable () |
Protected Member Functions | |
HashMapEntry * | getEntry (const K &key) const |
bool | putImpl (const K &key, const V &value, V &oldValue) |
bool | putImpl (const K &key, const V &value) |
void | putAllImpl (const Map< K, V > &map) |
HashMapEntry * | findKeyEntry (const K &key, int index, int keyHash) const |
void | rehash (int capacity) |
void | rehash () |
HashMapEntry * | createEntry (const K &key, int index, const V &value) |
HashMapEntry * | createHashedEntry (const K &key, int index, int hash) |
void | removeEntry (HashMapEntry *entry) |
HashMapEntry * | removeEntry (const K &key) |
Additional Inherited Members | |
![]() | |
util::concurrent::Mutex | mutex |
Hash table based implementation of the Map interface.
This implementation provides all of the optional map operations, and permits null values and the null key. This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.
This implementation provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets. Iteration over collection views requires time proportional to the "capacity" of the HashMap instance (the number of buckets) plus its size (the number of key-value mappings). Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important.
An instance of HashMap has two parameters that affect its performance: initial capacity and load factor. The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created. The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the hash table is rehashed (that is, internal data structures are rebuilt) so that the hash table has approximately twice the number of buckets.
As a general rule, the default load factor (.75) offers a good tradeoff between time and space costs. Higher values decrease the space overhead but increase the lookup cost (reflected in most of the operations of the HashMap class, including get and put). The expected number of entries in the map and its load factor should be taken into account when setting its initial capacity, so as to minimize the number of rehash operations. If the initial capacity is greater than the maximum number of entries divided by the load factor, no rehash operations will ever occur.
If many mappings are to be stored in a HashMap instance, creating it with a sufficiently large capacity will allow the mappings to be stored more efficiently than letting it perform automatic rehashing as needed to grow the table.
Note that this implementation is not synchronized. If multiple threads access a hash map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with a key that an instance already contains is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map. If no such object exists, the map should be "wrapped" using the Collections::synchronizedMap method. This is best done at creation time, to prevent accidental unsynchronized access to the map:
Map<K, V>* map = Collections::synchronizedMap(new HashMap<K, V>());
The iterators returned by all of this class's "collection view methods" are fail-fast: if the map is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove method, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.
Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: the fail-fast behavior of iterators should be used only to detect bugs.
|
inline |
Creates a new empty HashMap with default configuration settings.
|
inline |
Constructs a new HashMap instance with the specified capacity.
capacity | The initial capacity of this hash map. |
IllegalArgumentException | when the capacity is less than zero. |
|
inline |
Constructs a new HashMap instance with the specified capacity.
capacity | The initial capacity of this hash map. |
loadFactor | The load factor to use for this hash map. |
IllegalArgumentException | when the capacity is less than zero. |
|
inline |
Creates a new HashMap with default configuration settings and fills it with the contents of the given source Map instance.
References decaf::util::HashMap< K, V, HASHCODE >::putAll(), and decaf::util::HashMap< K, V, HASHCODE >::size().
|
inline |
Creates a new HashMap with default configuration settings and fills it with the contents of the given source Map instance.
References decaf::util::HashMap< K, V, HASHCODE >::putAll(), and decaf::util::Map< K, V >::size().
|
inlinevirtual |
References decaf::lang::ArrayPointer< T >::length(), and NULL.
|
inlinevirtual |
Removes all of the mappings from this map (optional operation).
The map will be empty after this call returns.
UnsupportedOperationException | if the clear operation is not supported by this map. |
Implements decaf::util::Map< K, V >.
References decaf::lang::ArrayPointer< T >::length(), and NULL.
Referenced by decaf::util::HashMap< K, V, HASHCODE >::copy().
|
inlinevirtual |
Returns true if this map contains a mapping for the specified key.
More formally, returns true if and only if this map contains a mapping for a key k such that (key == k). (There can be at most one such mapping.)
key | The key to look up. |
Implements decaf::util::Map< K, V >.
References decaf::util::HashMap< K, V, HASHCODE >::getEntry(), and NULL.
|
inlinevirtual |
Returns true if this map maps one or more keys to the specified value.
More formally, returns true if and only if this map contains at least one mapping to a value v such that (value==v). This operation will probably require time linear in the map size for most implementations of the Map interface.
value | The Value to look up in this Map. |
Implements decaf::util::Map< K, V >.
References decaf::lang::ArrayPointer< T >::length(), and NULL.
|
inlinevirtual |
Copies the content of the source map into this map.
Erases all existing mappings in this map. The copy is performed by using the entrySet of the source Map and iterating over those entries, inserting each into the target.
source | The source object to copy from. |
Implements decaf::util::Map< K, V >.
References decaf::util::HashMap< K, V, HASHCODE >::clear(), decaf::lang::ArrayPointer< T >::length(), decaf::util::HashMap< K, V, HASHCODE >::putAll(), and decaf::util::Map< K, V >::size().
|
inlineprotected |
|
inlineprotected |
Referenced by decaf::util::HashMap< K, V, HASHCODE >::putImpl().
|
inlinevirtual |
Returns a Set view of the mappings contained in this map.
The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.
Implements decaf::util::Map< K, V >.
References NULL, and decaf::lang::Pointer< T, REFCOUNTER >::reset().
|
inlinevirtual |
Implements decaf::util::Map< K, V >.
References NULL, and decaf::lang::Pointer< T, REFCOUNTER >::reset().
|
inlinevirtual |
Compares the specified object with this map for equality.
Returns true if the two maps represent the same mappings. More formally, two maps m1 and m2 represent the same mappings if m1.entrySet().equals(m2.entrySet()). This ensures that the equals method works properly across different implementations of the Map interface.
source | Map to compare to this one. |
Implements decaf::util::Map< K, V >.
|
inlineprotected |
References NULL.
Referenced by decaf::util::HashMap< K, V, HASHCODE >::getEntry(), and decaf::util::HashMap< K, V, HASHCODE >::putImpl().
|
inlinevirtual |
Gets the value mapped to the specified key in the Map.
If there is no element in the map whose key is equivalent to the key provided then a NoSuchElementException is thrown.
key | The search key whose value should be returned if present. |
NoSuchElementException | if the key requests doesn't exist in the Map. |
Implements decaf::util::Map< K, V >.
References decaf::util::HashMap< K, V, HASHCODE >::getEntry(), and NULL.
|
inlinevirtual |
Gets the value mapped to the specified key in the Map.
If there is no element in the map whose key is equivalent to the key provided then a NoSuchElementException is thrown.
key | The search key whose value should be returned if present. |
NoSuchElementException | if the key requests doesn't exist in the Map. |
Implements decaf::util::Map< K, V >.
References decaf::util::HashMap< K, V, HASHCODE >::getEntry(), and NULL.
|
inlineprotected |
|
inlinevirtual |
Implements decaf::util::Map< K, V >.
|
inlinevirtual |
Returns a Set view of the keys contained in this map.
The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
Implements decaf::util::Map< K, V >.
References NULL, and decaf::lang::Pointer< T, REFCOUNTER >::reset().
|
inlinevirtual |
Implements decaf::util::Map< K, V >.
References NULL, and decaf::lang::Pointer< T, REFCOUNTER >::reset().
|
inlinevirtual |
Associates the specified value with the specified key in this map (optional operation).
If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)
key | The target key. |
value | The value to be set. |
UnsupportedOperationException | if this map is unmodifiable. |
IllegalArgumentException | if some property of the specified key or value prevents it from being stored in this map |
Implements decaf::util::Map< K, V >.
References decaf::util::HashMap< K, V, HASHCODE >::putImpl().
|
inlinevirtual |
Associates the specified value with the specified key in this map (optional operation).
If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)
This method accepts a reference to a value which will be assigned the previous value for the given key (if any). If there was no previous mapping for the given key the out value is not written to. A return of true indicates that a value was replaced by this put operation.
key | The target key. |
value | The value to be set. |
oldValue | (out) The value previously held in the mapping for this key. . |
UnsupportedOperationException | if this map is unmodifiable. |
IllegalArgumentException | if some property of the specified key or value prevents it from being stored in this map |
Implements decaf::util::Map< K, V >.
References decaf::util::HashMap< K, V, HASHCODE >::putImpl().
|
inlinevirtual |
Copies all of the mappings from the specified map to this map (optional operation).
The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress.
UnsupportedOperationException | If the implementing class does not support the putAll operation. |
Implements decaf::util::Map< K, V >.
References decaf::util::Map< K, V >::isEmpty(), and decaf::util::HashMap< K, V, HASHCODE >::putAllImpl().
Referenced by decaf::util::HashMap< K, V, HASHCODE >::copy(), and decaf::util::HashMap< K, V, HASHCODE >::HashMap().
|
inlineprotected |
References decaf::util::Map< K, V >::entrySet(), decaf::util::MapEntry< K, V >::getKey(), decaf::util::MapEntry< K, V >::getValue(), decaf::util::HashMap< K, V, HASHCODE >::putImpl(), decaf::util::HashMap< K, V, HASHCODE >::rehash(), and decaf::util::Map< K, V >::size().
Referenced by decaf::util::HashMap< K, V, HASHCODE >::putAll().
|
inlineprotected |
References decaf::util::HashMap< K, V, HASHCODE >::createHashedEntry(), decaf::util::HashMap< K, V, HASHCODE >::findKeyEntry(), decaf::lang::ArrayPointer< T >::length(), NULL, and decaf::util::HashMap< K, V, HASHCODE >::rehash().
Referenced by decaf::util::HashMap< K, V, HASHCODE >::put(), and decaf::util::HashMap< K, V, HASHCODE >::putAllImpl().
|
inlineprotected |
|
inlineprotected |
References decaf::lang::ArrayPointer< T >::length(), and NULL.
|
inlineprotected |
|
inlinevirtual |
Removes the value (key/value pair) for the specified key from the map, returns a copy of the value that was mapped to the key.
Care must be taken when using this operation as it will throw an exception if there is no mapping for the given key.
key | The search key whose mapping is to be removed. |
NoSuchElementException | if this key is not in the Map. |
UnsupportedOperationException | if this map is unmodifiable. |
Implements decaf::util::Map< K, V >.
References NULL, and decaf::util::HashMap< K, V, HASHCODE >::removeEntry().
|
inlineprotected |
References decaf::lang::ArrayPointer< T >::length().
Referenced by decaf::util::HashMap< K, V, HASHCODE >::remove().
|
inlineprotected |
References decaf::lang::ArrayPointer< T >::length(), and NULL.
|
inlinevirtual |
Implements decaf::util::Map< K, V >.
Referenced by decaf::util::HashMap< K, V, HASHCODE >::HashMap().
|
inlinevirtual |
|
inlinevirtual |
Returns a Collection view of the values contained in this map.
The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations. For the const version of this method the Collection can only be used as a view into the Map.
Implements decaf::util::Map< K, V >.
References NULL, and decaf::lang::Pointer< T, REFCOUNTER >::reset().
|
inlinevirtual |
Implements decaf::util::Map< K, V >.
References NULL, and decaf::lang::Pointer< T, REFCOUNTER >::reset().