rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWTValHashMultiSet< T, H, EQ, A > Class Template Reference
[STL Extension-based Collections]

Maintains a collection of values stored according to a hash object, and with multiple equivalent values allowed. More...

#include <rw/tvhasht.h>

Inherits RW_VHAssoc< rw_hashmultiset< T, H, EQ,A >, RWTValHashMultiSet< T, H, EQ,A > >.

List of all members.

Public Types

typedef rw_hashmultiset< 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_typestd ()
const container_typestd () 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 RWTValHashMultiSet< T, H, EQ, A > &s) const
bool operator!= (const container_type &stdc) const
bool operator!= (const RWTValHashMultiSet< 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 k, value_type &a) 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)
void Union (const RWTValHashMultiSet< T, H, EQ, A > &rhs)
void intersection (const RWTValHashMultiSet< T, H, EQ, A > &s)
void difference (const RWTValHashMultiSet< T, H, EQ, A > &s)
bool isSubsetOf (const RWTValHashMultiSet< T, H, EQ, A > &s) const
bool isProperSubsetOf (const RWTValHashMultiSet< T, H, EQ, A > &s) const
bool isEquivalent (const RWTValHashMultiSet< T, H, EQ, A > &s) const
void symmetricDifference (const RWTValHashMultiSet< T, H, EQ, A > &s)
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 (RWTValHashMultiSet< T, H, EQ, A > &other)
RWTValHashMultiSet< T, H, EQ,A > & operator= (const RWTValHashMultiSet< T, H, EQ, A > &s)
RWTValHashMultiSet< T, H, EQ,A > & operator= (const rw_hashmultiset< T, H, EQ, A > &s)
RWTValHashMultiSet< T, H, EQ,A > & operator= (rw_hashmultiset< T, H, EQ, A > &&rhs)
 RWTValHashMultiSet (size_type sz=1024, const H &h=H(), const EQ &eq=EQ())
 RWTValHashMultiSet (const rw_hashmultiset< T, H, EQ, A > &s)
 RWTValHashMultiSet (const RWTValHashMultiSet< T, H, EQ, A > &rws)
 RWTValHashMultiSet (RWTValHashMultiSet< T, H, EQ, A > &&rws)
 RWTValHashMultiSet (const T *first, const T *last, size_type sz=1024, const H &h=H(), const EQ &eq=EQ())
 RWTValHashMultiSet (const H &h, size_type sz=64)

Related Functions

(Note that these are not member functions.)



template<class T , class H , class EQ , class A >
RWvostreamoperator<< (RWvostream &strm, const RWTValHashMultiSet< T, H, EQ, A > &coll)
template<class T , class H , class EQ , class A >
RWFileoperator<< (RWFile &file, const RWTValHashMultiSet< T, H, EQ, A > &coll)
template<class T , class H , class EQ , class A >
RWvistreamoperator>> (RWvistream &strm, RWTValHashMultiSet< T, H, EQ, A > &coll)
template<class T , class H , class EQ , class A >
RWFileoperator>> (RWFile &file, RWTValHashMultiSet< T, H, EQ, A > &coll)
template<class T , class H , class EQ , class A >
RWvistreamoperator>> (RWvistream &strm, RWTValHashMultiSet< T, H, EQ, A > *&p)
template<class T , class H , class EQ , class A >
RWFileoperator>> (RWFile &file, RWTValHashMultiSet< T, H, EQ, A > *&p)

Detailed Description

template<class T, class H, class EQ, class A = std:: allocator < T >>
class RWTValHashMultiSet< T, H, EQ, A >

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 type allows multiple equivalent objects. Equivalent objects are grouped together based on an equality object of type EQ. EQ 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.

Note:
Any two keys that are equivalent must hash to the same value.

The value type must have operator==() defined. This requirement is imposed by the C++ Standard Library.

Synopsis

 #include <rw/tvhasht.h>
 RWTValHashMultiSet<T,H,EQ,A> m;

Related Classes

Class RWTValHashSet<T,H,EQ,A> offers the same interface to a collection that does not accept multiple items that compare equal to each other.

Class rw_hashmultiset<T,H,EQ,A> is the C++ Standard Library collection class that serves as the underlying implementation for RWTValHashMultiSet<T,H,EQ,A>.

Persistence

Isomorphic

Examples

 #include <iostream>
 #include <functional>
 
 #include <rw/tvhasht.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 ()
 {
     RWTValHashMultiSet<RWCString,simple_hash,std::equal_to<RWCString> > set1;
     RWTValHashMultiSet<RWCString,simple_hash,std::equal_to<RWCString> > set2;
 
     set1.insert("one");
     set1.insert("two");
     set1.insert("three");
     set1.insert("one");        // OK: duplicates allowed
     set1.insert("one");
 
     std::cout << set1.entries() << std::endl; // Prints "5"
 
     set2.insert("one");
     set2.insert("five");
     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 "2"
 
     return 0;
 }

Program Output:

 5
 false
 0
 2

Member Typedef Documentation

template<class T, class H, class EQ, class A = std:: allocator < T >>
typedef container_type::const_iterator RWTValHashMultiSet< T, H, EQ, A >::const_iterator

Typedef for the const iterator.

template<class T, class H, class EQ, class A = std:: allocator < T >>
typedef container_type::const_reference RWTValHashMultiSet< T, H, EQ, A >::const_reference

Typedef for a const reference to a value in this container.

template<class T, class H, class EQ, class A = std:: allocator < T >>
typedef rw_hashmultiset<T,H,EQ ,A > RWTValHashMultiSet< T, H, EQ, A >::container_type

A typedef for the C++ Standard Library collection that serves as the underlying implementation for this class.

template<class T, class H, class EQ, class A = std:: allocator < T >>
typedef container_type::iterator RWTValHashMultiSet< T, H, EQ, A >::iterator

Typedef for the non-const iterator.

template<class T, class H, class EQ, class A = std:: allocator < T >>
typedef container_type::reference RWTValHashMultiSet< T, H, EQ, A >::reference

Typedef for a non-const reference to a value in this container.

template<class T, class H, class EQ, class A = std:: allocator < T >>
typedef container_type::size_type RWTValHashMultiSet< T, H, EQ, A >::size_type

Typedef for the type used to index into this container.

template<class T, class H, class EQ, class A = std:: allocator < T >>
typedef container_type::value_type RWTValHashMultiSet< T, H, EQ, A >::value_type

Typedef for the type of elements in this container.


Constructor & Destructor Documentation

template<class T, class H, class EQ, class A = std:: allocator < T >>
RWTValHashMultiSet< T, H, EQ, A >::RWTValHashMultiSet ( 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 as its hashing function, and uses eq to determine equivalence between elements.

template<class T, class H, class EQ, class A = std:: allocator < T >>
RWTValHashMultiSet< T, H, EQ, A >::RWTValHashMultiSet ( const rw_hashmultiset< T, H, EQ, A > &  s  )  [inline]

Constructs a set by copying all elements of s.

template<class T, class H, class EQ, class A = std:: allocator < T >>
RWTValHashMultiSet< T, H, EQ, A >::RWTValHashMultiSet ( const RWTValHashMultiSet< T, H, EQ, A > &  rws  )  [inline]

Copy constructor.

template<class T, class H, class EQ, class A = std:: allocator < T >>
RWTValHashMultiSet< T, H, EQ, A >::RWTValHashMultiSet ( RWTValHashMultiSet< T, H, EQ, A > &&  rws  )  [inline]

Move constructor. The constructed list takes ownership of the data owned by rws.

Condition:
This method is only available on platforms with rvalue reference support.
template<class T, class H, class EQ, class A = std:: allocator < T >>
RWTValHashMultiSet< T, H, EQ, A >::RWTValHashMultiSet ( 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 as its hashing function, and uses eq to determine equivalence between elements.

template<class T, class H, class EQ, class A = std:: allocator < T >>
RWTValHashMultiSet< T, H, EQ, A >::RWTValHashMultiSet ( const H &  h,
size_type  sz = 64 
) [inline]

Creates an empty hashed multi-set that uses the hash object h and has an initial hash table capacity of sz.


Member Function Documentation

template<class T, class H, class EQ, class A = std:: allocator < T >>
void RWTValHashMultiSet< 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.

template<class T, class H, class EQ, class A = std:: allocator < T >>
const_iterator RWTValHashMultiSet< T, H, EQ, A >::begin (  )  const [inline]

Returns an iterator positioned at the first element of self.

template<class T, class H, class EQ, class A = std:: allocator < T >>
iterator RWTValHashMultiSet< T, H, EQ, A >::begin (  )  [inline]

Returns an iterator positioned at the first element of self.

template<class T, class H, class EQ, class A = std:: allocator < T >>
size_type RWTValHashMultiSet< T, H, EQ, A >::capacity (  )  const [inline]

Returns the number of buckets (slots) available in the underlying hash representation. See resize().

template<class T, class H, class EQ, class A = std:: allocator < T >>
void RWTValHashMultiSet< T, H, EQ, A >::clear ( void   )  [inline]

Clears the collection by removing all items from self. Each item has its destructor called.

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< 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.

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< 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)(a,d)) is true, otherwise returns false. Client data may be passed through parameter d.

template<class T, class H, class EQ, class A = std:: allocator < T >>
void RWTValHashMultiSet< T, H, EQ, A >::difference ( const RWTValHashMultiSet< T, H, EQ, A > &  s  )  [inline]

Sets self to the set-theoretic difference given by (self - s).

template<class T, class H, class EQ, class A = std:: allocator < T >>
const_iterator RWTValHashMultiSet< T, H, EQ, A >::end (  )  const [inline]

Returns an iterator positioned "just past" the last element in self.

template<class T, class H, class EQ, class A = std:: allocator < T >>
iterator RWTValHashMultiSet< T, H, EQ, A >::end (  )  [inline]

Returns an iterator positioned "just past" the last element in self.

template<class T, class H, class EQ, class A = std:: allocator < T >>
size_type RWTValHashMultiSet< T, H, EQ, A >::entries ( void   )  const [inline]

Returns the number of items in self.

template<class T, class H, class EQ, class A = std:: allocator < T >>
float RWTValHashMultiSet< T, H, EQ, A >::fillRatio (  )  const [inline]

Returns the ratio entries() / capacity().

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< T, H, EQ, A >::find ( const_reference  k,
value_type a 
) const [inline]

If there exists an element t in self such that the expression (t == a) is true, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged.

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< 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 that compares equal to a, 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.

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< T, H, EQ, A >::insert ( value_type &&  datum  )  [inline]

Adds the item a to the collection. Returns true.

Condition:
This method is only available on platforms with rvalue reference support.
template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< T, H, EQ, A >::insert ( const_reference  datum  )  [inline]

Adds the item a to the collection. Returns true.

template<class T, class H, class EQ, class A = std:: allocator < T >>
void RWTValHashMultiSet< T, H, EQ, A >::intersection ( const RWTValHashMultiSet< T, H, EQ, A > &  s  )  [inline]

Destructively performs a set-theoretic intersection of self and s, replacing the contents of self with the result.

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< T, H, EQ, A >::isEmpty (  )  const [inline]

Returns true if there are no items in the collection, otherwise returns false.

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< T, H, EQ, A >::isEquivalent ( const RWTValHashMultiSet< T, H, EQ, A > &  s  )  const [inline]

Returns true if there is set equivalence between self and s, otherwise returns false.

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< T, H, EQ, A >::isProperSubsetOf ( const RWTValHashMultiSet< T, H, EQ, A > &  s  )  const [inline]

Returns true if self is a proper subset of s, otherwise returns false.

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< T, H, EQ, A >::isSubsetOf ( const RWTValHashMultiSet< T, H, EQ, A > &  s  )  const [inline]

Returns true if self is a subset of s, otherwise returns false.

template<class T, class H, class EQ, class A = std:: allocator < T >>
size_type RWTValHashMultiSet< T, H, EQ, A >::occurrencesOf ( const_reference  a  )  const [inline]

Returns the number of elements t in self that compare equal to a.

template<class T, class H, class EQ, class A = std:: allocator < T >>
size_type RWTValHashMultiSet< 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)(a,d)) is true. Client data may be passed through parameter d.

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< T, H, EQ, A >::operator!= ( const RWTValHashMultiSet< T, H, EQ, A > &  rwc  )  const [inline]

Returns the negation of operator==().

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< T, H, EQ, A >::operator!= ( const container_type stdc  )  const [inline]

Returns the negation of operator==().

template<class T, class H, class EQ, class A = std:: allocator < T >>
RWTValHashMultiSet<T,H,EQ ,A >& RWTValHashMultiSet< T, H, EQ, A >::operator= ( rw_hashmultiset< T, H, EQ, A > &&  rhs  )  [inline]

Move assignment. Self takes ownership of the data owned by rhs.

Condition:
This method is only available on platforms with rvalue reference support.
template<class T, class H, class EQ, class A = std:: allocator < T >>
RWTValHashMultiSet<T,H,EQ ,A >& RWTValHashMultiSet< T, H, EQ, A >::operator= ( const rw_hashmultiset< T, H, EQ, A > &  s  )  [inline]

Destroys all elements of self and replaces them by copying all elements of s.

template<class T, class H, class EQ, class A = std:: allocator < T >>
RWTValHashMultiSet<T,H,EQ ,A >& RWTValHashMultiSet< T, H, EQ, A >::operator= ( const RWTValHashMultiSet< T, H, EQ, A > &  s  )  [inline]

Destroys all elements of self and replaces them by copying all elements of s.

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< T, H, EQ, A >::operator== ( const RWTValHashMultiSet< 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.

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< 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.

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< T, H, EQ, A >::remove ( const_reference  a  )  [inline]

Removes the first element t in self that compares equal to a and returns true. If there is no such element, returns false.

template<class T, class H, class EQ, class A = std:: allocator < T >>
bool RWTValHashMultiSet< 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)(a,d)) is true and returns true. If there is no such element, returns false. Client data may be passed through parameter d.

template<class T, class H, class EQ, class A = std:: allocator < T >>
size_type RWTValHashMultiSet< 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.

template<class T, class H, class EQ, class A = std:: allocator < T >>
size_type RWTValHashMultiSet< T, H, EQ, A >::removeAll ( bool(*)(const_reference, void *)  fn,
void *  d 
) [inline]

Removes all elements t in self such that the expression ((*fn)(a,d)) is true. Returns the number of items removed. Client data may be passed through parameter d.

template<class T, class H, class EQ, class A = std:: allocator < T >>
void RWTValHashMultiSet< T, H, EQ, A >::resize ( size_type  sz  )  [inline]

Changes the capacity of self by creating a new hashed multi-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.

template<class T, class H, class EQ, class A = std:: allocator < T >>
const container_type& RWTValHashMultiSet< 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 the C++ Standard Library collections.

template<class T, class H, class EQ, class A = std:: allocator < T >>
container_type& RWTValHashMultiSet< 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 the C++ Standard Library collections.

template<class T, class H, class EQ, class A = std:: allocator < T >>
void RWTValHashMultiSet< T, H, EQ, A >::swap ( RWTValHashMultiSet< 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.

template<class T, class H, class EQ, class A = std:: allocator < T >>
void RWTValHashMultiSet< T, H, EQ, A >::symmetricDifference ( const RWTValHashMultiSet< T, H, EQ, A > &  s  )  [inline]

Destructively performs a set-theoretic symmetric difference operation on self and s. Self is replaced by the result. A symmetric difference can be informally defined as $ (A \cup B) \setminus (A \cap B) $.

template<class T, class H, class EQ, class A = std:: allocator < T >>
void RWTValHashMultiSet< T, H, EQ, A >::Union ( const RWTValHashMultiSet< T, H, EQ, A > &  rhs  )  [inline]

Destructively performs a set-theoretic union operation on self and rhs. Self is replaced by the result. Note the uppercase 'U' in Union to avoid conflict with the C++ reserved word.


Friends And Related Function Documentation

template<class T , class H , class EQ , class A >
RWFile & operator<< ( RWFile file,
const RWTValHashMultiSet< T, H, EQ, A > &  coll 
) [related]

Saves the collection coll to the RWFile file, or a reference to the file if the collection has already been saved.

template<class T , class H , class EQ , class A >
RWvostream & operator<< ( RWvostream strm,
const RWTValHashMultiSet< 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.

template<class T , class H , class EQ , class A >
RWFile & operator>> ( RWFile file,
RWTValHashMultiSet< T, H, EQ, A > *&  p 
) [related]

Looks at the next object on the stream represented by 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.

template<class T , class H , class EQ , class A >
RWvistream & operator>> ( RWvistream strm,
RWTValHashMultiSet< 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.

template<class T , class H , class EQ , class A >
RWFile & operator>> ( RWFile file,
RWTValHashMultiSet< T, H, EQ, A > &  coll 
) [related]

Restores the contents of the collection coll from the RWFile file.

template<class T , class H , class EQ , class A >
RWvistream & operator>> ( RWvistream strm,
RWTValHashMultiSet< T, H, EQ, A > &  coll 
) [related]

Restores the contents of the collection coll from the input stream strm.

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© 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.