|
activemq-cpp-3.9.5
|
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). | |||||||||||
| HashSet (int capacity) | |||||||||||
| Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor (0.75). | |||||||||||
| HashSet (int capacity, float loadFactor) | |||||||||||
Constructs a new instance of HashSet with the specified capacity and load factor. | |||||||||||
| HashSet (const Collection< E > &collection) | |||||||||||
| Constructs a new set containing the elements in the specified collection. | |||||||||||
| HashSet (const HashSet< E > &collection) | |||||||||||
| Constructs a new set containing the elements in the specified HashSet. | |||||||||||
| 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. | |||||||||||
| virtual void | clear () | ||||||||||
Removes all elements from this HashSet, leaving it empty. | |||||||||||
| virtual bool | contains (const E &value) const | ||||||||||
Searches this HashSet for the specified object. | |||||||||||
| virtual bool | isEmpty () const | ||||||||||
Returns true if this HashSet has no elements, false otherwise. | |||||||||||
| virtual Iterator< E > * | iterator () | ||||||||||
Returns an Iterator on the elements of this HashSet. | |||||||||||
| virtual Iterator< E > * | iterator () const | ||||||||||
| virtual bool | remove (const E &value) | ||||||||||
| Removes the specified element from this set if it is present. | |||||||||||
| virtual int | size () const | ||||||||||
Returns the number of elements in this HashSet. | |||||||||||
| virtual std::string | toString () const | ||||||||||
Public Member Functions inherited from decaf::util::AbstractSet< E > | |||||||||||
| 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.
| |||||||||||
Public Member Functions inherited from decaf::util::Set< E > | |||||||||||
| virtual | ~Set () | ||||||||||
Public Member Functions inherited from decaf::util::Collection< E > | |||||||||||
| virtual | ~Collection () | ||||||||||
| virtual void | copy (const Collection< E > &collection)=0 | ||||||||||
| Renders this Collection as a Copy of the given Collection. | |||||||||||
| virtual bool | add (const E &value)=0 | ||||||||||
| Returns true if this collection changed as a result of the call. | |||||||||||
| virtual bool | addAll (const Collection< E > &collection)=0 | ||||||||||
| Adds all of the elements in the specified collection to this collection. | |||||||||||
| virtual void | clear ()=0 | ||||||||||
| Removes all of the elements from this collection (optional operation). | |||||||||||
| virtual bool | contains (const E &value) const =0 | ||||||||||
| Returns true if this collection contains the specified element. | |||||||||||
| virtual bool | containsAll (const Collection< E > &collection) const =0 | ||||||||||
| Returns true if this collection contains all of the elements in the specified collection. | |||||||||||
| virtual bool | equals (const Collection< E > &value) const =0 | ||||||||||
| Compares the passed collection to this one, if they contain the same elements, i.e. | |||||||||||
| virtual bool | isEmpty () const =0 | ||||||||||
| virtual bool | remove (const E &value)=0 | ||||||||||
| Removes a single instance of the specified element from the collection. | |||||||||||
| virtual bool | removeAll (const Collection< E > &collection)=0 | ||||||||||
| Removes all this collection's elements that are also contained in the specified collection (optional operation). | |||||||||||
| virtual bool | retainAll (const Collection< E > &collection)=0 | ||||||||||
| Retains only the elements in this collection that are contained in the specified collection (optional operation). | |||||||||||
| virtual int | size () const =0 | ||||||||||
| Returns the number of elements in this collection. | |||||||||||
| virtual std::vector< E > | toArray () const =0 | ||||||||||
| Returns an array containing all of the elements in this collection. | |||||||||||
Public Member Functions inherited from decaf::lang::Iterable< E > | |||||||||||
| virtual | ~Iterable () | ||||||||||
| virtual decaf::util::Iterator< E > * | iterator ()=0 | ||||||||||
| virtual decaf::util::Iterator< E > * | iterator () const =0 | ||||||||||
Public Member Functions inherited from decaf::util::concurrent::Synchronizable | |||||||||||
| virtual | ~Synchronizable () | ||||||||||
| virtual void | lock ()=0 | ||||||||||
| Locks the object. | |||||||||||
| virtual bool | tryLock ()=0 | ||||||||||
| Attempts to Lock the object, if the lock is already held by another thread than this method returns false. | |||||||||||
| virtual void | unlock ()=0 | ||||||||||
| Unlocks the object. | |||||||||||
| virtual void | wait ()=0 | ||||||||||
| Waits on a signal from this object, which is generated by a call to Notify. | |||||||||||
| virtual void | wait (long long millisecs)=0 | ||||||||||
| Waits on a signal from this object, which is generated by a call to Notify. | |||||||||||
| virtual void | wait (long long millisecs, int nanos)=0 | ||||||||||
| Waits on a signal from this object, which is generated by a call to Notify. | |||||||||||
| virtual void | notify ()=0 | ||||||||||
| Signals a waiter on this object that it can now wake up and continue. | |||||||||||
| virtual void | notifyAll ()=0 | ||||||||||
| Signals the waiters on this object that it can now wake up and continue. | |||||||||||
Public Member Functions inherited from decaf::util::AbstractCollection< E > | |||||||||||
| AbstractCollection () | |||||||||||
| AbstractCollection (const AbstractCollection &other) | |||||||||||
| Copy Constructor, copy element from the source collection to this collection after clearing any element stored in this collection. | |||||||||||
| 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. | |||||||||||
| virtual void | clear () | ||||||||||
| Removes all of the elements from this collection (optional operation). | |||||||||||
| virtual bool | contains (const E &value) const | ||||||||||
Returns true if this collection contains the specified element.More formally, returns true if and only if this collection contains at least one element e such that (value == NULL ? e == NULL : value == e ).
| |||||||||||
| 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. | |||||||||||
| virtual void | copy (const Collection< E > &collection) | ||||||||||
| Renders this Collection as a Copy of the given Collection. | |||||||||||
| virtual bool | isEmpty () const | ||||||||||
| Returns true if this collection contains no elements. | |||||||||||
| 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 | remove (const E &value) | ||||||||||
Removes a single instance of the specified element from the collection.More formally, removes an element e such that (value == NULL ? e == NULL : value == e), if this collection contains one or more such elements. Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).
| |||||||||||
| 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 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. | |||||||||||
| 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. | |||||||||||
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. | |
Protected Attributes | |
| HashMap< E, Set< E > *, HASHCODE > * | backingMap |
Protected Attributes inherited from decaf::util::AbstractCollection< E > | |
| 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::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 >::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::HashMap< K, V, HASHCODE >::put().
Referenced by decaf::util::HashSet< E, HASHCODE >::HashSet(), and decaf::util::LinkedHashSet< E, HASHCODE >::LinkedHashSet().
|
inlinevirtual |
Removes all elements from this HashSet, leaving it empty.
Reimplemented from decaf::util::AbstractCollection< E >.
References decaf::util::HashMap< K, V, HASHCODE >::clear().
Referenced by decaf::util::HashSet< E, HASHCODE >::operator=().
|
inlinevirtual |
Searches this HashSet for the specified object.
| value | the object to search for. |
true if object is an element of this HashSet, false otherwise. Reimplemented from decaf::util::AbstractCollection< E >.
References decaf::util::HashMap< K, V, HASHCODE >::containsKey().
|
inlinevirtual |
Returns true if this HashSet has no elements, false otherwise.
true if this HashSet has no elements, false otherwise. Reimplemented from decaf::util::AbstractCollection< E >.
References decaf::util::HashMap< K, V, HASHCODE >::isEmpty().
|
inlinevirtual |
Returns an Iterator on the elements of this HashSet.
HashSet. Implements decaf::lang::Iterable< E >.
References decaf::lang::Iterable< E >::iterator(), and decaf::util::HashMap< K, V, HASHCODE >::keySet().
Referenced by decaf::util::HashSet< E, HASHCODE >::HashSet().
|
inlinevirtual |
Implements decaf::lang::Iterable< E >.
References decaf::lang::Iterable< E >::iterator(), and decaf::util::HashMap< K, V, HASHCODE >::keySet().
|
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::HashMap< K, V, HASHCODE >::remove().
|
inlinevirtual |
Returns the number of elements in this HashSet.
HashSet. Implements decaf::util::Collection< E >.
References decaf::util::HashMap< K, V, HASHCODE >::size().
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 >::~HashSet().