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

©Copyright 1996 Rogue Wave Software

RWTValHashMultiMap<K,T,H,EQ>

Synopsis

#include <rw/tvhmmap.h> 
RWTValHashMultiMap<K,T,H,EQ> m;

Standard C++ Library Dependent!


RWTValHashMultiMap requires the Standard C++ Library.



Description

This class maintains a collection of keys, each with an associated item of type T. These pairs are stored according to a hash object of type H. H must provide a hash function on elements of type K via a public member

unsigned long operator()(const K& x) const

Equivalent keys 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 K& x, const K& y) const

which should return true if x and y are equivalent.

RWTValHashMultiMap<K,T,H,EQ> may contain multiple keys that compare equal to each other. (RWTValHashMap<K,T,H,EQ> will not accept a key that compares equal to any key already in the collection.) Equality is based on the comparison object and not on the == operator.

Persistence

Isomorphic.

Examples

//
// tvhmmrat.cpp
//
#include<rw/tvhmmap.h>
#include<iostream.h>
#include<rw/cstring.h>

struct silly_hash{
   unsigned long operator()(RWCString x) const
   { return x.length() * (long)x[0]; }
};
int main(){
  RWCString trd = "Third";
  RWTValHashMultiMap<RWCString,int,silly_hash,equal_to<RWCString> >
       contest;
  contest.insert("First", 7);
  contest.insert(trd,3);




                              //equivalent to trd 
  contest.insert("Second",2);

  contest.resize(8);
  cout << "The table is " << contest.fillRatio() * 100.0 
       << "% full<< endl;
  return 0;
}
 
Program Output:
The table is 50% full

Related Classes

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

Class rw_hashmultimap<K,T,H,EQ> is the C++-standard collection that serves as the underlying implementation for this collection.

Public Typedefs

typedef rw_hashmultimap<K,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 pair <const K,T>                       value_type;
typedef pair <const K,T>&                      reference; 
typedef const pair<const K,T>&                 const_reference;

Public Constructors

RWTValHashMultiMap<K,T,H,EQ>();
RWTValHashMultiMap<K,T,H,EQ>
(const rw_hashmultimap<K,T,H,EQ>& m);
RWTValHashMultiMap<K,T,H,EQ>
(const RWTValHashMultiMap<K,T,H,EQ>& rwm);
RWTValHashMultiMap<K,T,H,EQ>
(const value_type* first, const value_type* last);

Public Member Operators

RWTValHashMultiMap<K,T,H,EQ>&
operator=(const RWTValHashMultiMap<K,T,H,EQ>& m);
RWTValHashMultiMap<K,T,H,EQ>&
operator=(const rw_hashmultimap<K,T,H,EQ>& m);
bool
operator==(const RWTValHashMultiMap<K,T,H,EQ>& m) const;
bool
operator==(const rw_hashmultimap<K,T,H,EQ>& m) const;

Public Member Functions

void
apply(void (*fn)(const K&, T&, void*),void* d);
void
apply(void (*fn)(const K&,const T&, void*), void* d) const;
void
applyToKeyAndValue(void (*fn)(const K&, T&, void*),void* d);
void
applyToKeyAndValue
(void (*fn)(const K&,const T&,void*), void* d) const;
iterator
begin();
const_iterator
begin() const;
size_type
capacity() const;
void
clear();
bool
contains(const K& key) const;
bool
contains
(bool (*fn)(const_reference,void*), void* d) const;
iterator
end();
const_iterator
end() const;
size_type
entries() const;
float
fillRatio() const;
bool
find(const K& key, Key& r) const;
bool
find (bool (*fn)(const_reference,void*),
      void* d,pair<K,T>& r) const;
bool
findValue(const K& key, T& r) const;
bool
findKeyValue(const K& key, K& kr, T& tr) const;
bool
insert(const K& key, const T& a);
bool
insertKeyAndValue(const K& key, const T& a);
bool
isEmpty() const;
size_type
occurrencesOf(const K& key) const;
size_type
occurrencesOf
(bool (*fn)(const_reference,void*),void* d) const;
bool
remove(const K& key);
bool
remove(bool (*fn)(const_reference,void*), void* d);
size_type
removeAll(const K& key);
size_type
removeAll(bool (*fn)(const_reference,void*), void* d);
void
resize(size_type sz);
rw_hashmultimap<K,T,H,EQ>&
std();
const rw_hashmultimap<K,T,H,EQ>&
std() const;

Related Global Operators

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