Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWTPtrHashSet<T,H,EQ>

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

Synopsis

#include <rw/tphset.h> 
RWTPtrHashSet<T,H,EQ> s;

Please Note!


If you have the Standard C++ Library, use the interface described here. Otherwise, use the restricted interface to RWTPtrHashSet 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 const hash function on 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.

RWTPtrHashSet<T,H,EQ> will not accept an item that is equivalent to an item already in the collection. (RWTPtrHashMultiSet<T,H,EQ> may contain multiple items that are equivalent to each other.) Equality is based on the equality object and not on the == operator.

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

Persistence

Isomorphic

Example

//
// tphset2.cpp
//
#include <rw/tphset.h>
#include <rw/cstring.h>
#include <iostream.h>

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

main(){
RWTPtrHashSet<RWCString,silly_hash,equal_to<RWCString> > set1;
RWTPtrHashSet<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")); // Duplicate insertion rejected

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

 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 RWTPtrHashMultiSet<T,H,EQ> offers the same interface to a pointer-based collection that accepts multiple items that compare equal to each other.

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

Public Typedefs

typedef rw_deref_compare<EQ,T>                 container_eq;
typedef rw_deref_hash<H,T>                     container_hash; 
typedef rw_hashset<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

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

Public Member Operators

RWTPtrHashSet<T,H,EQ>&
operator=(const RWTPtrHashSet<T,H,EQ>& s); 
bool
operator==(const RWTPtrHashSet<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 RWTPtrHashSet<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 RWTPtrHashSet<T,H,EQ>& s); 
bool
isEmpty() const; 
bool
isEquivalent(const RWTPtrHashSet<T,H,EQ>& s) const; 
bool
isProperSubsetOf(const RWTPtrHashSet<T,H,EQ>& s) const; 
bool
isSubsetOf(const RWTPtrHashSet<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 RWTPtrHashSet<T,H,EQ>& s); 
void
Union(const RWTPtrHashSet<T,H,EQ>& s); 

Related Global Operators

RWvostream&
operator<<(RWvostream& strm, 
       const RWTPtrHashSet<T,H,EQ>& coll);
RWFile&
operator<<(RWFile& strm, 
       const RWTPtrHashSet<T,H,EQ>& coll);
RWvistream&
operator>>(RWvistream& strm, RWTPtrHashSet<T,H,EQ>& coll); 
RWFile&
operator>>(RWFile& strm, RWTPtrHashSet<T,H,EQ>& coll);
RWvistream&
operator>>(RWvistream& strm, RWTPtrHashSet<T,H,EQ>*& p);
RWFile&
operator>>(RWFile& strm, RWTPtrHashSet<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.