⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hashtablediagnose.h

📁 这是一个从音频信号里提取特征参量的程序
💻 H
📖 第 1 页 / 共 3 页
字号:
      }            // delete hash tables      //      for (long i = (j * 50) - 1; i >= 0; i--) {	delete htables[i];	delete system_htables[i];      }            // clean up memory      //      delete [] htables;      delete [] system_htables;    }  }    // test assign methods  //  HashTable<String, Char> tmp_htable;  HashTable<String, Char>* tmp_dyn_htable = new HashTable<String, Char>();  // USER-allocated  //  HashTable<String, Char> tmp_htable_1(USER);  HashTable<String, Char>* tmp_dyn_htable_1 = new HashTable<String, Char>(USER);    // add some items into the htable  //  for (long i = 0; i < num_elem; i++) {    tmp_htable.insert(keys[i], items[i]);  }    // try the htable assign method  //  tmp_dyn_htable->assign(tmp_htable);  tmp_htable_1.assign(*tmp_dyn_htable_1);    if ((tmp_htable_1.ne(*tmp_dyn_htable_1)) ||      (tmp_dyn_htable_1->ne(tmp_htable_1))) {    return Error::handle(name(), L"assign", Error::TEST, __FILE__,			 __LINE__);  }    if ((tmp_dyn_htable->ne(tmp_htable)) ||      (tmp_htable.ne(*tmp_dyn_htable))) {    return Error::handle(name(), L"assign", Error::TEST, __FILE__,			 __LINE__);  }    // clean up  //  delete tmp_dyn_htable;  delete tmp_dyn_htable_1;  // testing i/o methods  //  String text_filename;  Integral::makeTemp(text_filename);  String bin_filename;  Integral::makeTemp(bin_filename);  // open files in write mode  //  Sof text_file;  text_file.open(text_filename, File::WRITE_ONLY, File::TEXT);  Sof bin_file;  bin_file.open(bin_filename, File::WRITE_ONLY, File::BINARY);    // prepare items for the htables  //  Char** write_chars = new Char*[10];  String** write_strings = new String*[10];  Vector<Char>* vec_chars = new Vector<Char>[10];  unichar tmp_char = L'a';    for (long i = 0; i < 10; i++) {    write_chars[i] = new Char(tmp_char);    write_strings[i] = new String();    vec_chars[i].setLength(5);    vec_chars[i].assign(*write_chars[i]);    tmp_char++;  }    write_strings[0]->assign(L"this ");  write_strings[1]->assign(L"is");  write_strings[2]->assign(L"a");  write_strings[3]->assign(L"HashTable");  write_strings[4]->assign(L"String");  write_strings[5]->assign(L"this ");  write_strings[6]->assign(L"is");  write_strings[7]->assign(L"in");  write_strings[8]->assign(L"the");  write_strings[9]->assign(L"diagnose");    // create hash tables to write, we set a small capacity on purpose  //  HashTable<String, Char> write_char_htable(USER, (long)20);  HashTable<String, String> write_str_htable(USER, (long)20);  HashTable<String,  Vector<Char> > write_vec_char_htable(USER, (long)20);  HashTable<String, Long> write_empty_hash;  HashTable<String, Long> write_nested_hash;    Long l;  l = 8;  String object_name(L"Object");  write_nested_hash.insert(object_name, &l);  for ( long i = 0; i < 10; i++) {    write_char_htable.insert(keys[i], write_chars[i]);    write_str_htable.insert(keys[i], write_strings[i]);    write_vec_char_htable.insert(keys[i], &vec_chars[i]);  }    // print our some hash tables  //  if (level_a >= Integral::ALL) {    write_str_htable.debug(L"write_str_htable");  }    // write the values  //  write_char_htable.write(text_file, (long)0);  write_char_htable.write(bin_file, (long)0);    write_str_htable.write(text_file, (long)0);  write_str_htable.write(bin_file, (long)0);  write_vec_char_htable.write(text_file, (long)0);  write_vec_char_htable.write(bin_file, (long)0);  String hash_name(L"hash");  text_file.put(object_name, 0, -1);  write_empty_hash.writeData(text_file, hash_name);  l.writeData(text_file);  bin_file.put(object_name, 0, write_empty_hash.sofSize() + l.sofSize());  write_empty_hash.writeData(bin_file, hash_name);  l.writeData(bin_file);    text_file.put(object_name, 1, -1);  write_nested_hash.writeData(text_file, hash_name);  l.writeData(text_file);  bin_file.put(object_name, 1, write_empty_hash.sofSize() + l.sofSize());  write_nested_hash.writeData(bin_file, hash_name);  l.writeData(bin_file);  // close the files  //  text_file.close();  bin_file.close();  // open the files in read mode  //  text_file.open(text_filename);  bin_file.open(bin_filename);    // create objects for reading in  //  HashTable<String, Char> read_char_htable_text;  HashTable<String, Char> read_char_htable_bin;  HashTable<String, String> read_str_htable_text;  HashTable<String, String> read_str_htable_bin;  HashTable< String, Vector<Char> > read_vec_char_htable_text;  HashTable< String, Vector<Char> > read_vec_char_htable_bin;  HashTable<String, Long> read_empty_text;  HashTable<String, Long> read_empty_bin;    // read in the hash tables and test for equivalence  // if there is error, print out the hash tables  //  if (!read_char_htable_text.read(text_file, (long)0) ||      (read_char_htable_text.ne(write_char_htable))) {    write_char_htable.debug(L"write_char_htable");    read_char_htable_text.debug(L"read_char_htable_text");    return Error::handle(name(), L"read char text", Error::TEST, __FILE__,			 __LINE__);  }    if (!read_char_htable_bin.read(bin_file, (long)0) ||      (read_char_htable_bin.ne(write_char_htable))) {    write_char_htable.debug(L"write_char_htable");    read_char_htable_bin.debug(L"read_char_htable_bin");    return Error::handle(name(), L"read char bin", Error::TEST, __FILE__,			 __LINE__);  }    if (!read_str_htable_text.read(text_file, (long)0) ||      (read_str_htable_text.ne(write_str_htable))) {    write_str_htable.debug(L"write_str_htable");    read_str_htable_text.debug(L"read_str_htable_text");    return Error::handle(name(), L"read str text", Error::TEST, __FILE__, 			 __LINE__);  }    if (!read_str_htable_bin.read(bin_file, (long)0) ||      (read_str_htable_bin.ne(write_str_htable))) {    write_str_htable.debug(L"write_str_htable");    read_str_htable_bin.debug(L"read_str_htable_bin");    return Error::handle(name(), L"read str bin", Error::TEST, __FILE__,			 __LINE__);  }    if (!read_vec_char_htable_text.read(text_file, (long)0) ||      (read_vec_char_htable_text.ne(write_vec_char_htable))) {    write_vec_char_htable.debug(L"write_vec_char_htable");    read_vec_char_htable_text.debug(L"read_vec_char_htable_text");    return Error::handle(name(), L"read vec_char text", Error::TEST, __FILE__,			 __LINE__);  }  if (!read_vec_char_htable_bin.read(bin_file, (long)0) ||      (read_vec_char_htable_bin.ne(write_vec_char_htable))) {    write_vec_char_htable.debug(L"write_vec_char_htable");    read_vec_char_htable_bin.debug(L"read_vec_char_htable_bin");    return Error::handle(name(), L"read vec_char bin", Error::TEST, __FILE__,			 __LINE__);  }  SofParser parser;  if (!text_file.find(object_name, 0)) {    return Error::handle(name(), L"find", Error::TEST, __FILE__, __LINE__);  }  parser.load(text_file);  if ((!read_empty_text.readData(text_file, hash_name,				parser.getEntry(text_file, hash_name),				false, true)) ||      (read_empty_text.ne(write_empty_hash))) {    read_empty_text.debug(L"read_empty_text");    write_empty_hash.debug(L"write_empty_hash");    return Error::handle(name(), L"read empty text", Error::TEST,			 __FILE__, __LINE__);  }  Long read_l;  if (!read_l.readData(text_file, Long::DEF_PARAM,		       parser.getEntry(text_file, Long::DEF_PARAM)) ||      read_l.ne(l)) {    return Error::handle(name(), L"read empty text", Error::TEST,			 __FILE__, __LINE__);  }        if (!text_file.find(object_name, 1)) {    return Error::handle(name(), L"find", Error::TEST, __FILE__, __LINE__);  }  parser.reset();  parser.load(text_file);  if ((!read_empty_text.readData(text_file, hash_name,				 parser.getEntry(text_file, hash_name),				 false, true)) ||      (read_empty_text.ne(write_nested_hash))) {    read_empty_text.debug(L"read_nested_text");    write_nested_hash.debug(L"write_nested_hash");    return Error::handle(name(), L"read empty text", Error::TEST,			 __FILE__, __LINE__);  }  if (!read_l.readData(text_file, Long::DEF_PARAM,		       parser.getEntry(text_file, Long::DEF_PARAM)) ||      read_l.ne(l)) {    return Error::handle(name(), L"read empty text", Error::TEST,			 __FILE__, __LINE__);  }      if (!bin_file.find(object_name, 0)) {    return Error::handle(name(), L"find", Error::TEST, __FILE__, __LINE__);  }  if ((!read_empty_bin.readData(bin_file, hash_name)) ||      (read_empty_bin.ne(write_empty_hash))) {    read_empty_bin.debug(L"read_empty_bin");    write_empty_hash.debug(L"write_empty_hash");    return Error::handle(name(), L"read empty bin", Error::TEST,			 __FILE__, __LINE__);  }  if (!read_l.readData(bin_file) ||      read_l.ne(l)) {    return Error::handle(name(), L"read empty bin ", Error::TEST,			 __FILE__, __LINE__);  }        if (!bin_file.find(object_name, 1)) {    return Error::handle(name(), L"find", Error::TEST, __FILE__, __LINE__);  }  if ((!read_empty_bin.readData(bin_file, hash_name)) ||      (read_empty_bin.ne(write_nested_hash))) {    read_empty_bin.debug(L"read_nested_bin");    write_nested_hash.debug(L"write_nested_hash");    return Error::handle(name(), L"read empty bin", Error::TEST,			 __FILE__, __LINE__);  }  if (!read_l.readData(bin_file, Long::DEF_PARAM) ||      read_l.ne(l)) {    return Error::handle(name(), L"read empty bin", Error::TEST,			 __FILE__, __LINE__);  }        // close and delete the temporary files  //  text_file.close();  bin_file.close();  // cleanup the memory that was created by the HashTable read  //  for ( long i = 0; i < 10; i++) {    delete write_chars[i];    delete write_strings[i];  }  delete [] write_chars;  delete [] write_strings;  delete [] vec_chars;  // test equality methods  //  HashTable<String, Char> char_ht_0(SYSTEM, (long)50);    // initialize the characters and store them in the htables  //  for (long i = 0; i < num_elem; i++) {        // add the character to the hash table    //    char_ht_0.insert(keys[i], items[i]);  }  // create another hash table the same as this  //  HashTable<String, Char> char_ht_1;  char_ht_1.assign(char_ht_0);    if (char_ht_0.getAllocationMode() != char_ht_1.getAllocationMode()) {    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);  }  if (!char_ht_0.eq(char_ht_1)) {    char_ht_0.debug(L"char_ht_0");    char_ht_1.debug(L"char_ht_1");    return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__);  }    if (char_ht_0.ne(char_ht_1)) {    return Error::handle(name(), L"ne", Error::TEST, __FILE__, __LINE__);  }  // test equality methods  //  HashTable<String, Char> char_ht_2(USER, (long)30);    // initialize the characters and store them in the htables  //  for (long i = 0; i < num_elem; i++) {        // add the character to the hash table    //    char_ht_2.insert(keys[i], items[i]);  }    // create another hash table the same as this  //  HashTable<String, Char> char_ht_3;  char_ht_3.assign(char_ht_2);  if (char_ht_3.getAllocationMode() != char_ht_2.getAllocationMode()) {    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);  }    if (!char_ht_2.eq(char_ht_3)) {    char_ht_2.debug(L"char_ht_2");    char_ht_3.debug(L"char_ht_3");    return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__);  }    if (char_ht_2.ne(char_ht_3)) {    return Error::handle(name(), L"ne", Error::TEST, __FILE__, __LINE__);  }    // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }      // --------------------------------------------------------------------  //  // 2. testing class-specific public methods  //     hash table manipulation methods  //  // --------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific public methods: hash table manipulation methods...\n");    Console::increaseIndention();   }  if (char_ht_0.getNumItems() != num_elem) {    return Error::handle(name(), L"put", Error::TEST, __FILE__, __LINE__);  }    // get the character by its key  //  for (long i = 0; i < num_elem; i++) {    Char* tmp_char = char_ht_0.get(keys[i]);    if (tmp_char->ne(*items[i])) {            tmp_char->debug(L"get char");      items[i]->debug(L"items[i]");      return Error::handle(name(), L"get", Error::TEST, __FILE__, __LINE__);    }  }  if (char_ht_2.getNumItems() != num_elem) {    return Error::handle(name(), L"put", Error::TEST, __FILE__, __LINE__);  }    // get the character by its key  //  for (long i = 0; i < num_elem; i++) {    Char* tmp_char = char_ht_2.get(keys[i]);    if (tmp_char->ne(*items[i])) {            tmp_char->debug(L"get char");      items[i]->debug(L"items[i]");      return Error::handle(name(), L"get", Error::TEST, __FILE__, __LINE__);    }  }    // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }  // --------------------------------------------------------------------  //  // 3. testing class-specific public methods  //     hash table data access methods  //  // --------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific public methods: hash table data access methods...\n");    Console::increaseIndention(); 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -