SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Maintains a collection of values stored according to a hash object. More...
#include <rw/tvhset.h>
Inherits RW_SVHAssoc< rw_hashset< T, H, EQ,A >, RWTValHashSet< T, H, EQ,A > >.
Public Types | |
typedef rw_hashset< T, H, EQ,A > | container_type |
typedef container_type::iterator | iterator |
typedef container_type::const_iterator | const_iterator |
typedef container_type::size_type | size_type |
typedef container_type::value_type | value_type |
typedef container_type::reference | reference |
typedef container_type::const_reference | const_reference |
Public Member Functions | |
container_type & | std () |
const container_type & | std () const |
iterator | begin () |
const_iterator | begin () const |
iterator | end () |
const_iterator | end () const |
bool | isEmpty () const |
size_type | entries () const |
bool | operator== (const container_type &s) const |
bool | operator== (const RWTValHashSet< T, H, EQ, A > &s) const |
bool | operator!= (const container_type &stdc) const |
bool | operator!= (const RWTValHashSet< T, H, EQ, A > &rwc) const |
void | clear () |
bool | contains (bool(*fn)(const_reference, void *), void *d) const |
bool | contains (const_reference a) const |
bool | find (bool(*fn)(const_reference, void *), void *d, value_type &k) const |
bool | find (const_reference a, value_type &k) const |
size_type | occurrencesOf (bool(*fn)(const_reference, void *), void *d) const |
size_type | occurrencesOf (const_reference a) const |
bool | remove (bool(*fn)(const_reference, void *), void *d) |
bool | remove (const_reference a) |
size_type | removeAll (bool(*fn)(const_reference, void *), void *d) |
size_type | removeAll (const_reference a) |
bool | isSubsetOf (const RWTValHashSet< T, H, EQ, A > &s) const |
bool | isProperSubsetOf (const RWTValHashSet< T, H, EQ, A > &s) const |
bool | isEquivalent (const RWTValHashSet< T, H, EQ, A > &s) const |
RWTValHashSet< T, H, EQ,A > & | Union (const RWTValHashSet< T, H, EQ, A > &rhs) |
RWTValHashSet< T, H, EQ,A > & | Union (const rw_hashset< T, H, EQ, A > &rhs) |
RWTValHashSet< T, H, EQ,A > & | intersection (const RWTValHashSet< T, H, EQ, A > &rhs) |
RWTValHashSet< T, H, EQ,A > & | intersection (const rw_hashset< T, H, EQ, A > &rhs) |
RWTValHashSet< T, H, EQ,A > & | difference (const RWTValHashSet< T, H, EQ, A > &s) |
RWTValHashSet< T, H, EQ,A > & | difference (const rw_hashset< T, H, EQ, A > &s) |
RWTValHashSet< T, H, EQ,A > & | symmetricDifference (const RWTValHashSet< T, H, EQ, A > &rhs) |
RWTValHashSet< T, H, EQ,A > & | symmetricDifference (const rw_hashset< T, H, EQ, A > &rhs) |
void | apply (void(*fn)(const_reference, void *), void *d) const |
bool | insert (const_reference datum) |
bool | insert (value_type &&datum) |
size_type | capacity () const |
float | fillRatio () const |
void | resize (size_type sz) |
void | swap (RWTValHashSet< T, H, EQ, A > &other) |
RWTValHashSet< T, H, EQ,A > & | operator= (const RWTValHashSet< T, H, EQ, A > &s) |
RWTValHashSet< T, H, EQ,A > & | operator= (const rw_hashset< T, H, EQ, A > &s) |
RWTValHashSet< T, H, EQ,A > & | operator= (RWTValHashSet< T, H, EQ, A > &&rhs) |
RWTValHashSet (size_type sz=1024, const H &h=H(), const EQ &eq=EQ()) | |
RWTValHashSet (const rw_hashset< T, H, EQ, A > &s) | |
RWTValHashSet (const RWTValHashSet< T, H, EQ, A > &rws) | |
RWTValHashSet (RWTValHashSet< T, H, EQ, A > &&rws) | |
RWTValHashSet (const T *first, const T *last, size_type sz=1024, const H &h=H(), const EQ &eq=EQ()) | |
RWTValHashSet (const H &h, size_type sz=1024) | |
Related Functions | |
(Note that these are not member functions.) | |
template<class T , class H , class EQ , class A > | |
RWvostream & | operator<< (RWvostream &strm, const RWTValHashSet< T, H, EQ, A > &coll) |
template<class T , class H , class EQ , class A > | |
RWFile & | operator<< (RWFile &file, const RWTValHashSet< T, H, EQ, A > &coll) |
template<class T , class H , class EQ , class A > | |
RWvistream & | operator>> (RWvistream &strm, RWTValHashSet< T, H, EQ, A > &coll) |
template<class T , class H , class EQ , class A > | |
RWFile & | operator>> (RWFile &file, RWTValHashSet< T, H, EQ, A > &coll) |
template<class T , class H , class EQ , class A > | |
RWvistream & | operator>> (RWvistream &strm, RWTValHashSet< T, H, EQ, A > *&p) |
template<class T , class H , class EQ , class A > | |
RWFile & | operator>> (RWFile &file, RWTValHashSet< T, H, EQ, A > *&p) |
This class maintains a collection of values, which are stored according to a hash object of type H
. Class T
is the type of items in the collection. Class A
is an allocator of objects of class T
. For more information about using custom allocators, please see the Essential Tools Module User's Guide.
H
must offer a const
hash function for elements of type T
via public member:
unsigned long operator()(const T& x) const;
This collection does not accept an item that is equivalent to an item already in the collection. Equivalence is determined through the equivalence object EQ
, which must ensure this grouping via public member:
bool operator()(const T& x, const T& y) const;
which should return true
if x
and y
are equivalent, otherwise false
. Equivalence is determined by this equivalence object, not by operator==().
The value type must have operator==()
defined. This requirement is imposed by the C++ Standard Library.
#include <rw/tvhset.h> RWTValHashSet<T,H,EQ,A> s;
Class RWTValHashMultiSet<T,H,EQ,A> offers the same interface to a collection that does accept multiple items that compare equal to each other.
Class rw_hashset<T,H,EQ,A> is the C++ Standard Library collection that serves as the underlying implementation for RWTValHashSet<T,H,EQ,A>.
Isomorphic
#include <iostream> #include <functional> #include <rw/tvhset.h> #include <rw/cstring.h> struct simple_hash { unsigned long operator()(const RWCString& ref) const { size_t n = ref.length (); return (unsigned long)(n ? n * size_t (ref [0]) : 0); } }; int main () { RWTValHashSet<RWCString,simple_hash,std::equal_to<RWCString> > set1; RWTValHashSet<RWCString,simple_hash,std::equal_to<RWCString> > set2; set1.insert("one"); set1.insert("two"); set1.insert("three"); // Rejected, no duplicates allowed set1.insert("one"); std::cout << set1.entries() << std::endl; // Prints "3" set2.insert("one"); set2.insert("five"); // Rejected, no duplicates allowed set2.insert("one"); std::cout << ((set1.isEquivalent(set2)) ? "true" : "false") << std::endl; // Prints "false" set2.intersection(set1); set1.clear(); std::cout << set1.entries() << std::endl; // Prints "0" std::cout << set2.entries() << std::endl; // Prints "1" return 0; }
Program Output:
3
false
0
1
typedef container_type::const_iterator RWTValHashSet< T, H, EQ, A >::const_iterator |
Typedef for the const
iterator.
typedef container_type::const_reference RWTValHashSet< T, H, EQ, A >::const_reference |
Typedef for a const
reference to a value in this container.
typedef rw_hashset<T,H,EQ ,A > RWTValHashSet< T, H, EQ, A >::container_type |
A typedef for the C++ Standard Library collection that serves as the underlying implementation for this class.
typedef container_type::iterator RWTValHashSet< T, H, EQ, A >::iterator |
Typedef for the non-const
iterator.
typedef container_type::reference RWTValHashSet< T, H, EQ, A >::reference |
Typedef for a non-const
reference to a value in this container.
typedef container_type::size_type RWTValHashSet< T, H, EQ, A >::size_type |
Typedef for the type used to index into this container.
typedef container_type::value_type RWTValHashSet< T, H, EQ, A >::value_type |
Typedef for the type of elements in this container.
RWTValHashSet< T, H, EQ, A >::RWTValHashSet | ( | size_type | sz = 1024 , |
|
const H & | h = H() , |
|||
const EQ & | eq = EQ() | |||
) | [inline] |
Constructs an empty set. The underlying hash table representation has sz buckets, uses h for its hashing function, and uses eq to determine equality between elements
RWTValHashSet< T, H, EQ, A >::RWTValHashSet | ( | const rw_hashset< T, H, EQ, A > & | s | ) | [inline] |
Constructs a set by copying all elements of s.
RWTValHashSet< T, H, EQ, A >::RWTValHashSet | ( | const RWTValHashSet< T, H, EQ, A > & | rws | ) | [inline] |
Copy constructor.
RWTValHashSet< T, H, EQ, A >::RWTValHashSet | ( | RWTValHashSet< T, H, EQ, A > && | rws | ) | [inline] |
Move constructor. The constructed list takes ownership of the data owned by rws.
RWTValHashSet< T, H, EQ, A >::RWTValHashSet | ( | const T * | first, | |
const T * | last, | |||
size_type | sz = 1024 , |
|||
const H & | h = H() , |
|||
const EQ & | eq = EQ() | |||
) | [inline] |
Constructs a set by copying elements from the array of objects of type T
pointed to by first, up to, but not including, the element pointed to by last. The underlying hash table representation has sz buckets, uses h for its hashing function, and uses eq to determine equality between elements
RWTValHashSet< T, H, EQ, A >::RWTValHashSet | ( | const H & | h, | |
size_type | sz = 1024 | |||
) | [inline] |
Creates an empty hashed set that uses the hash object h and has an initial hash table capacity of sz.
void RWTValHashSet< T, H, EQ, A >::apply | ( | void(*)(const_reference, void *) | fn, | |
void * | d | |||
) | const [inline] |
Applies the user-defined function pointed to by fn to every item in the collection. Client data may be passed through parameter d.
const_iterator RWTValHashSet< T, H, EQ, A >::begin | ( | ) | const [inline] |
Returns an iterator positioned at the first element of self.
iterator RWTValHashSet< T, H, EQ, A >::begin | ( | ) | [inline] |
Returns an iterator positioned at the first element of self.
size_type RWTValHashSet< T, H, EQ, A >::capacity | ( | ) | const [inline] |
Returns the number of buckets (slots) available in the underlying hash representation. See resize().
void RWTValHashSet< T, H, EQ, A >::clear | ( | void | ) | [inline] |
Clears the collection by removing all items from self. Each item has its destructor called.
bool RWTValHashSet< T, H, EQ, A >::contains | ( | const_reference | a | ) | const [inline] |
Returns true
if there exists an element t
in self that compares equal to a, otherwise returns false
.
bool RWTValHashSet< T, H, EQ, A >::contains | ( | bool(*)(const_reference, void *) | fn, | |
void * | d | |||
) | const [inline] |
Returns true
if there exists an element t
in self such that the expression ((*fn)(t,d))
is true
, otherwise returns false
. Client data may be passed through parameter d.
RWTValHashSet<T,H,EQ ,A >& RWTValHashSet< T, H, EQ, A >::difference | ( | const rw_hashset< T, H, EQ, A > & | s | ) | [inline] |
Sets self to the set-theoretic difference given by (self - s)
.
RWTValHashSet<T,H,EQ ,A >& RWTValHashSet< T, H, EQ, A >::difference | ( | const RWTValHashSet< T, H, EQ, A > & | s | ) | [inline] |
Sets self to the set-theoretic difference given by (self - s)
.
const_iterator RWTValHashSet< T, H, EQ, A >::end | ( | ) | const [inline] |
Returns an iterator positioned "just past" the last element in self.
iterator RWTValHashSet< T, H, EQ, A >::end | ( | ) | [inline] |
Returns an iterator positioned "just past" the last element in self.
size_type RWTValHashSet< T, H, EQ, A >::entries | ( | void | ) | const [inline] |
Returns the number of items in self.
float RWTValHashSet< T, H, EQ, A >::fillRatio | ( | ) | const [inline] |
Returns the ratio entries() / capacity()
.
bool RWTValHashSet< T, H, EQ, A >::find | ( | const_reference | a, | |
value_type & | k | |||
) | const [inline] |
If there exists an element t
in self that compares equal to a, assigns t
to k and returns true
. Otherwise, returns false
and leaves the value of k unchanged.
bool RWTValHashSet< T, H, EQ, A >::find | ( | bool(*)(const_reference, void *) | fn, | |
void * | d, | |||
value_type & | k | |||
) | const [inline] |
If there exists an element t
in self such that the expression ((*fn)(t,d))
is true
, assigns t
to k and returns true
. Otherwise, returns false
and leaves the value of k unchanged. Client data may be passed through parameter d.
bool RWTValHashSet< T, H, EQ, A >::insert | ( | value_type && | datum | ) | [inline] |
Adds the item a to the collection. Returns true
if the insertion is successful, otherwise returns false
. The function returns true
unless the collection already holds an element with the equivalent key.
bool RWTValHashSet< T, H, EQ, A >::insert | ( | const_reference | datum | ) | [inline] |
Adds the item a to the collection. Returns true
if the insertion is successful, otherwise returns false
. The function returns true
unless the collection already holds an element with the equivalent key.
RWTValHashSet<T,H,EQ ,A >& RWTValHashSet< T, H, EQ, A >::intersection | ( | const rw_hashset< T, H, EQ, A > & | rhs | ) | [inline] |
Destructively performs a set-theoretic intersection of self and rhs, replacing the contents of self with the result.
RWTValHashSet<T,H,EQ ,A >& RWTValHashSet< T, H, EQ, A >::intersection | ( | const RWTValHashSet< T, H, EQ, A > & | rhs | ) | [inline] |
Destructively performs a set-theoretic intersection of self and rhs, replacing the contents of self with the result.
bool RWTValHashSet< T, H, EQ, A >::isEmpty | ( | ) | const [inline] |
Returns true
if there are no items in the collection, otherwise returns false
.
bool RWTValHashSet< T, H, EQ, A >::isEquivalent | ( | const RWTValHashSet< T, H, EQ, A > & | s | ) | const [inline] |
Returns true
if there is set equivalence between self and s, otherwise returns false
.
bool RWTValHashSet< T, H, EQ, A >::isProperSubsetOf | ( | const RWTValHashSet< T, H, EQ, A > & | s | ) | const [inline] |
Returns true
if self is a proper subset of s, otherwise returns false
.
bool RWTValHashSet< T, H, EQ, A >::isSubsetOf | ( | const RWTValHashSet< T, H, EQ, A > & | s | ) | const [inline] |
Returns true
if self is a subset of s or if self is set equivalent to s, otherwise returns false
.
size_type RWTValHashSet< T, H, EQ, A >::occurrencesOf | ( | const_reference | a | ) | const [inline] |
Returns the number of elements t
in self that compare equal to a.
size_type RWTValHashSet< T, H, EQ, A >::occurrencesOf | ( | bool(*)(const_reference, void *) | fn, | |
void * | d | |||
) | const [inline] |
Returns the number of elements t
in self such that the expression ((*fn)(t,d))
is true
. Client data may be passed through parameter d.
bool RWTValHashSet< T, H, EQ, A >::operator!= | ( | const RWTValHashSet< T, H, EQ, A > & | rwc | ) | const [inline] |
Returns the negation of operator==().
bool RWTValHashSet< T, H, EQ, A >::operator!= | ( | const container_type & | stdc | ) | const [inline] |
Returns the negation of operator==().
RWTValHashSet<T,H,EQ ,A >& RWTValHashSet< T, H, EQ, A >::operator= | ( | RWTValHashSet< T, H, EQ, A > && | rhs | ) | [inline] |
Move assignment. Self takes ownership of the data owned by rhs.
RWTValHashSet<T,H,EQ ,A >& RWTValHashSet< T, H, EQ, A >::operator= | ( | const rw_hashset< T, H, EQ, A > & | s | ) | [inline] |
Destroys all elements of self and replaces them by copying all elements of s.
RWTValHashSet<T,H,EQ ,A >& RWTValHashSet< T, H, EQ, A >::operator= | ( | const RWTValHashSet< T, H, EQ, A > & | s | ) | [inline] |
Destroys all elements of self and replaces them by copying all elements of s.
bool RWTValHashSet< T, H, EQ, A >::operator== | ( | const RWTValHashSet< T, H, EQ, A > & | s | ) | const [inline] |
Returns true
if self compares equal to s, otherwise returns false
. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual elements that compare equal to each other.
bool RWTValHashSet< T, H, EQ, A >::operator== | ( | const container_type & | s | ) | const [inline] |
Returns true
if self compares equal to s, otherwise returns false
. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual elements that compare equal to each other.
bool RWTValHashSet< T, H, EQ, A >::remove | ( | const_reference | a | ) | [inline] |
Removes the first element t
in self that compares equal to a and returns true
. Returns false
if there is no such element.
bool RWTValHashSet< T, H, EQ, A >::remove | ( | bool(*)(const_reference, void *) | fn, | |
void * | d | |||
) | [inline] |
Removes the first element t
in self such that the expression ((*fn)(t,d))
is true
and returns true
. Returns false
if there is no such element. Client data may be passed through parameter d.
size_type RWTValHashSet< T, H, EQ, A >::removeAll | ( | const_reference | a | ) | [inline] |
Removes all elements t
in self that compare equal to a. Returns the number of items removed.
size_type RWTValHashSet< T, H, EQ, A >::removeAll | ( | bool(*)(const_reference, void *) | fn, | |
void * | d | |||
) | [inline] |
Removes all elements t
in self such that the expression ((*fn)(t,d))
is true
. Returns the number of items removed. Client data may be passed through parameter d.
void RWTValHashSet< T, H, EQ, A >::resize | ( | size_type | sz | ) | [inline] |
Changes the capacity of self by creating a new hashed set with a capacity of sz. resize() copies every element of self into the new container and finally swaps the internal representation of the new container with the internal representation of self.
const container_type& RWTValHashSet< T, H, EQ, A >::std | ( | ) | const [inline] |
Returns a reference to the underlying collection that serves as the implementation for self. This reference may be used freely, providing access to the C++ Standard Library interface as well as interoperability with other software components that make use of C++ Standard Library collections.
container_type& RWTValHashSet< T, H, EQ, A >::std | ( | ) | [inline] |
Returns a reference to the underlying collection that serves as the implementation for self. This reference may be used freely, providing access to the C++ Standard Library interface as well as interoperability with other software components that make use of C++ Standard Library collections.
void RWTValHashSet< T, H, EQ, A >::swap | ( | RWTValHashSet< T, H, EQ, A > & | other | ) | [inline] |
Swaps the data held by self with the data held by other, including the H
and EQ
objects. This method does not copy or destroy any of the items swapped; rather, it swaps the underlying hash tables.
RWTValHashSet<T,H,EQ ,A >& RWTValHashSet< T, H, EQ, A >::symmetricDifference | ( | const rw_hashset< T, H, EQ, A > & | rhs | ) | [inline] |
Destructively performs a set-theoretic symmetric difference operation on self and s. Self is replaced by the result. A symmetric difference can be defined as .
RWTValHashSet<T,H,EQ ,A >& RWTValHashSet< T, H, EQ, A >::symmetricDifference | ( | const RWTValHashSet< T, H, EQ, A > & | rhs | ) | [inline] |
Destructively performs a set-theoretic symmetric difference operation on self and s. Self is replaced by the result. A symmetric difference can be defined as .
RWTValHashSet<T,H,EQ ,A >& RWTValHashSet< T, H, EQ, A >::Union | ( | const rw_hashset< T, H, EQ, A > & | rhs | ) | [inline] |
Destructively performs a set-theoretic union operation on self and s. Self is replaced by the result. Note the use of the uppercase 'U'
in Union
to avoid conflict with the C++ reserved word.
RWTValHashSet<T,H,EQ ,A >& RWTValHashSet< T, H, EQ, A >::Union | ( | const RWTValHashSet< T, H, EQ, A > & | rhs | ) | [inline] |
Destructively performs a set-theoretic union operation on self and s. Self is replaced by the result. Note the use of the uppercase 'U'
in Union
to avoid conflict with the C++ reserved word.
RWFile & operator<< | ( | RWFile & | file, | |
const RWTValHashSet< T, H, EQ, A > & | coll | |||
) | [related] |
Saves the collection coll to the RWFile file, or a reference to it if it has already been saved.
RWvostream & operator<< | ( | RWvostream & | strm, | |
const RWTValHashSet< T, H, EQ, A > & | coll | |||
) | [related] |
Saves the collection coll onto the output stream strm, or a reference to it if it has already been saved.
RWFile & operator>> | ( | RWFile & | file, | |
RWTValHashSet< T, H, EQ, A > *& | p | |||
) | [related] |
Looks at the next object on the stream represented by the RWFile file and either creates a new collection off the heap and sets p to point to it, or sets p to point to a previously read instance. If a collection is created off the heap, the application is responsible for deleting it.
RWvistream & operator>> | ( | RWvistream & | strm, | |
RWTValHashSet< T, H, EQ, A > *& | p | |||
) | [related] |
Looks at the next object on the input stream strm and either creates a new collection off the heap and sets p to point to it, or sets p to point to a previously read instance. If a collection is created off the heap, the application is responsible for deleting it.
RWFile & operator>> | ( | RWFile & | file, | |
RWTValHashSet< T, H, EQ, A > & | coll | |||
) | [related] |
Restores the contents of the collection coll from the RWFile file.
RWvistream & operator>> | ( | RWvistream & | strm, | |
RWTValHashSet< T, H, EQ, A > & | coll | |||
) | [related] |
Restores the contents of the collection coll from the input stream strm.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.