Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWTValHashMultiSet<T,H,EQ>

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

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

Please Note!


If you have the Standard C++ Library, use the interface described here. Otherwise, use the interface for RWTValHashTable described in Appendix A.


Description

This class maintains a collection of values, which are stored according to a hash object of type H. H must offer a const hash function for elements of type T via public member

unsigned long operator()(const T& x) const;

Objects within the collection will be 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, false otherwise.

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

RWTValHashMultiSet<T,H,EQ> may contain multiple items that are equivalent to each other. (RWTValHashSet<T,H,EQ> will not accept an item that is equivalent to an item already in the collection.)

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

Persistence

Isomorphic

Example

//
// tvhmsstr.cpp
//
#include <rw/tvhasht.h>
#include <rw/cstring.h>
#include <iostream.h>

struct silly_hash{
   unsigned long operator()(RWCString x) const
   { return x.length() * (long)x[0]; }
};

main(){
RWTValHashMultiSet<RWCString,silly_hash,equal_to<RWCString> > set1;
RWTValHashMultiSet<RWCString,silly_hash,equal_to<RWCString> > set2;

  set1.insert("one");
  set1.insert("two");
  set1.insert("three");
  set1.insert("one");     // OK: duplicates allowed
  set1.insert("one");

  cout << set1.entries() << endl;  // Prints "5"

  set2.insert("one");
  set2.insert("five");
  set2.insert("one");

  cout << ((set1.isEquivalent(set2)) ? "TRUE" : "FALSE") << endl;
  // Prints "FALSE"

  set2.intersection(set1);
  set1.clear();

  cout << set1.entries() << endl;    // Prints "0"
  cout << set2.entries() << endl;    // Prints "2"

  return 0;
}

Related Classes

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

Class rw_hashmultiset<T,H,EQ> is the C++-standard compliant collection that serves as the underlying implementation for RWTValHashMultiSet<T,H,EQ>.

Public Typedefs

typedef rw_hashmultiset<T,H,EQ>                container_type; 
typedef container_type::iterator               iterator;
typedef container_type::const_iterator         const_iterator;
typedef container_type::size_type              size_type;
typedef T                                      value_type; 
typedef T&                                     reference; 
typedef const T&                               const_reference; 

Public Constructors

RWTValHashMultiSet<T,H,EQ>
(size_type sz = 1024,const H& h = H(),const EQ& eq = EQ());
RWTValHashMultiSet<T,H,EQ>(const rw_hashmultiset<T,H,EQ>& s);
RWTValHashMultiSet<T,H,EQ>(const RWTValHashMultiSet<T,H,EQ>&);
RWTValHashMultiSet<T,H,EQ>
(const H& h,size_type sz = RWDEFAULT_CAPACITY);
RWTValHashMultiSet<T,H,EQ>(const T* first,const T* last,size_type sz = 1024,const H& h = H(),const EQ& eq = EQ());

Public Member Operators

RWTValHashMultiSet<T,H,EQ>&
operator=(const RWTValHashMultiSet<T,H,EQ>& s); 
RWTValHashMultiSet<T,H,EQ>&
operator=(const rw_hashmultiset<T,H,EQ>& s);
bool
operator==(const RWTValHashMultiSet<T,H,EQ>& s) const; 
bool
operator==(const rw_hashmultiset<T,H,EQ>& s) const;

Public Member Functions

void
apply(void (*fn)(const_reference,void*), void* d) const; 
iterator
begin();
const_iterator
begin() const;
size_type
capacity() const; 
void
clear();
bool
contains(const_reference a) const; 
bool
contains(bool (*fn)(const_reference,void*), void* d) const;
void
difference(const RWTValHashMultiSet<T,H,EQ>& s); 
iterator
end();
const_iterator
end() const;
size_type
entries() const; 
float
fillRatio() const; 
bool
find(const_reference a,T& k) const; 
bool
find(bool (*fn)(const_reference,void*),void* d,T& k) const; 
bool
insert(const_reference a); 
void
intersection(const RWTValHashMultiSet<T,H,EQ>& s); 
bool
isEmpty() const; 
bool
isEquivalent(const RWTValHashMultiSet<T,H,EQ>& s) const; 
bool
isProperSubsetOf(const RWTValHashMultiSet<T,H,EQ>& s) const; 
bool
isSubsetOf(const RWTValHashMultiSet<T,H,EQ>& s) const; 
size_type
occurrencesOf(const_reference a) const; 
size_type
occurrencesOf(bool (*fn)(const_reference,void*),void* d) const;
bool
remove(const_reference a); 
bool
remove(bool (*fn)(const_reference,void*), void* d);
size_type
removeAll(const_reference a); 
size_type
removeAll(bool (*fn)(const_reference,void*), void* d);
void
resize(size_type sz); 
rw_hashmultiset<T,H,EQ>&
std();
const rw_hashmultiset<T,H,EQ>&
std() const;
void
symmetricDifference(const RWTValHashMultiSet<T,H,EQ>& s); 
void
Union(const RWTValHashMultiSet<T,H,EQ>& rhs); 

Related Global Operators

RWvostream&
operator<<(RWvostream& strm, 
       const RWTValHashMultiSet<T,H,EQ>& coll);
RWFile&
operator<<(RWFile& strm, 
       const RWTValHashMultiSet<T,H,EQ>& coll);
RWvistream&
operator>>(RWvistream& strm, RWTValHashMultiSet<T,H,EQ>& coll); 
RWFile&
operator>>(RWFile& strm, RWTValHashMultiSet<T,H,EQ>& coll);
RWvistream&
operator>>(RWvistream& strm, RWTValHashMultiSet<T,H,EQ>*& p);
RWFile&
operator>>(RWFile& strm, RWTValHashMultiSet<T,H,EQ>*& p);


Previous fileTop of documentContentsIndexNext file
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.