📄 hashtablediagnose.h
字号:
// file: $isip/class/dstr/HashTable/HashTableDiagnose.h// version: $Id: HashTableDiagnose.h,v 1.10 2001/04/30 02:03:57 duncan Exp $//// make sure definitions are only made once//#ifndef ISIP_HASH_TABLE_DIAGNOSE#define ISIP_HASH_TABLE_DIAGNOSE// isip include files//#ifndef ISIP_HASH_TABLE#include <HashTable.h>#endif// HashTableDiagnose: a class that contains the diagnose method of// HashTable class.//template<class THashable, class TObject>class HashTableDiagnose : public HashTable<THashable, TObject> { //--------------------------------------------------------------------------- // // public constants // //---------------------------------------------------------------------------public: // define the class name // //---------------------------------------- // // i/o related constants // //---------------------------------------- //---------------------------------------- // // default values and arguments // //---------------------------------------- // default values // // default arguments to methods // //---------------------------------------- // // error codes // //---------------------------------------- //--------------------------------------------------------------------------- // // protected data // //---------------------------------------------------------------------------protected: //--------------------------------------------------------------------------- // // required public methods // //---------------------------------------------------------------------------public: // method: name // static const String& name() { return HashTable<THashable, TObject>::name(); } // other static methods // static boolean diagnose(Integral::DEBUG debug_level); // debug methods // these methods are omitted since this class does not have data // members and operations // // destructor/constructor(s): // these methods are omitted since this class does not have data // members and operations // // assign methods: // these methods are omitted since this class does not have data // members and operations // // operator= methods: // these methods are omitted since this class does not have data // members and operations // // i/o methods: // these methods are omitted since this class does not have data // members and operations // // equality methods: // these methods are omitted since this class does not have data // members and operations // // memory-management methods: // these methods are omitted since this class does not have data // members and operations // //--------------------------------------------------------------------------- // // class-specific public methods // //--------------------------------------------------------------------------- // these methods are omitted since this class does not have data // members and operations // //--------------------------------------------------------------------------- // // private methods // //---------------------------------------------------------------------------private:}; // below are all the methods for the HashTableDiagnose template class////-----------------------------------------------------------------------------//// required static methods////-----------------------------------------------------------------------------// method: diagnose//// arguments:// Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//template<class THashable, class TObject>boolean HashTableDiagnose<THashable, TObject>::diagnose(Integral::DEBUG level_a) { //---------------------------------------------------------------------- // // 0. preliminaries // //---------------------------------------------------------------------- // output the class name // if (level_a > Integral::NONE) { SysString output(L"diagnosing class "); output.concat(CLASS_NAME); output.concat(L": "); Console::put(output); Console::increaseIndention(); } //--------------------------------------------------------------------- // // 1. required public methods // //--------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing required public methods...\n"); Console::increaseIndention(); } // test the debug methods // setDebug(debug_level_d); if (level_a > Integral::BRIEF) { Integral::debug(L"debug"); } // prepare items and keys for all the hash tables used in this diagnose // long num_elem = 20; Char** items = new Char*[num_elem]; String* keys = new String[num_elem]; Char key_char; for (long i = 0; i < num_elem; i++) { items[i] = new Char((unichar)((int)'a' + i)); key_char.assign((unichar)((int)'a' + i)); keys[i].assign(key_char); keys[i].concat(L"-key"); } // we change some keys in order to create some collisions // keys[5].assign(L"ab-key"); // hashes to 17 from 49 keys[9].assign(L"az-key"); // hashes to 17 from 49 keys[13].assign(L"ad-key"); // hashes to 17 from 49 keys[15].assign(L"ah-key"); // hashes to 1 from 49 keys[19].assign(L"aa-key"); // hashes to 1 from 49 // test constructors // HashTable<String, Char> def_htable(SYSTEM, (long)50); if (def_htable.getCapacity() != (long)50) { Long cap = def_htable.getCapacity(); cap.debug(L"capacity"); return Error::handle(name(), L"constructor", Error::TEST, __FILE__, __LINE__); } for (long i = 0; i < num_elem; i++) { def_htable.insert(keys[i], items[i]); } // copy constructor // HashTable<String, Char> copy_htable(def_htable); // the two constructed hash tables should be the same now // if (def_htable.ne(copy_htable)) { def_htable.debug(L"def_htable"); return Error::handle(name(), L"copy constructor", Error::TEST, __FILE__, __LINE__); } { // test constructors // HashTable<String, Char> def_htable; if (def_htable.getCapacity() != (long)128) { return Error::handle(name(), L"constructor", Error::TEST, __FILE__, __LINE__); } for (long i = 0; i < num_elem; i++) { def_htable.insert(keys[i], items[i]); } // copy constructor // HashTable<String, Char> copy_htable(def_htable); // the two constructed hash tables should be the same now // if (def_htable.ne(copy_htable)) { def_htable.debug(L"def_htable"); return Error::handle(name(), L"copy constructor", Error::TEST, __FILE__, __LINE__); } } // check the constructors and destructors for allocating on the dynamic // memory heap // HashTable<String, Char>* def_dyn_htable = new HashTable<String, Char>(SYSTEM, (long)50); if (def_dyn_htable->getCapacity() != (long)50) { return Error::handle(name(), L"constructor", Error::TEST, __FILE__, __LINE__); } for (long i = 0; i < num_elem; i++) { def_dyn_htable->insert(keys[i], items[i]); } HashTable<String, Char>* copy_dyn_htable = new HashTable<String, Char>(*def_dyn_htable); // the two constructed hash tables should be the same now // if (def_dyn_htable->ne(*copy_dyn_htable)) { return Error::handle(name(), L"copy constructor", Error::TEST, __FILE__, __LINE__); } // see if we can dynamically delete // delete def_dyn_htable; delete copy_dyn_htable; { // check the constructors and destructors for allocating on the dynamic // memory heap // HashTable<String, Char>* def_dyn_htable = new HashTable<String, Char>(); if (def_dyn_htable->getCapacity() != (long)128) { return Error::handle(name(), L"constructor", Error::TEST, __FILE__, __LINE__); } for (long i = 0; i < num_elem; i++) { def_dyn_htable->insert(keys[i], items[i]); } HashTable<String, Char>* copy_dyn_htable = new HashTable<String, Char>(*def_dyn_htable); // the two constructed hash tables should be the same now // if (def_dyn_htable->ne(*copy_dyn_htable)) { return Error::handle(name(), L"copy constructor", Error::TEST, __FILE__, __LINE__); } // see if we can dynamically delete // delete def_dyn_htable; delete copy_dyn_htable; } // check the constructors for allocating on the stack // HashTable<String, Char> def_htable_2(USER, (long)50); if (def_htable_2.getCapacity() != (long)50) { return Error::handle(name(), L"constructor", Error::TEST, __FILE__, __LINE__); } for (long i = 0; i < num_elem; i++) { def_htable_2.insert(keys[i], items[i]); } // copy constructor // HashTable<String, Char> copy_htable_2(def_htable_2); // the two constructed hash tables should be the same now // if (def_htable_2.ne(copy_htable_2)) { return Error::handle(name(), L"copy constructor", Error::TEST, __FILE__, __LINE__); } { // check the constructors for allocating on the stack // HashTable<String, Char> def_htable_2(USER); if (def_htable_2.getCapacity() != (long)128) { return Error::handle(name(), L"constructor", Error::TEST, __FILE__, __LINE__); } for (long i = 0; i < num_elem; i++) { def_htable_2.insert(keys[i], items[i]); } // copy constructor // HashTable<String, Char> copy_htable_2(def_htable_2); // the two constructed hash tables should be the same now // if (def_htable_2.ne(copy_htable_2)) { return Error::handle(name(), L"copy constructor", Error::TEST, __FILE__, __LINE__); } } // check the constructors and destructors for allocating on the dynamic // memory heap // HashTable<String, Char>* def_dyn_htable_2 = new HashTable<String, Char>(USER, (long)50); if (def_dyn_htable_2->getCapacity() != (long)50) { return Error::handle(name(), L"constructor", Error::TEST, __FILE__, __LINE__); } for (long i = 0; i < num_elem; i++) { def_dyn_htable_2->insert(keys[i], items[i]); } HashTable<String, Char>* copy_dyn_htable_2 = new HashTable<String, Char>(*def_dyn_htable_2); // the two constructed hash tables should be the same now // if (def_dyn_htable_2->ne(*copy_dyn_htable_2)) { return Error::handle(name(), L"copy constructor", Error::TEST, __FILE__, __LINE__); } // see if we can dynamically delete // delete def_dyn_htable_2; delete copy_dyn_htable_2; { // check the constructors and destructors for allocating on the dynamic // memory heap // HashTable<String, Char>* def_dyn_htable_2 = new HashTable<String, Char>(USER); if (def_dyn_htable_2->getCapacity() != (long)128) { return Error::handle(name(), L"constructor", Error::TEST, __FILE__, __LINE__); } for (long i = 0; i < num_elem; i++) { def_dyn_htable_2->insert(keys[i], items[i]); } HashTable<String, Char>* copy_dyn_htable_2 = new HashTable<String, Char>(*def_dyn_htable_2); // the two constructed hash tables should be the same now // if (def_dyn_htable_2->ne(*copy_dyn_htable_2)) { return Error::handle(name(), L"copy constructor", Error::TEST, __FILE__, __LINE__); } // see if we can dynamically delete // delete def_dyn_htable_2; delete copy_dyn_htable_2; } // test large allocation construction and deletion // if (level_a >= Integral::ALL) { // output an informative message // Console::put(L"\ntesting large chunk memory allocation and deletion:\n"); // set the memory to a strange block size so we can hopefully catch any // frame overrun errors // HashTable<THashable, TObject>::setGrowSize((long)13); // loop for a large number of times creating and deleting a large number // of htables at each loop // for (long j = 1; j <= 10; j++) { HashTable<String, Char>** htables = new HashTable<String, Char>*[j * 50]; HashTable<String, Char>** system_htables = new HashTable<String, Char>*[j * 50]; // create the items // for (long i = 0; i < j * 50; i++) { system_htables[i] = new HashTable<String, Char>(); htables[i] = new HashTable<String, Char>(USER);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -