activemq-cpp-3.9.0
decaf::util::HashSet< E, HASHCODE > Class Template Reference

This class implements the Set interface, backed by a hash table (actually a HashMap instance). More...

#include <src/main/decaf/util/HashSet.h>

Inheritance diagram for decaf::util::HashSet< E, HASHCODE >:

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
 
- 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.
Parameters
collectionThe Collection whose elements are to be removed from this one.
Returns
true if the collection changed as a result of this call.
Exceptions
UnsupportedOperationExceptioif this is an unmodifiable collection.
NullPointerExceptionif the Collection is a container of pointers and does not allow NULL values.
This implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's so contained, it's removed from this collection with the iterator's remove method.Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method and this collection contains one or more elements in common with the specified collection. More...
 
- Public Member Functions inherited from decaf::util::Set< E >
virtual ~Set ()
 
- Public Member Functions inherited from decaf::util::Collection< E >
virtual ~Collection ()
 
- Public Member Functions inherited from decaf::lang::Iterable< E >
virtual ~Iterable ()
 
- Public Member Functions inherited from decaf::util::concurrent::Synchronizable
virtual ~Synchronizable ()
 
- 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. 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.
Parameters
collectionThe Collection to compare to this one.
Exceptions
NullPointerExceptionif the Collection contains pointers and the Collection does not allow for NULL elements (optional check).
More...
 
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.)
Parameters
collectionThe Collection whose elements are added to this one.
Returns
true if this collection changed as a result of the call
Exceptions
UnsupportedOperationExceptioif this is an unmodifiable collection.
NullPointerExceptionif the Collection is a container of pointers and does not allow NULL values.
IllegalArgumentExceptionif some property of an element prevents it from being added to this collection
IllegalStateExceptionif an element cannot be added at this time due to insertion restrictions.
More...
 
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.
Parameters
collectionThe Collection whose elements are to be retained.
Returns
true if the collection changed as a result of this call.
Exceptions
UnsupportedOperationExceptioif this is an unmodifiable collection.
NullPointerExceptionif the Collection is a container of pointers and does not allow NULL values.
More...
 
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
 
- Protected Attributes inherited from decaf::util::AbstractCollection< E >
util::concurrent::Mutex mutex
 

Detailed Description

template<typename E, typename HASHCODE = HashCode<E>>
class decaf::util::HashSet< E, HASHCODE >

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.

Since
1.0

Constructor & Destructor Documentation

template<typename E, typename HASHCODE = HashCode<E>>
decaf::util::HashSet< E, HASHCODE >::HashSet ( )
inline

Constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75).

template<typename E, typename HASHCODE = HashCode<E>>
decaf::util::HashSet< E, HASHCODE >::HashSet ( int  capacity)
inline

Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor (0.75).

Parameters
capacityThe initial capacity of this HashSet.
template<typename E, typename HASHCODE = HashCode<E>>
decaf::util::HashSet< E, HASHCODE >::HashSet ( int  capacity,
float  loadFactor 
)
inline

Constructs a new instance of.

with the specified capacity and load factor.

Parameters
capacityThe initial capacity for this HashSet.
loadFactorThe initial load factor for this HashSet.
template<typename E, typename HASHCODE = HashCode<E>>
decaf::util::HashSet< E, HASHCODE >::HashSet ( const Collection< E > &  collection)
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.

Parameters
collectionThe 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().

template<typename E, typename HASHCODE = HashCode<E>>
decaf::util::HashSet< E, HASHCODE >::HashSet ( const HashSet< E > &  collection)
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.

Parameters
collectionThe 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().

template<typename E, typename HASHCODE = HashCode<E>>
virtual decaf::util::HashSet< E, HASHCODE >::~HashSet ( )
inlinevirtual
template<typename E, typename HASHCODE = HashCode<E>>
decaf::util::HashSet< E, HASHCODE >::HashSet ( HashMap< E, Set< E > *, HASHCODE > *  backingMap)
inlineprotected

Protected constructor for use by subclasses that wish to use an alternate type of backing Map.

Parameters
backingMapThe instance of the Map type used to back this HashSet.

Member Function Documentation

template<typename E, typename HASHCODE = HashCode<E>>
virtual bool decaf::util::HashSet< E, HASHCODE >::add ( const E &  value)
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.

Parameters
valueThe object to add.
Returns
true when this HashSet did not already contain the object,false otherwise.

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().

template<typename E, typename HASHCODE = HashCode<E>>
virtual void decaf::util::HashSet< E, HASHCODE >::clear ( )
inlinevirtual

Removes all elements from this.

, leaving it empty.

See also
isEmpty
size

Reimplemented from decaf::util::AbstractCollection< E >.

References decaf::util::HashSet< E, HASHCODE >::backingMap.

Referenced by decaf::util::HashSet< E, HASHCODE >::operator=().

template<typename E, typename HASHCODE = HashCode<E>>
virtual bool decaf::util::HashSet< E, HASHCODE >::contains ( const E &  value) const
inlinevirtual

Searches this.

for the specified object.

Parameters
valuethe object to search for.
Returns
true
if
object
is an element of this ,
false
otherwise.

Reimplemented from decaf::util::AbstractCollection< E >.

References decaf::util::HashSet< E, HASHCODE >::backingMap.

template<typename E, typename HASHCODE = HashCode<E>>
virtual bool decaf::util::HashSet< E, HASHCODE >::isEmpty ( ) const
inlinevirtual

Returns true if this.

has no elements, false otherwise.

Returns
true
if this has no elements,
false
otherwise.
See also
size

Reimplemented from decaf::util::AbstractCollection< E >.

References decaf::util::HashSet< E, HASHCODE >::backingMap.

template<typename E, typename HASHCODE = HashCode<E>>
virtual Iterator<E>* decaf::util::HashSet< E, HASHCODE >::iterator ( )
inlinevirtual

Returns an Iterator on the elements of this.

.

Returns
an Iterator on the elements of this .
See also
Iterator

Implements decaf::lang::Iterable< E >.

References decaf::util::HashSet< E, HASHCODE >::backingMap.

Referenced by decaf::util::HashSet< E, HASHCODE >::HashSet().

template<typename E, typename HASHCODE = HashCode<E>>
virtual Iterator<E>* decaf::util::HashSet< E, HASHCODE >::iterator ( ) const
inlinevirtual
template<typename E, typename HASHCODE = HashCode<E>>
HashSet<E>& decaf::util::HashSet< E, HASHCODE >::operator= ( const Collection< E > &  collection)
inline
template<typename E, typename HASHCODE = HashCode<E>>
virtual bool decaf::util::HashSet< E, HASHCODE >::remove ( const E &  value)
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.)

Parameters
valueThe value to remove from this set.
Returns
true if the value was removed, false otherwise.

Reimplemented from decaf::util::AbstractCollection< E >.

References decaf::util::HashSet< E, HASHCODE >::backingMap.

template<typename E, typename HASHCODE = HashCode<E>>
virtual int decaf::util::HashSet< E, HASHCODE >::size ( ) const
inlinevirtual

Returns the number of elements in this.

.

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().

template<typename E, typename HASHCODE = HashCode<E>>
virtual std::string decaf::util::HashSet< E, HASHCODE >::toString ( ) const
inlinevirtual

Field Documentation


The documentation for this class was generated from the following file: