Changeset 243 for 06/libkombilo-branches
- Timestamp:
- 03/22/07 22:41:18 (2 years ago)
- Files:
-
- 06/libkombilo-branches/hash_center/cpptest.cpp (modified) (1 diff)
- 06/libkombilo-branches/hash_center/process.py (modified) (2 diffs)
- 06/libkombilo-branches/hash_center/search.cpp (modified) (9 diffs)
- 06/libkombilo-branches/hash_center/search.h (modified) (2 diffs)
- 06/libkombilo-branches/hash_center/test_hash_center2.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/libkombilo-branches/hash_center/cpptest.cpp
r242 r243 29 29 gl.start_processing(); 30 30 directory_iterator end_itr; 31 //string path = "/home/ug/go/kombilo/06/hash_center";31 string path = "/home/ug/go/kombilo/06/hash_center"; 32 32 // string path = "/home/ug/go/gtl/reviews"; 33 string path = "/home/ug/go/gogod06/2001";33 // string path = "/home/ug/go/gogod06/2001"; 34 34 int counter = 0; 35 35 for(directory_iterator it(path); it != end_itr; ++it) { 06/libkombilo-branches/hash_center/process.py
r242 r243 10 10 11 11 try: 12 os.system('rm t1.db*')12 # os.system('rm t1.db*') 13 13 pass 14 14 except: … … 51 51 52 52 # filelist = glob.glob('./*.sgf') 53 filelist = glob.glob('/home/ug/go/gogod06/*/*.sgf')53 # filelist = glob.glob('/home/ug/go/gogod06/*/*.sgf') 54 54 # filelist = glob.glob('/home/ug/go/KGS/*/*.sgf') 55 #filelist = glob.glob('/home/ug/go/KGS2005/*.sgf')55 filelist = glob.glob('/home/ug/go/KGS2005/*.sgf') 56 56 57 57 filelist.sort() 06/libkombilo-branches/hash_center/search.cpp
r242 r243 2653 2653 } 2654 2654 2655 void HashCTREntry::add(int gameid, int pos, char ori, bool cs ) {2655 void HashCTREntry::add(int gameid, int pos, char ori, bool cs, bool do_sort) { 2656 2656 data.push_back(new HashhitCS(gameid, pos, ori, cs)); 2657 2657 // printf("HashCTREntry::add 1 gid: %d, ori: %d, pos: %d,l: %d\n", gameid, ori, pos, data.size()); 2658 if (d ata.size() > 1) sort(data.begin(), data.end(), cmp_HashhitCS);2659 } 2660 2661 void HashCTREntry::add(int gameid, int position, bool cs ) {2658 if (do_sort && data.size() > 1) sort(data.begin(), data.end(), cmp_HashhitCS); 2659 } 2660 2661 void HashCTREntry::add(int gameid, int position, bool cs, bool do_sort) { 2662 2662 data.push_back(new HashhitCS(gameid, position, cs)); 2663 2663 // printf("HashCTREntry::add 2 gid: %d, position: %d, l:%d\n", gameid, position, data.size()); 2664 if (d ata.size() > 1) sort(data.begin(), data.end(), cmp_HashhitCS);2665 } 2666 2667 char* HashCTREntry::to_charp() {2664 if (do_sort && data.size() > 1) sort(data.begin(), data.end(), cmp_HashhitCS); 2665 } 2666 2667 unsigned char* HashCTREntry::to_charp() { 2668 2668 // printf("to charp\n"); 2669 char* c = newchar[7*data.size()];2669 unsigned char* c = new unsigned char[7*data.size()]; 2670 2670 unsigned int i=0; 2671 2671 for(vector<HashhitCS* >::iterator it = data.begin(); it != data.end(); it++) { … … 2733 2733 // else printf("ok 3\n"); 2734 2734 } 2735 2736 for(set<pair<hashtype, int> >::iterator it = hash_vector.begin(); it != hash_vector.end(); it++) { 2735 2736 int counter = 0; 2737 for(map<hashtype, HashCTREntry* >::iterator it = all_hashes.begin(); it != all_hashes.end(); it++) { 2738 if (!(counter++ % 100)) printf("ctr %d\n", counter); 2737 2739 // printf("enter loop\n"); 2738 HashCTREntry* he = 0;2739 2740 rc = sqlite3_bind_int64(selStmt, 1, it->first); 2740 2741 if (rc != SQLITE_OK) printf("error 4a: %d\n", rc); // return rc; 2741 2742 rc = sqlite3_step(selStmt); 2742 2743 if (rc != SQLITE_DONE && rc != SQLITE_ROW) printf("error 4: %d\n", rc); // throw DBError(); 2743 // else printf("ok 4\n");2744 HashCTREntry* he = it->second; 2744 2745 if (rc == SQLITE_ROW) { 2745 2746 // printf("update %lld\n", it->first); 2746 he = new HashCTREntry((unsigned char*)sqlite3_column_blob(selStmt, 0), sqlite3_column_bytes(selStmt, 0)); 2747 // if (he->get_length() != sqlite3_column_bytes(selStmt, 0)) 2748 // printf("ouch %d %d\n", he->get_length(), sqlite3_column_bytes(selStmt, 0)); 2749 he->add(gid, it->second); 2750 char* he_charp = he->to_charp(); 2747 he->add((unsigned char*)sqlite3_column_blob(selStmt, 0), sqlite3_column_bytes(selStmt, 0), false, true); 2748 unsigned char* he_charp = he->to_charp(); 2751 2749 rc = sqlite3_bind_blob(updStmt, 1, he_charp, he->get_length(), SQLITE_TRANSIENT); 2752 2750 if (rc != SQLITE_OK) printf("error 5: %d\n", rc); // return rc; 2753 // else printf("ok 5\n");2754 2751 delete [] he_charp; 2755 2752 rc = sqlite3_bind_int64(updStmt, 2, it->first); 2756 2753 if (rc != SQLITE_OK) printf("error 6: %d\n", rc); // return rc; 2757 // else printf("ok 6\n");2758 2754 rc = sqlite3_step(updStmt); 2759 2755 if (rc != SQLITE_DONE) printf("error 7: %d\n", rc); // return rc; 2760 // else printf("ok 7\n");2761 2756 rc = sqlite3_reset(updStmt); 2762 2757 if (rc != SQLITE_OK) printf("error 8: %d\n", rc); // return rc; 2763 // else printf("ok 8\n");2764 // sqlite3_reset(selStmt);2765 // rc = sqlite3_step(selStmt);2766 // printf("new length %d\n", sqlite3_column_bytes(selStmt, 0));2767 delete he;2768 2758 } else { 2769 // printf("insert %lld\n", it->first);2770 he = new HashCTREntry();2771 he->add(gid, it->second);2772 2759 rc = sqlite3_bind_int64(insStmt, 1, it->first); 2773 2760 if (rc != SQLITE_OK) printf("error 9: %d\n", rc); // return rc; 2774 // else printf("ok 9\n"); 2775 char* he_charp = he->to_charp(); 2761 unsigned char* he_charp = he->to_charp(); 2776 2762 rc = sqlite3_bind_blob(insStmt, 2, he_charp, he->get_length(), SQLITE_TRANSIENT); 2777 2763 if (rc != SQLITE_OK) printf("error 10: %d\n", rc); // return rc; 2778 // else printf("ok 10\n");2779 2764 delete [] he_charp; 2780 2765 rc = sqlite3_step(insStmt); 2781 2766 if (rc != SQLITE_DONE) printf("error 11: %d\n", rc); // return rc; 2782 // else printf("ok 11\n");2783 2767 rc = sqlite3_reset(insStmt); 2784 2768 if (rc != SQLITE_OK) printf("error 12: %d\n", rc); // return rc; 2785 // else printf("ok 12\n"); 2786 // sqlite3_reset(selStmt); 2787 // rc = sqlite3_step(selStmt); 2788 // printf("new length %d\n", sqlite3_column_bytes(selStmt, 0)); 2789 delete he; 2790 } 2769 } 2770 delete he; 2791 2771 rc = sqlite3_reset(selStmt); 2792 2772 if (rc != SQLITE_OK) printf("error 13: %d\n", rc); // throw DBError(); 2793 // else printf("ok 13\n");2794 }2773 } 2774 all_hashes.clear(); 2795 2775 return 0; // success 2796 2776 } … … 2799 2779 // printf("enter algo_hash::initialize_processing\n"); 2800 2780 db = DB; 2781 all_hashes.clear(); 2801 2782 char buf[200]; 2802 2783 sprintf(buf, "create table if not exists algo_hash_%d_%s ( hash integer, data blob );", boardsize, dbnameext.c_str()); … … 2873 2854 (*it)->finalize(); 2874 2855 if (commit) { 2875 int rc = insert_all_hashes(); 2876 if (rc) printf("ouch %d\n",rc); 2877 hash_vector.clear(); 2878 } else hash_vector.clear(); 2856 for(set<pair<hashtype, int> >::iterator it = hash_vector.begin(); it != hash_vector.end(); it++) { 2857 HashCTREntry* he = 0; 2858 map<hashtype, HashCTREntry* >::iterator ah_it = all_hashes.find(it->first); 2859 if (ah_it != all_hashes.end()) { 2860 ah_it->second->add(gid, it->second, false, false); 2861 } else { 2862 he = new HashCTREntry(); 2863 he->add(gid, it->second); 2864 all_hashes[it->first] = he; 2865 } 2866 } 2867 } 2868 hash_vector.clear(); 2879 2869 } 2880 2870 2881 2871 void Algo_hash::finalize_process() { 2882 int rc; 2872 int rc = insert_all_hashes(); 2873 if (rc) printf("ouch %d\n",rc); 2874 2883 2875 rc = sqlite3_finalize(insStmt); 2884 2876 if (rc != SQLITE_OK) printf("error 14: %d\n", rc); // return rc; … … 3023 3015 else index = patternList.flipTable[*flip + 8]; 3024 3016 // printf("%d %d %d %d make cand %d, %d, %d\n", pos, ori, fl, *flip, pos_left, pos_top, index); 3025 candidates->push_back(new Candidate(pos_left, pos_top, index)); 3017 if (patternList.data[index].left <= pos_left && pos_left <= patternList.data[index].right && patternList.data[index].top <= pos_top && pos_top <= patternList.data[index].bottom) 3018 candidates->push_back(new Candidate(pos_left, pos_top, index)); 3026 3019 } 3027 3020 delete f_list; … … 3142 3135 string sql = buf; 3143 3136 3144 PatternList* sub_pl1 ;3137 PatternList* sub_pl1 = 0; 3145 3138 int fl2 = fl; 3146 3139 if (patternList.data[patternList.size()-1].colorSwitch) { … … 4890 4883 hash_result = ((Algo_hash_corner*)algo_ps[algo_hash_corner+20*bs_index])->search(pl, *this, *searchOptions, algo_dbs[algo_hash_corner+20*bs_index]); 4891 4884 if (hash_result == 0) { 4885 // printf("hash_corner\n"); 4892 4886 if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist+20*bs_index]) 4893 // printf("movelist 0\n");4894 4887 algo_ps[algo_movelist+20*bs_index]->search(pl, *this, *searchOptions); 4895 4888 } … … 4901 4894 hash_result = ((Algo_hash_center*)algo_ps[algo_hash_center+20*bs_index])->search(pl, *this, *searchOptions, algo_dbs[algo_hash_center+20*bs_index]); 4902 4895 if (hash_result == 0) { 4903 // printf(" movelist after center hash\n");4896 // printf("hash_center\n"); 4904 4897 if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist+20*bs_index]) 4905 4898 algo_ps[algo_movelist+20*bs_index]->search(pl, *this, *searchOptions); … … 4907 4900 } 4908 4901 if (hash_result == -1) { 4902 // printf("finalpos\n"); 4909 4903 if (searchOptions->algos & ALGO_FINALPOS && algo_ps[algo_finalpos+20*bs_index]) 4910 4904 algo_ps[algo_finalpos+20*bs_index]->search(pl, *this, *searchOptions); 4911 // printf("movelist\n");4912 4905 if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist+20*bs_index]) 4913 4906 algo_ps[algo_movelist+20*bs_index]->search(pl, *this, *searchOptions); 06/libkombilo-branches/hash_center/search.h
r242 r243 524 524 525 525 void add(unsigned char* c, int l, bool cs, bool do_sort = true); 526 void add(int gameid, int pos, char ori, bool cs = false );527 void add(int gameid, int position, bool cs = false );528 char* to_charp();526 void add(int gameid, int pos, char ori, bool cs = false, bool do_sort = true); 527 void add(int gameid, int position, bool cs = false, bool do_sort = true); 528 unsigned char* to_charp(); 529 529 int get_length(); 530 530 }; … … 558 558 int maxNumStones; 559 559 std::set<std::pair<hashtype, int> > hash_vector; 560 std::map<hashtype, HashCTREntry* > all_hashes; 560 561 virtual int insert_hash(hashtype hashCod, int pos); 561 562 int insert_all_hashes(); 06/libkombilo-branches/hash_center/test_hash_center2.py
r242 r243 52 52 (gl.lookupLabel(x,y), cont.B, cont.wB, cont.lB, cont.W, cont.wW, cont.lW)) 53 53 54 if nh_result != h_result: 55 print nh_result 56 print h_result 57 raise Exception() 54 if ''.join(nh_result) != ''.join(h_result): 55 out1 = open('nh_result', 'ab') 56 out1.write(''.join(nh_result)) 57 out1.close() 58 out2 = open('h_result', 'ab') 59 out2.write(''.join(h_result)) 60 out1.close() 58 61 return (nohash_time, hash_time) 59 62 … … 102 105 103 106 start = time.time() 104 gl = GameList( 't1.db')107 gl = GameList(sys.argv[1] + '.db') 105 108 end = time.time() 106 109 print gl.size(), 'games in the database' … … 108 111 for pattern in pl: 109 112 print pattern.printPattern() 110 print 'nh, h:', timed_search(gl, pattern) 113 print timed_search(gl, pattern) 114 print 'num hits:', gl.num_hits 115 print '..................................................................' 116 print 111 117
