Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWTValHashSet<T,H,EQ>

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

Synopsis

#include <rw/tvhset.h> 
RWTValHashSet<T,H,EQ> s;

Please Note!


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

RWTValHashSet<T,H,EQ> will not accept an item that is equivalent to an item already in the collection. (RWTValHashMultiSet<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

//
// tvhsstr.cpp
//
#include <rw/tvhset.h>
#include <rw/cstring.h>
#include <iostream.h>

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

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

  set1.insert("one");
  set1.insert("two");
  set1.insert("three");

//Rejected, no duplicates allowed
  set1.insert("one");

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

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

//Rejected, no duplicates allowed
  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 "1"

  return 0;
}

Related Classes

Class RWTValHashMultiSet<T,H,EQ> offers the same interface to a collection that accepts multiple items that compare equal to each other.

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

Public Typedefs

typedef rw_hashset<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

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

Public Member Operators

RWTValHashSet<T,H,EQ>&
operator=(const RWTValHashSet<T,H,EQ>& s); 
RWTValHashSet<T,H,EQ>&
operator=(const rw_hashset<T,H,EQ>& s);
bool
operator==(const RWTValHashSet<T,H,EQ>& s) const; 
bool
operator==(const rw_hashset<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 RWTValHashSet<T,H,EQ>& s); 
void
difference(const rw_hashset<T,H,EQ>& s);
iterator
end();
const_iterator
end() const;
size_type
entries() const; 
float
fillRatio() const; 
bool
find(const_reference a, value_type& k) const; 
bool
find(bool (*fn)(const_reference,void*), void* d, 
     value_type& k) const;
bool
insert(const_reference a); 
void
intersection(const RWTValHashSet<T,H,EQ>& rhs); 
void
intersection(const rw_hashset<T,H,EQ>& rhs);
bool
isEmpty() const; 
bool
isEquivalent(const RWTValHashSet<T,H,EQ>& s) const; 
bool
isProperSubsetOf(const RWTValHashSet<T,H,EQ>& s) const; 
bool
isSubsetOf(const RWTValHashSet<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_hashset<T,H,EQ>&
std();
const rw_hashset<T,H,EQ>&
std() const;
void
symmetricDifference(const RWTValHashSet<T,H,EQ>& s); 
void
symmetricDifference(const rw_hashset<T,H,EQ>& s);
void
Union(const RWTValHashSet<T,H,EQ>& s); 
void
Union(const rw_hashsett<T,H,EQ>& s);

Related Global Operators

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