activemq-cpp-3.9.0
|
Hashed and linked list implementation of the Map interface, with predictable iteration order. More...
#include <src/main/decaf/util/LinkedHashMap.h>
Public Member Functions | |
LinkedHashMap () | |
Constructs an empty insertion-ordered LinkedHashMap instance with the default initial capacity (16) and load factor (0.75). More... | |
LinkedHashMap (int capacity) | |
Constructs a new LinkedHashMap instance with the specified capacity. More... | |
LinkedHashMap (int capacity, float load) | |
Constructs a new. More... | |
LinkedHashMap (int capacity, float load, bool order) | |
Constructs a new. More... | |
LinkedHashMap (const HashMap< K, V > &map) | |
Constructs a new LinkedHashMap instance containing the mappings from the specified map. More... | |
virtual | ~LinkedHashMap () |
virtual bool | containsValue (const V &value) const |
Returns true if this map maps one or more keys to the specified value. More... | |
virtual void | clear () |
Removes all of the mappings from this map (optional operation). More... | |
virtual bool | put (const K &key, const V &value) |
Associates the specified value with the specified key in this map (optional operation). More... | |
virtual bool | put (const K &key, const V &value, V &oldValue) |
Associates the specified value with the specified key in this map (optional operation). More... | |
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. More... | |
virtual Set< MapEntry< K, V > > & | entrySet () |
Returns a Set view of the mappings contained in this map. More... | |
virtual const Set< MapEntry< K, V > > & | entrySet () const |
virtual Set< K > & | keySet () |
Returns a Set view of the keys contained in this map. More... | |
virtual const Set< K > & | keySet () const |
virtual Collection< V > & | values () |
Returns a Collection view of the values contained in this map. More... | |
virtual const Collection< V > & | values () const |
virtual std::string | toString () const |
![]() | |
HashMap () | |
Creates a new empty HashMap with default configuration settings. More... | |
HashMap (int capacity) | |
Constructs a new HashMap instance with the specified capacity. More... | |
HashMap (int capacity, float loadFactor) | |
Constructs a new HashMap instance with the specified capacity. More... | |
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. More... | |
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. More... | |
virtual | ~HashMap () |
HashMap< K, V > & | operator= (const Map< K, V > &other) |
HashMap< K, V > & | operator= (const HashMap< K, V > &other) |
bool | operator== (const Map< K, V > &other) const |
bool | operator!= (const Map< K, V > &other) const |
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. More... | |
virtual V & | get (const K &key) |
Gets the value mapped to the specified key in the Map. More... | |
virtual const V & | get (const K &key) const |
Gets the value mapped to the specified key in the Map. More... | |
virtual void | putAll (const Map< K, V > &map) |
Copies all of the mappings from the specified map to this map (optional operation). More... | |
virtual bool | equals (const Map< K, V > &source) const |
Compares the specified object with this map for equality. More... | |
virtual void | copy (const Map< K, V > &source) |
Copies the content of the source map into this map. More... | |
![]() | |
AbstractMap () | |
AbstractMap (const Map< K, V > &map DECAF_UNUSED) | |
AbstractMap (const AbstractMap< K, V > &map DECAF_UNUSED) | |
virtual | ~AbstractMap () |
virtual void | lock () |
Locks the object. More... | |
virtual bool | tryLock () |
Attempts to Lock the object, if the lock is already held by another thread than this method returns false. More... | |
virtual void | unlock () |
Unlocks the object. More... | |
virtual void | wait () |
Waits on a signal from this object, which is generated by a call to Notify. More... | |
virtual void | wait (long long millisecs) |
Waits on a signal from this object, which is generated by a call to Notify. More... | |
virtual void | wait (long long millisecs, int nanos) |
Waits on a signal from this object, which is generated by a call to Notify. More... | |
virtual void | notify () |
Signals a waiter on this object that it can now wake up and continue. More... | |
virtual void | notifyAll () |
Signals the waiters on this object that it can now wake up and continue. More... | |
![]() | |
Map () | |
Default constructor - does nothing. More... | |
virtual | ~Map () |
![]() | |
virtual | ~Synchronizable () |
Protected Member Functions | |
virtual bool | removeEldestEntry (const MapEntry< K, V > &eldest DECAF_UNUSED) |
This method is queried from the put and putAll methods to check if the eldest member of the map should be deleted before adding the new member. More... | |
virtual void | onEviction (const MapEntry< K, V > &eldest DECAF_UNUSED) |
This method is called when the removeEldestEntry has returned true and a MapEntry is about to be removed from the Map. More... | |
virtual LinkedHashMapEntry * | getEntry (const K &key) const |
virtual HashMap< K, V, HASHCODE >::HashMapEntry * | createEntry (const K &key, int index, const V &value) |
virtual HashMap< K, V, HASHCODE >::HashMapEntry * | createHashedEntry (const K &key, int index, int hash) |
void | linkEntry (LinkedHashMapEntry *entry) |
virtual bool | putImpl (const K &key, const V &value) |
virtual bool | putImpl (const K &key, const V &value, V &oldValue) |
![]() | |
void | putAllImpl (const Map< K, V > &map) |
HashMapEntry * | findKeyEntry (const K &key, int index, int keyHash) const |
void | rehash (int capacity) |
void | rehash () |
void | removeEntry (HashMapEntry *entry) |
HashMapEntry * | removeEntry (const K &key) |
Additional Inherited Members | |
![]() | |
HASHCODE | hashFunc |
The Hash Code generator for this map's keys. More... | |
int | elementCount |
decaf::lang::ArrayPointer < HashMapEntry * > | elementData |
int | modCount |
float | loadFactor |
int | threshold |
decaf::lang::Pointer < HashMapEntrySet > | cachedEntrySet |
decaf::lang::Pointer < HashMapKeySet > | cachedKeySet |
decaf::lang::Pointer < HashMapValueCollection > | cachedValueCollection |
decaf::lang::Pointer < ConstHashMapEntrySet > | cachedConstEntrySet |
decaf::lang::Pointer < ConstHashMapKeySet > | cachedConstKeySet |
decaf::lang::Pointer < ConstHashMapValueCollection > | cachedConstValueCollection |
![]() | |
util::concurrent::Mutex | mutex |
Hashed and linked list implementation of the Map interface, with predictable iteration order.
This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order). Note that insertion order is not affected if a key is re-inserted into the map. (A key k is reinserted into a map m if m.put(k, v) is invoked when m.containsKey(k) would return true immediately prior to the invocation.)
This implementation spares its clients from the unspecified, generally chaotic ordering provided by HashMap, without incurring the increased cost associated with TreeMap. It can be used to produce a copy of a map that has the same order as the original, regardless of the original map's implementation:
void foo(Map m) { Map copy = new LinkedHashMap(m); ... }
This technique is particularly useful if a module takes a map on input, copies it, and later returns results whose order is determined by that of the copy. (Clients generally appreciate having things returned in the same order they were presented.)
A special constructor is provided to create a linked hash map whose order of iteration is the order in which its entries were last accessed, from least-recently accessed to most-recently (access-order). This kind of map is well-suited to building LRU caches. Invoking the put or get method results in an access to the corresponding entry (assuming it exists after the invocation completes). The putAll method generates one entry access for each mapping in the specified map, in the order that key-value mappings are provided by the specified map's entry set iterator. No other methods generate entry accesses. In particular, operations on collection-views do not affect the order of iteration of the backing map.
The removeEldestEntry(MapEntry) method may be overridden to impose a policy for removing stale mappings automatically when new mappings are added to the map. When the entries are about to be removed from the map the onEviction method is called giving subclasses a chance to delete pointer values or perform other cleanup prior to the mapping being removed.
This class provides all of the optional Map operations. Like HashMap, it provides constant-time performance for the basic operations (add, contains and remove), assuming the hash function disperses elements properly among the buckets. Performance is likely to be just slightly below that of HashMap, due to the added expense of maintaining the linked list, with one exception: Iteration over the collection-views of a LinkedHashMap requires time proportional to the size of the map, regardless of its capacity. Iteration over a HashMap is likely to be more expensive, requiring time proportional to its capacity.
A linked hash map has two parameters that affect its performance: initial capacity and load factor. They are defined precisely as for HashMap. Note, however, that the penalty for choosing an excessively high value for initial capacity is less severe for this class than for HashMap, as iteration times for this class are unaffected by capacity.
Note that this implementation is not synchronized. If multiple threads access a linked hash map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. 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>* m = Collections::synchronizedMap(new LinkedHashMap(...));
A structural modification is any operation that adds or deletes one or more mappings or, in the case of access-ordered linked hash maps, affects iteration order. In insertion-ordered linked hash maps, merely changing the value associated with a key that is already contained in the map is not a structural modification. In access-ordered linked hash maps, merely querying the map with get is a structural modification.)
The iterators returned by the iterator method of the collections 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 |
Constructs an empty insertion-ordered LinkedHashMap instance with the default initial capacity (16) and load factor (0.75).
|
inline |
Constructs a new LinkedHashMap instance with the specified capacity.
capacity | The initial capacity of this map. |
IllegalArgumentException | if the capacity is less than zero. |
|
inline |
Constructs a new.
instance with the specified capacity and load factor.
capacity | The initial capacity of this map. |
load | The initial load factor for this map. |
IllegalArgumentException | If the capacity is less than zero or the load factor is less or equal to zero. |
|
inline |
Constructs a new.
instance with the specified capacity, load factor and a flag specifying the ordering behavior.
capacity | The initial capacity of this map. |
load | The initial load factor for this map. |
order | True if the ordering should be done based on the last access (from least-recently accessed to most-recently accessed), and false if the ordering should be the order in which the entries were inserted. |
IllegalArgumentException | If the capacity is less than zero or the load factor is less or equal to zero. |
|
inline |
Constructs a new LinkedHashMap instance containing the mappings from the specified map.
The order of the elements is preserved.
map | The mappings to add to this Map instance. |
|
inlinevirtual |
|
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. |
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References decaf::util::HashMap< K, V, HASHCODE >::clear(), 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. |
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References NULL.
|
inlineprotectedvirtual |
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References decaf::util::HashMap< K, V, HASHCODE >::elementData, and decaf::util::LinkedHashMap< K, V, HASHCODE >::linkEntry().
|
inlineprotectedvirtual |
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References decaf::util::HashMap< K, V, HASHCODE >::elementData, and decaf::util::LinkedHashMap< K, V, HASHCODE >::linkEntry().
Referenced by decaf::util::LinkedHashMap< 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.
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References decaf::util::HashMap< K, V, HASHCODE >::cachedEntrySet, and NULL.
|
inlinevirtual |
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References decaf::util::HashMap< K, V, HASHCODE >::cachedConstEntrySet, and NULL.
|
inlineprotectedvirtual |
|
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.
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References decaf::util::HashMap< K, V, HASHCODE >::cachedKeySet, and NULL.
|
inlinevirtual |
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References decaf::util::HashMap< K, V, HASHCODE >::cachedConstKeySet, and NULL.
|
inlineprotected |
|
inlineprotectedvirtual |
This method is called when the removeEldestEntry has returned true and a MapEntry is about to be removed from the Map.
This method allows for Maps that contain pointers in their MapEntry object to have a chance to properly delete the pointer when the entry is removed.
Referenced by decaf::util::LinkedHashMap< K, V, HASHCODE >::put().
|
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 |
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References decaf::util::LinkedHashMap< K, V, HASHCODE >::onEviction(), decaf::util::LinkedHashMap< K, V, HASHCODE >::putImpl(), and decaf::util::LinkedHashMap< K, V, HASHCODE >::removeEldestEntry().
|
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 |
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References decaf::util::LinkedHashMap< K, V, HASHCODE >::onEviction(), decaf::util::LinkedHashMap< K, V, HASHCODE >::putImpl(), and decaf::util::LinkedHashMap< K, V, HASHCODE >::removeEldestEntry().
|
inlineprotectedvirtual |
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
Referenced by decaf::util::LinkedHashMap< K, V, HASHCODE >::put().
|
inlineprotectedvirtual |
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References decaf::util::LinkedHashMap< K, V, HASHCODE >::createHashedEntry(), decaf::util::HashMap< K, V, HASHCODE >::elementCount, decaf::util::HashMap< K, V, HASHCODE >::elementData, decaf::util::HashMap< K, V, HASHCODE >::findKeyEntry(), decaf::util::HashMap< K, V, HASHCODE >::hashFunc, decaf::util::LinkedHashMap< K, V, HASHCODE >::linkEntry(), decaf::util::HashMap< K, V, HASHCODE >::modCount, NULL, decaf::util::HashMap< K, V, HASHCODE >::rehash(), and decaf::util::HashMap< K, V, HASHCODE >::threshold.
|
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. |
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References NULL, and decaf::util::HashMap< K, V, HASHCODE >::removeEntry().
|
inlineprotectedvirtual |
This method is queried from the put and putAll methods to check if the eldest member of the map should be deleted before adding the new member.
If this map was created with accessOrder = true, then the result of removeEldestEntry is assumed to be false.
eldest | The entry to check if it should be removed. |
Reimplemented in decaf::util::LRUCache< K, V, HASHCODE >.
Referenced by decaf::util::LinkedHashMap< K, V, HASHCODE >::put().
|
inlinevirtual |
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
|
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.
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References decaf::util::HashMap< K, V, HASHCODE >::cachedValueCollection, and NULL.
|
inlinevirtual |
Reimplemented from decaf::util::HashMap< K, V, HASHCODE >.
References decaf::util::HashMap< K, V, HASHCODE >::cachedConstValueCollection, and NULL.