Пример #1
0
int main(int argc, char* argv[])
{
    if (argc < 2)
    {
        STXXL_MSG("Usage: " << argv[0] << " #log_ins");
        return -1;
    }

    const int log_nins = atoi(argv[1]);
    if (log_nins > 31) {
        STXXL_ERRMSG("This test can't do more than 2^31 operations, you requested 2^" << log_nins);
        return -1;
    }

    btree_type BTree(1024 * 128, 1024 * 128);

    const stxxl::uint64 nins = 1ULL << log_nins;

    stxxl::ran32State = (unsigned int)time(NULL);


    stxxl::vector<int> Values(nins);
    STXXL_MSG("Generating " << nins << " random values");
    stxxl::generate(Values.begin(), Values.end(), rnd_gen(), 4);

    stxxl::vector<int>::const_iterator it = Values.begin();
    STXXL_MSG("Inserting " << nins << " random values into btree");
    for ( ; it != Values.end(); ++it)
        BTree.insert(std::pair<int, double>(*it, double(*it) + 1.0));


    STXXL_MSG("Number of elements in btree: " << BTree.size());

    STXXL_MSG("Searching " << nins << " existing elements");
    stxxl::vector<int>::const_iterator vIt = Values.begin();

    for ( ; vIt != Values.end(); ++vIt)
    {
        btree_type::iterator bIt = BTree.find(*vIt);
        STXXL_CHECK(bIt != BTree.end());
        STXXL_CHECK(bIt->first == *vIt);
    }

    STXXL_MSG("Searching " << nins << " non-existing elements");
    stxxl::vector<int>::const_iterator vIt1 = Values.begin();

    for ( ; vIt1 != Values.end(); ++vIt1)
    {
        btree_type::iterator bIt = BTree.find((*vIt1) + 1);
        STXXL_CHECK(bIt == BTree.end());
    }

    STXXL_MSG("Test passed.");

    return 0;
}
Пример #2
0
std::string EasyUtil::GetUUID()
{
	try
	{
		boost::uuids::random_generator rnd_gen;
		boost::uuids::uuid u = rnd_gen();
		std::string s = boost::uuids::to_string(u);
		boost::erase_all(s, "-");
		return s;
	}
	catch (std::exception &e)
	{
		printf("SysUtil::GetUUID error: %s\n", e.what());
		return std::string();
	}
}
Пример #3
0
void
test_subsets(){
	bj_ostream& os = bj_out;

	MARK_USED(os);

	row<bool> dbg_arr;
	dbg_arr.fill(false, DBG_NUM_LEVS);
	
	dbg_arr[2] = true;

	GSKE.kg_root_path = TEST_ROOT_PATH;
	GSKE.init_paths();
	GSKE.print_paths(os);

	ch_string GSKE_ROOT = GSKE.kg_root_path + SKG_SKELETON_DIR;
	os << "WARNING !!! deleting '" << GSKE_ROOT << "'" << bj_eol;
	delete_directory(GSKE_ROOT);
	//dbg_arr[80] = true;

	long num_test_to_gen = 1000;
	//unsigned long init_val = (long)(run_time());
	unsigned long init_val = 10;
	tak_mak rnd_gen(init_val);

	for(long aa = 0; aa < num_test_to_gen; aa++){
		test_pair_subsets(rnd_gen, aa);
		os << aa << " ";
		os.flush();
	}
	os << bj_eol;

	GSKE.clear_all();

	os << "2. FINISHING ..."  << bj_eol;
	os.flush();
}
Пример #4
0
bool	test_nw_srt_from(long test_consec, long start_rnd, avg_stat& spd_avg, 
						 bool DEBUG_SRT_FROM = false, bool SPEED_TEST = false)
{
	std::ostream& os = std::cout;
	os << "TEST " << test_consec << "(seed=" << start_rnd << ")";
	os.flush();

	sort_glb glb1;
	//glb1.init_head_ss();
	glb1.stab_mutual_init();

	//os << "START_RND=" << start_rnd << std::endl;

	tak_mak rnd_gen(start_rnd);

	k_row<elem_sor> all_elem;

	row<op_sor> all_ops;
	if(SPEED_TEST){
		all_ops.set_cap(10000);
	}

	long num_elem = rnd_gen.gen_rand_int32_ie(1, 1000);
	all_elem.set_cap(num_elem);
	for(long aa = 0; aa <= num_elem; aa++){
		elem_sor& ele = all_elem.inc_sz();
		ele.es_id = "e=";
	}


	row<elem_sor*> tmp_rr1;
	row<elem_sor*> tmp_rr2;
	bool stop_all = false;

	std::stringstream ss_tmp;
	
	long num_lvs = rnd_gen.gen_rand_int32_ie(1, 10);
	for(long bb = 1; ((bb < num_lvs) && ! stop_all); bb++){
		glb1.sg_curr_stab_consec++;
		
		DBG_CK(glb1.sg_curr_stab_consec >= bb);
		DBG_CK(glb1.sg_curr_stab_consec >= glb1.sg_dbg_last_id);
		
		std::string bb_ss = long_to_str(bb);
		long num_reps_lv = rnd_gen.gen_rand_int32_ie(1, 10);
		for(long dd = 0; ((dd < num_reps_lv) && ! stop_all); dd++){
			DBG_CK(glb1.sg_curr_stab_consec >= glb1.sg_dbg_last_id);
			
			long num_elem_rep = rnd_gen.gen_rand_int32_ie(1, num_elem);
			for(long cc = 0; ((cc < num_elem_rep) && ! stop_all); cc++){
				DBG_CK(glb1.sg_curr_stab_consec >= glb1.sg_dbg_last_id);
				
				bool all_csecs = false;
				long elem_idx = rnd_gen.gen_rand_int32_ie(1, num_elem);
				SORTER_CK(all_elem.is_valid_idx(elem_idx));
				elem_sor& ele = all_elem[elem_idx];

				if(DEBUG_SRT_FROM){
					ss_tmp.clear();
					ss_tmp.seekg(0, std::ios::beg);
					ss_tmp.str("");
					ss_tmp.flush();

					glb1.sort_to_row_and_all_consec<elem_sor>(tmp_rr1, all_csecs);
					tmp_rr1.print_row_data(ss_tmp, true, "\n");

					if(! tmp_rr1.is_sorted(cmp_elem_sr)){
						//tmp_rr1.print_row_data(os, true, "\n");
						std::string out_ss = ss_tmp.str();
						os << out_ss;
						os << "FAILED starting" << std::endl << ele << std::endl;
						os << "START_RND=" << start_rnd << std::endl;
						stop_all = true;
						break;
					}
				}

				std::string dbg_id_start = ele.es_id;

				if(SPEED_TEST){
					op_sor& the_op = all_ops.inc_sz();
					the_op.op_elem = &ele;
					the_op.op_id = bb;
				} else {
					DBG_CK(glb1.sg_curr_stab_consec >= bb);
					DBG_CK(glb1.sg_curr_stab_consec >= glb1.sg_dbg_last_id);
					ele.es_srt_bdr.sort_from(glb1, bb);
					DBG_CK(glb1.sg_curr_stab_consec >= glb1.sg_dbg_last_id);
				}

				ele.es_id += "b" + bb_ss;
				ele.add(bb);

				std::string dbg_id_end = ele.es_id;

				if(DEBUG_SRT_FROM){
					glb1.sort_to_row_and_all_consec<elem_sor>(tmp_rr2, all_csecs);
					if(! tmp_rr2.is_sorted(cmp_elem_sr)){
						os << "STARTING" << std::endl;
						std::string out_ss = ss_tmp.str();
						os << out_ss;
						//tmp_rr1.print_row_data(os, true, "\n");
						os << std::endl << std::endl << "ENDING" << std::endl;
						tmp_rr2.print_row_data(os, true, "\n");
						os << "FAILED ending" << std::endl << ele << std::endl;
						os << "curr_id=" << bb << std::endl;
						os << "dbg_id_start=" << dbg_id_start << std::endl;
						os << "dbg_id_end=" << dbg_id_end << std::endl;
						os << "START_RND=" << start_rnd << std::endl;
						stop_all = true;
						ck_sorted_elems(tmp_rr2, cmp_elem_sr);
						break;
					}
				}
			}
		}
	}
	os << "::";
	os.flush();
	//DBG_CK(glb1.sg_curr_stab_consec >= glb1.sg_dbg_last_id);

	long num_srt_from = 0;
	double run_speed = 0;
	if(SPEED_TEST){
		double start_tm = cpu_time();

		for(long aa = 0; aa < all_ops.size(); aa++){
			op_sor& the_op = all_ops[aa];
			SORTER_CK(the_op.op_elem != NULL_PT);
			SORTER_CK(the_op.op_id > 0);
			the_op.op_elem->es_srt_bdr.sort_from(glb1, the_op.op_id);
			num_srt_from++;
		}
		double finish_tm = cpu_time();

		run_speed = num_srt_from / (finish_tm - start_tm);

		if(finite(run_speed)){
			spd_avg.add_val(run_speed);
		}
	}
	//DBG_CK(glb1.sg_curr_stab_consec >= glb1.sg_dbg_last_id);

	if(! stop_all){
		row<elem_sor*> s_rr;
		bool all_in_consec = false;
		glb1.sort_to_row_and_all_consec<elem_sor>(s_rr, all_in_consec);

		os << " #elem=" << num_elem << " #ops=" << num_srt_from << " speed=" << run_speed 
			<< " finite=" << finite(run_speed);

		//os << "SIZE=" << s_rr.size() << bj_eol;
		//s_rr.print_row_data(os, true, "\n");

		//os << "NUM_ELEM=" << num_elem << std::endl;
		//os << "START_RND=" << start_rnd << std::endl;
		//os << std::endl;

		bool finish_ok = true;

		if(! s_rr.is_sorted(cmp_elem_sr)){
			s_rr.print_row_data(os, true, "\n");
			os << " START_RND=" << start_rnd << std::endl;
			SORTER_CK(ck_sorted_elems(s_rr, cmp_elem_sr));
			finish_ok = false;
		}

		glb1.sort_to_tmp_srss();
		if(! glb1.sg_tmp_srss.is_sorted(cmp_sorsets)){
			s_rr.print_row_data(os, true, "\n");
			os << " START_RND=" << start_rnd << std::endl;
			ck_sorted_sorsets(glb1.sg_tmp_srss, cmp_sorsets);
			SORTER_CK(false);
			finish_ok = false;
		}
		//os << "FINISHED OK=" << start_rnd << std::endl;
		if(finish_ok){
			os << " finished ok";
		} else {
			os << " FAILED !!!!!!!!!!!!!!!!!!!!!!!!!!!!";
			os.flush();
			abort_func(0);
		}

		//os << std::endl;

		//glb1.release_all();
		//glb1.init_head_ss();
		glb1.stab_mutual_init();
	}
	//os << "START_RND=" << start_rnd << std::endl;
	
	return ! stop_all;
}
Пример #5
0
void
test_skl(){
	row<bool> dbg_arr;
	dbg_arr.fill(false, DBG_NUM_LEVS);
	
	dbg_arr[2] = true;
	//dbg_arr[95] = true;

	bj_ostream& os = bj_out;
	MARK_USED(os);

	GSKE.kg_root_path = TEST_ROOT_PATH;

	ch_string GSKE_ROOT = GSKE.kg_root_path + SKG_SKELETON_DIR;
	os << "WARNING !!! deleting '" << GSKE_ROOT << "'" << bj_eol;
	delete_directory(GSKE_ROOT);

	GSKE.init_paths();
	GSKE.print_paths(os);

	GSKE.kg_find_cnn_pth = true;
	GSKE.kg_dbg_verifying_skeleton_tree = false;
	GSKE.kg_dbg_only_save = false;

	os << "Type RETURN ..." << bj_eol;
	getchar();

	GSKE.kg_dbg_save_canon = true;

	//dbg_arr[107] = true;
	dbg_arr[73] = true;
	//dbg_arr[76] = true;
	//dbg_arr[78] = true;
	//dbg_arr[108] = true;
	//dbg_arr[109] = true;

	//ccl_skl_walker& skl_wlkr = GSKE.kg_ccl_wlkr;
	//clause_walker& wlkr = skl_wlkr.fw_walker;

	canon_cnf the_cnf;
	//wlkr.cw_cnf = &the_cnf;

	//unsigned long init_val = (long)(run_time());
	unsigned long init_val = 10;

	tak_mak rnd_gen(init_val);
	tak_mak rnd_gen2(init_val);

	glb_test_tak_mak = &rnd_gen2;

	long NUM_CNFS = 50;

	long max_ccl_sz = 5;
	long max_num_ccls_cnf = 200;
	long max_num_vars_cnf = 50;

	ch_string rr_pth = SKG_REF_DIR;
	ch_string r1_pth = rr_pth + "/test_ref1/";
	ch_string r2_pth = rr_pth + "/test_ref2/";
	ch_string r3_pth = rr_pth + "/test_ref3/";

	GSKE.ref_create(r1_pth);
	GSKE.ref_create(r2_pth);
	GSKE.ref_create(r3_pth);

	//GSKE.report_err("a_missing_path", GSKE.kg_missing_path);

	ch_string skl_nt_pth = GSKE.as_full_path(SKG_CNF_DIR);

	os << "1. SAVING TEST ..."  << bj_eol;
	
	for(long aa = 0; aa < NUM_CNFS; aa++){
		the_cnf.release_and_init(GSKE, true);
		//gen_phases(rnd_gen, the_cnf.cf_phdat);
		gen_ccls_cnf(rnd_gen, the_cnf, max_ccl_sz, max_num_ccls_cnf, max_num_vars_cnf);

		the_cnf.cf_kind = fk_diff;
		ch_string cnn_base_name = the_cnf.get_cnf_path();
		
		if(! GSKE.ref_exists(cnn_base_name)){
			os << "num_test=" << aa << bj_eol;
			the_cnf.save_cnf(GSKE, cnn_base_name);

			row<neuron*> all_found;
			ch_string vpth = the_cnf.first_vnt_i_super_of(GSKE, all_found);
			MARK_USED(vpth);
			BRAIN_CK(vpth != SKG_INVALID_PTH);

		} else {
			os << bj_eol;
			os << bj_eol;
			os << "!!! SKIPED num_test=" << aa;
		}

		the_cnf.release_and_init(GSKE, true);

		update_rnd_elap_in_dir(rnd_gen2, skl_nt_pth);
	}

	os << "3. LOADING TEST ..."  << bj_eol;

	bool fnd1 = GSKE.find_skl_path(GSKE.as_full_path(rr_pth + "/test_ref1/"));
	bool fnd2 = GSKE.find_skl_path(GSKE.as_full_path(rr_pth + "/test_ref2/"));
	bool fnd3 = GSKE.find_skl_path(GSKE.as_full_path(rr_pth + "/test_ref3/"));

	MARK_USED(fnd1);
	MARK_USED(fnd2);
	MARK_USED(fnd3);

	BRAIN_CK(fnd1);
	BRAIN_CK(fnd2);
	BRAIN_CK(fnd3);

	load_all_in_dir(skl_nt_pth);

	the_cnf.release_and_init(GSKE, true);
	GSKE.clear_all();

	os << "4. FINISHING ..."  << bj_eol;
	os.flush();
}