activemq-cpp-3.9.0
|
This class implements the Set interface, backed by a hash table (actually a HashMap instance). More...
#include <src/main/decaf/util/HashSet.h>
Public Member Functions | |||||||||||
HashSet () | |||||||||||
Constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75). More... | |||||||||||
HashSet (int capacity) | |||||||||||
Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor (0.75). More... | |||||||||||
HashSet (int capacity, float loadFactor) | |||||||||||
Constructs a new instance of. More... | |||||||||||
HashSet (const Collection< E > &collection) | |||||||||||
Constructs a new set containing the elements in the specified collection. More... | |||||||||||
HashSet (const HashSet< E > &collection) | |||||||||||
Constructs a new set containing the elements in the specified HashSet. More... | |||||||||||
virtual | ~HashSet () | ||||||||||
HashSet< E > & | operator= (const Collection< E > &collection) | ||||||||||
virtual bool | add (const E &value) | ||||||||||
Adds the specified element to this set if it is not already present. More... | |||||||||||
virtual void | clear () | ||||||||||
Removes all elements from this. More... | |||||||||||
virtual bool | contains (const E &value) const | ||||||||||
Searches this. More... | |||||||||||
virtual bool | isEmpty () const | ||||||||||
Returns true if this. More... | |||||||||||
virtual Iterator< E > * | iterator () | ||||||||||
Returns an Iterator on the elements of this. More... | |||||||||||
virtual Iterator< E > * | iterator () const | ||||||||||
virtual bool | remove (const E &value) | ||||||||||
Removes the specified element from this set if it is present. More... | |||||||||||
virtual int | size () const | ||||||||||
Returns the number of elements in this. More... | |||||||||||
virtual std::string | toString () const | ||||||||||
![]() | |||||||||||
AbstractSet () | |||||||||||
virtual | ~AbstractSet () | ||||||||||
virtual bool | removeAll (const Collection< E > &collection) | ||||||||||
Removes all this collection's elements that are also contained in the specified collection (optional operation).After this call returns, this collection will contain no elements in common with the specified collection.
| |||||||||||
![]() | |||||||||||
virtual | ~Set () | ||||||||||
![]() | |||||||||||
virtual | ~Collection () | ||||||||||
![]() | |||||||||||
virtual | ~Iterable () | ||||||||||
![]() | |||||||||||
virtual | ~Synchronizable () | ||||||||||
![]() | |||||||||||
AbstractCollection () | |||||||||||
AbstractCollection (const AbstractCollection &other) | |||||||||||
Copy Constructor, copy element from the source collection to this collection after clearing any element stored in this collection. More... | |||||||||||
virtual | ~AbstractCollection () | ||||||||||
AbstractCollection< E > & | operator= (const AbstractCollection< E > &collection) | ||||||||||
Assignment Operator, copy element from the source collection to this collection after clearing any element stored in this collection. More... | |||||||||||
virtual bool | containsAll (const Collection< E > &collection) const | ||||||||||
Returns true if this collection contains all of the elements in the specified collection.
| |||||||||||
virtual bool | equals (const Collection< E > &collection) const | ||||||||||
Answers true if this Collection and the one given are the same size and if each element contained in the Collection given is equal to an element contained in this collection. More... | |||||||||||
virtual void | copy (const Collection< E > &collection) | ||||||||||
Renders this Collection as a Copy of the given Collection. More... | |||||||||||
virtual bool | add (const E &value DECAF_UNUSED) | ||||||||||
virtual bool | addAll (const Collection< E > &collection) | ||||||||||
Adds all of the elements in the specified collection to this collection.The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.)
| |||||||||||
virtual bool | retainAll (const Collection< E > &collection) | ||||||||||
Retains only the elements in this collection that are contained in the specified collection (optional operation).In other words, removes from this collection all of its elements that are not contained in the specified collection.
| |||||||||||
virtual std::vector< E > | toArray () const | ||||||||||
Answers an STL vector containing copies of all elements contained in this Collection. More... | |||||||||||
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... | |||||||||||
Protected Member Functions | |
HashSet (HashMap< E, Set< E > *, HASHCODE > *backingMap) | |
Protected constructor for use by subclasses that wish to use an alternate type of backing Map. More... | |
Protected Attributes | |
HashMap< E, Set< E > *, HASHCODE > * | backingMap |
![]() | |
util::concurrent::Mutex | mutex |
This class implements the Set interface, backed by a hash table (actually a HashMap instance).
It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.
This class offers constant time performance for the basic operations (add, remove, contains and size), assuming the hash function disperses the elements properly among the buckets. Iterating over this set requires time proportional to the sum of the HashSet instance's size (the number of elements) plus the "capacity" of the backing HashMap instance (the number of buckets). Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important.
Note that this implementation is not synchronized. If multiple threads access a hash set concurrently, and at least one of the threads modifies the set, it must be synchronized externally. This is typically accomplished by synchronizing on some object that naturally encapsulates the set. If no such object exists, the set should be "wrapped" using the Collections::synchronizedSet method. This is best done at creation time, to prevent accidental unsynchronized access to the set:
Set<E>* s = Collections::synchronizedSet(new HashSet<E>(...));
The iterators returned by this class's iterator method are fail-fast: if the set is modified at any time after the iterator is created, in any way except through the iterator's own remove method, the Iterator throws 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 a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75).
|
inline |
|
inline |
|
inline |
Constructs a new set containing the elements in the specified collection.
The HashMap is created with default load factor (0.75) and an initial capacity sufficient to contain the elements in the specified collection.
collection | The collection of elements to add to this HashSet. |
References decaf::util::HashSet< E, HASHCODE >::add(), decaf::util::HashSet< E, HASHCODE >::backingMap, decaf::lang::Iterable< E >::iterator(), and decaf::util::Collection< E >::size().
|
inline |
Constructs a new set containing the elements in the specified HashSet.
The HashMap is created with default load factor (0.75) and an initial capacity sufficient to contain the elements in the specified collection.
collection | The collection of elements to add to this HashSet. |
References decaf::util::HashSet< E, HASHCODE >::add(), decaf::util::HashSet< E, HASHCODE >::backingMap, decaf::util::HashSet< E, HASHCODE >::iterator(), and decaf::util::HashSet< E, HASHCODE >::size().
|
inlinevirtual |
References decaf::util::HashSet< E, HASHCODE >::backingMap, and DECAF_CATCHALL_NOTHROW.
|
inlineprotected |
|
inlinevirtual |
Adds the specified element to this set if it is not already present.
More formally, adds the specified element e to this set if this set contains no element e2 such that (e == e2). If this set already contains the element, the call leaves the set unchanged and returns false.
value | The object to add. |
Implements decaf::util::Collection< E >.
References decaf::util::HashSet< E, HASHCODE >::backingMap.
Referenced by decaf::util::HashSet< E, HASHCODE >::HashSet(), and decaf::util::LinkedHashSet< E, HASHCODE >::LinkedHashSet().
|
inlinevirtual |
Removes all elements from this.
, leaving it empty.
Reimplemented from decaf::util::AbstractCollection< E >.
References decaf::util::HashSet< E, HASHCODE >::backingMap.
Referenced by decaf::util::HashSet< E, HASHCODE >::operator=().
|
inlinevirtual |
Searches this.
for the specified object.
value | the object to search for. |
Reimplemented from decaf::util::AbstractCollection< E >.
References decaf::util::HashSet< E, HASHCODE >::backingMap.
|
inlinevirtual |
Returns true if this.
has no elements, false otherwise.
Reimplemented from decaf::util::AbstractCollection< E >.
References decaf::util::HashSet< E, HASHCODE >::backingMap.
|
inlinevirtual |
Returns an Iterator on the elements of this.
.
Implements decaf::lang::Iterable< E >.
References decaf::util::HashSet< E, HASHCODE >::backingMap.
Referenced by decaf::util::HashSet< E, HASHCODE >::HashSet().
|
inlinevirtual |
Implements decaf::lang::Iterable< E >.
References decaf::util::HashSet< E, HASHCODE >::backingMap.
|
inline |
|
inlinevirtual |
Removes the specified element from this set if it is present.
More formally, removes an element e such that (e == value), if this set contains such an element. Returns true if this set contained the element (or equivalently, if this set changed as a result of the call). (This set will not contain the element once the call returns.)
value | The value to remove from this set. |
Reimplemented from decaf::util::AbstractCollection< E >.
References decaf::util::HashSet< E, HASHCODE >::backingMap.
|
inlinevirtual |
Returns the number of elements in this.
.
Implements decaf::util::Collection< E >.
References decaf::util::HashSet< E, HASHCODE >::backingMap.
Referenced by decaf::util::HashSet< E, HASHCODE >::HashSet(), and decaf::util::HashSet< E, HASHCODE >::toString().
|
inlinevirtual |
Reimplemented in decaf::util::LinkedHashSet< E, HASHCODE >.
References decaf::util::HashSet< E, HASHCODE >::size(), and decaf::lang::Integer::toString().
|
protected |
Referenced by decaf::util::HashSet< E, HASHCODE >::add(), decaf::util::HashSet< E, HASHCODE >::clear(), decaf::util::HashSet< E, HASHCODE >::contains(), decaf::util::HashSet< E, HASHCODE >::HashSet(), decaf::util::HashSet< E, HASHCODE >::isEmpty(), decaf::util::HashSet< E, HASHCODE >::iterator(), decaf::util::HashSet< E, HASHCODE >::remove(), decaf::util::HashSet< E, HASHCODE >::size(), and decaf::util::HashSet< E, HASHCODE >::~HashSet().