Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWTPtrHashMap<K,T,H,EQ>

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

Synopsis

#include <rw/tphdict.h> 
RWTPtrHashMap<K,T,H,EQ> m;

Please Note!


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


Description

This class maintains a pointer-based collection of associations of type pair<K* const, T*>. These pairs are stored according to a hash object of type H. H must provide a const hash function on elements of type K via 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.

Note: Any two keys that are equivalent must hash to the same value.

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

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

Persistence

Isomorphic

Examples

//
// tphmap.cpp
//
#include<rw/tphdict.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";
   RWTPtrHashMap<RWCString,int,silly_hash,equal_to<RWCString> >
       contest;
   contest.insert(new RWCString("First"), new int(7));
   contest.insert(&snd,new int(3));

   //duplicate insertion rejected
   contest.insert(&snd,new int(6));
   contest.insert(new RWCString("Third"), new int(2));
   cout << "There was " 
        << contest.occurrencesOf(new RWCString("Second"))
        << " second place winner." << endl;
   return 0;
}
 Program Output:
There was 1 second place winner.

Related Classes

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

Class rw_hashmap<K*,T*,rw_deref_hash<H,K>,rw_deref_compare<C,K> > is the C++-standard library 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_hashmap<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

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

Public Member Operators

RWTPtrHashMap<K,T,H,EQ>&
operator=(const container_type& m); 
RWTPtrHashMap<K,T,H,EQ>&
operator=(const RWTPtrHashMap<K,T,H,EQ>& m);
bool
operator==(const RWTPtrHashMap<K,T,H,EQ>& m) const; 
T*&
operator[](K* key); 

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); 
rw_hashmap<K*,T*,rw_deref_hash<H,K>,deref_compare<EQ,K>>&
std();
const rw_hashmap<K*,T*,rw_deref_hash<H,K>,deref_compare<EQ,K>>&
std() const;

Related Global Operators

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