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

©Copyright 1996 Rogue Wave Software

RWTPtrHashMultiMap<K,T,H,EQ>

Synopsis

#include <rw/tphmmap.h> 
RWTPtrHashMultiMap<K,T,H,EQ> m;

Standard C++ Library Dependent!


RWTPtrHashMultiMap requires the Standard C++ Library.



Description

This class maintains a pointer-based collection of associatoins of type pair<K* const, 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)

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)

which should return true if x and y are equivalent.

RWTPtrHashMultiMap<K,T,H,EQ> may contain multiple keys that compare equal to each other. (RWTPtrHashMap<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

//
// tphmap.cpp
//
#include<rw/tphmmap.h>
#include<rw/cstring.h>
#include<iostream.h>

struct silly_hash{
   unsigned long operator()(RWCString x) const
   { return x.length() * (long)x[0]; }
};
int main(){
  RWCString snd = "Second";
  RWTPtrHashMultiMap<RWCString,int,silly_hash,equal_to<RWCString> >
      contest;
  contest.insert(new RWCString("First"), new int(7));
  contest.insert(&snd, new int(3));
  contest.insert(&snd, new int(6));      // duplicate key OK
  contest.insert(new RWCString("Third"), new int(2));

  cout << "There were " << contest.occurrencesOf(&snd)
       << " second place winners." << endl;

  return 0;
}
 Program Output:
There were 2 second place winners.

Related Classes

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

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

Public Typedefs

typedef rw_deref_hash<H,K>                container_hash;
typedef rw_deref_compare<EQ,K>            container_eq;
typedef rw_hashmultimap<K*,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 pair <K* const, T*>               value_type;
typedef pair <K* const, T*>&              reference;
typedef const pair <K* const, T*>&        const_reference;
typedef K*                                value_type_key;
typedef T*                                value_type_data;
typedef K*&                               reference_key;
typedef T*&                               reference_data;
typedef const K*const&                    const_reference_key;
typedef const T*const&                    const_reference_data;

Public Constructors

RWTPtrHashMultiMap<K,T,H,EQ>();
RWTPtrHashMultiMap<K,T,H,EQ>(const container_type& m);
RWTPtrHashMultiMap<K,T,H,EQ>
(const RWTPtrHashMultiMap<K,T,H,EQ>& rwm);
RWTPtrHashMultiMap<K,T,H,EQ>
(value_type* first, value_type* last);
RWTPtrHashMultiMap<K,T,H,EQ>
(const H& h, size_type sz = RWDEFAULT_CAPACITY);

Public Member Operators

RWTPtrHashMultiMap<K,T,H,EQ>&
operator=(const container_type&jjj m);
RWTPtrHashMultiMap<K,T,H,EQ>&
operator=(const RWTPtrHashMultiMap<K,T,H,EQ>& m);
bool
operator==(const RWTPtrHashMultiMap<K,T,H,EQ>& m);

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();
void
clearAndDestroy();
bool
contains(const K* key) const;
bool
contains(bool (*fn)(value_type,void*),void* d) const;
iterator
end();
const_iterator
end() const;
size_type
entries() const;
float
fillRatio() const;
const K*
find(const K* key) const;
value_type
find(bool (*fn)(value_type,void*), void* d) const;
T*
findValue(const K* key);
const T*
findValue(const K* key) const;
const K*
findKeyAndValue(const K* key, T*& tr);
const K*
findKeyAndValue(const K* key, const T*& tr) const;
bool
insert(K* key,T* a);
bool
insertKeyAndValue(K* key,T* a);
bool
isEmpty() const;
size_type
occurrencesOf(const K* key) const;
size_type
occurrencesOf
(bool(*fn)(value_type,void*),void* d)const;
K*
remove(const K* key);
K*
remove(bool (*fn)(value_type,void*), void* d);
size_type
removeAll(const K* key);
size_type
removeAll(bool (*fn)(value_type,void*), void* d);
void
resize(size_type sz);
container_type&
std();
const container_type&
std() const;

Related Global Operators

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