void cfg_sci_prop_sets::set_data_raw(stream_reader * p_stream, t_size p_sizehint, abort_callback & p_abort) { t_str_to_str_map data_map; pfc::string8_fast key, val; t_size count; try { p_stream->read_lendian_t(count, p_abort); for (t_size i = 0; i < count; ++i) { p_stream->read_string(key, p_abort); p_stream->read_string(val, p_abort); data_map[key] = val; } } catch (std::exception &) { // Load default init_data(prop_sets_init_table); return; } merge_data(data_map); }
void topdown_merge_sort(std::vector<T> &data, int low, int high){ if(high <= low) return; int mid_ = low +(high-low)/2; //Why? topdown_merge_sort(data, low, mid_) ; topdown_merge_sort(data, mid_+1 , high); merge_data(data, low, mid_, high); }
void bottomup_merge(std::vector<T> &data, int lo, int high){ sort_clock trackTime; trackTime._start = std::chrono::system_clock::now(); int N = high; for (int sz = 1; sz < N; sz+=sz){ for(int lo =0; lo < N-sz; lo+=sz+sz){ merge_data(data, lo, lo+sz-1, minValue(lo+sz+sz-1, N-1)); } } trackTime._end = std::chrono::system_clock::now(); trackTime._elapsed_seconds = trackTime._end-trackTime._start; std::cout << "Finished Bottom Merge Sort in:" << trackTime._elapsed_seconds.count() << std:: endl; }
void cfg_sci_prop_sets::import_from_file(const char * filename) { typedef pfc::chain_list_v2_t<pfc::string8_fast> t_string_chain_list; t_string_chain_list lines; pfc::string8_fast text, key; t_str_to_str_map data_map; // First read whole content in a string helpers::read_file(filename, text); // Then split splitStringByLines(lines, text); // Read data for (t_string_chain_list::iterator iter = lines.first(); iter != lines.last(); ++iter) { if (iter->get_length() > 0) { int len = iter->get_length(); const char * ptr = iter->get_ptr(); // Comment or length two small, skip if (*ptr == '#' || len <= 3) continue; const char * delim = strchr(ptr, '='); if ((!delim) || (delim - ptr + 1 > len)) continue; if (delim > ptr) { key.set_string(ptr, delim - ptr); data_map[key].set_string(delim + 1); } } } // Merge merge_data(data_map); }
int main(int argc, char* argv[]) { // Simulation configuration int num_of_clients = 50; // Indexing int i,j,n,l; // Temporary Logging generalLog_filepath = TEST3_GENERAL_LOG; starting_k = 5; max_k = 20; ignore_count = 3; if( getenv("SUDO_UID") ) { user_uid = atoi(getenv("SUDO_UID")); } else { printf("You need sudo to run the test\n"); exit(0); } #ifdef HARD_UPPER_LIMIT if( argc > 1 ) { upper_limit = atoi(argv[1]); } #endif if( argc > 2 ) { num_of_clients = atoi(argv[2]); } seteuid(user_uid); setfsuid(user_uid); setup_logs(); // Statistical variables running_stats_t rs; //set_default_running_stats( &rs ); create_service("group",group_count); for( l=1; l <= sizeof(group_size_array)/sizeof(int); l++) { group_size = group_size_array[l-1]; num_of_clients = group_size; set_default_running_stats( &rs ); printf("===================Pre-test Runs=====================\n"); for( j = 0; j < ignore_count; j++ ) { // ignore first few iterations timeLog_file = fopen( timeLog_filepath, "w" ); fclose(timeLog_file); test3( timeLog_filepath, num_of_clients, 1); } printf("===================Starting KSM1=====================\n"); resultsLogRAW_file = fopen( resultsLogRAW_filepath, "a" ); fprintf(resultsLogRAW_file, "===================Starting KSM1=====================\n"); if(resultsLogRAW_file) fclose(resultsLogRAW_file); run_test3(&rs, num_of_clients, 1); log_data( test3_dat_ksm1_filepath, group_size, &rs ); set_default_running_stats( &rs ); printf("===================Pre-test Runs=====================\n"); for( j = 0; j < ignore_count; j++ ) { // ignore first few iterations timeLog_file = fopen( timeLog_filepath, "w" ); fclose(timeLog_file); test3( timeLog_filepath, num_of_clients, 2); } printf("===================Starting KSM2=====================\n"); resultsLogRAW_file = fopen( resultsLogRAW_filepath, "a" ); fprintf(resultsLogRAW_file, "===================Starting KSM2=====================\n"); if(resultsLogRAW_file) fclose(resultsLogRAW_file); run_test3(&rs, num_of_clients, 2); log_data( test3_dat_ksm2_filepath, group_size, &rs ); } delete_service("group",group_count); merge_data(test3_dat_filepath, test3_dat_ksm1_filepath, test3_dat_ksm2_filepath); remove(test3_dat_ksm1_filepath); remove(test3_dat_ksm2_filepath); remove(timeLog_filepath); return 0; }