Rogue Wave Software logo banner

Click on the banner to return to the Class Reference home page.

©Copyright 1996 Rogue Wave Software

RWTPtrHashMultiSet<T,H,EQ>

Synopsis

#include <rw/tphasht.h>
RWTPtrHashMultiSet<T,H,EQ> hmset;

Please Note!


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


Description

This class maintains a pointer-based collection of values, which are stored according to a hash object of type H. Class T is the type pointed to by the items in the collection. H must provide a hash function on elements of type T via a public member

   unsigned long operator()(const T& x)

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)

which should return true if x and y are equivalent, false otherwise.

RWTPtrHashMultiSet<T,H,EQ> may contain multiple items that compare equal to each other. (RWTPtrHashSet<T,H,EQ> will not accept an item that compares equal to an item already in the collection.)

Persistence

Isomorphic

Examples

//
// tphasht.cpp
//
#include <rw/tphasht.h>
#include <rw/cstring.h>
#include <iostream.h>

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

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

 set1.insert(new RWCString("one"));
 set1.insert(new RWCString("two"));
 set1.insert(new RWCString("three"));
 set1.insert(new RWCString("one"));  // OK: duplicates allowd

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

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

 set2.difference(set1);

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

 return 0;
}

Related Classes

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

Class rw_hashmultiset<T*,rw_deref_hash<H,T>,rw_deref_compare<EQ,T> > is the C++-standard collection that serves as the underlying implementation for RWTPtrHashMultiSet<T,H,EQ>.

Public Typedefs

typedef rw_deref_compare<EQ,T>                 container_eq;
typedef rw_deref_hash<H,T>                     container_hash;

typedef rw_hashmultiset<T*,container_hash,container_eq>
                                               container_type;
typedef container_type::size_type              size_type;
typedef container_type::difference_type        difference_type;
typedef container_type::iterator               iterator;
typedef container_type::const_iterator         const_iterator;
typedef T*                                     value_type;
typedef T* const&                              reference;
typedef T* const&                              const_reference;

Public Constructors

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

Public Member Operators

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

Public Member Functions

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

Related Global Operators

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