/* $XConsortium: cc_hdict.h /main/5 1996/08/21 15:49:02 drk $ */ #ifndef _cc_hdict_h #define _cc_hdict_h 1 #include "dti_cc/types.h" #include "dti_cc/cc_pvect.h" #include "dti_cc/CC_Slist.h" #include template class kv_pair { public: static CC_Boolean f_needRemove; kv_pair(K* k, V* v = 0): f_key(k), f_value(v) {}; ~kv_pair(); unsigned int operator==(const kv_pair&); #ifdef DEBUG ostream& print(ostream&); friend ostream& operator<<(ostream& out, kv_pair& kv) { return kv.print(out); } #endif K* f_key; V* f_value; }; #define DEFAULT_BUCKET_NUM 30 template class hashTableIterator; template class hashTable { //template //friend class hashTableIterator; friend class hashTableIterator; protected: pointer_vector > > f_buckets; unsigned (*f_hash_func_ptr)(const K&); size_t f_items; protected: kv_pair* _find(const K* k) const; public: hashTable(const hashTable &); hashTable(unsigned (*)(const K&), size_t init_bucket_num = DEFAULT_BUCKET_NUM ); ~hashTable(); void clearAndDestroy(); size_t entries() { return f_items; }; CC_Boolean contains(const K*) const; V* findValue(const K*) const; K* findKeyAndValue(const K*, V*&) const; void insertKeyAndValue(K*, V*); K* remove(const K*); #ifdef DEBUG ostream& print(ostream& out); friend ostream& operator<<(ostream& out, hashTable& ht) { return ht.print(out); }; #endif }; template class hashTableIterator { protected: size_t f_bucket_num; size_t f_pos; kv_pair* f_rec; hashTable& f_hashTable; CC_Boolean _findNonEmptyBucket(); CC_Boolean _findNextRecord(); public: hashTableIterator(hashTable&); ~hashTableIterator(); CC_Boolean operator++(); K* key(); V* value() const; }; #ifdef EXPAND_TEMPLATES #include "cc_hdict.C" #endif #endif