バナーをクリックすれば目次に戻ります
Copyright 1999 Rogue Wave Software
Copyright 1999 Sun Microsystems, Inc.
RWTPtrHashMap<K,T,H,EQ>
#include <rw/tphdict.h> RWTPtrHashMap<K,T,H,EQ> m;
注 - 標準 C++ ライブラリがある場合は、ここで述べるインタフェースを使用します。標準 C++ ライブラリがない場合は、付録 A に記載する RWTPtrHashDictionary 用インタフェースを使用してください。
unsigned long operator()(const K& x)コレクション中の同値キーは、型 EQ の同等オブジェクトにもとづいてグループ化されます。EQ は、次の公開メンバーを介して、このグループ化を保証しなければなりません。
bool operator()(const K& x, const K& y)これは、x と y が等しい場合に TRUE を返します。
RWTPtrHashMap<K,T,H,EQ> は、コレクション内の既存のキーと等しいキーは受け付けません (RWTPtrHashMultiMap<K,T,H,EQ> には、互いに等しい複数のキーを含めることができます)。等しいかどうかは、== 演算子ではなく、比較オブジェクトにもとづいて判定されます。
//
// 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));
//二重挿入が拒絶された
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;
}
|
There was 1 second place winner. |
クラス rw_hashmap<K*,T*,rw_deref_hash<H,K>,rw_deref_compare<C,K>> は、このコレクションの基礎となる実装として使用される C++ 標準スタイルコレクションです。
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;
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);
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);
void apply(void (*fn)(const K*, T*&,void*),void* d); void apply(void (*fn)(const K*,const T*,void*),void* d) const;
void yourfun(const K* key, T*& a, void* d);
void yourfun(const K* key, const T* a, void* d);
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;
bool yourTester(value_type a, void* d);
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;
bool yourTester(value_type a, void* d);
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;
bool yourTester(value_type a, void* d);
K* remove(const K* key);
K* remove(bool (*fn)(value_type,void*), void* d);
bool yourTester(value_type a, void* d);
size_type removeAll(const K* key);
size_type removeAll(bool (*fn)(value_type,void*), void* d);
bool yourTester(value_type a, 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;
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);
