InfInt karatsubaMult(string x, string y)
{
	InfInt *result = new InfInt(0);
	int m = makeEqualLength(x, y);

	if(m == 0)
		return *result;

	size_t sz = 0;
	if( x.length() == 1 || y.length() == 1 ) {
		result = new InfInt(stoull(x, &sz, 0) * stoull(y, &sz, 0));
		return *result;
	}

	// m2 + m2Rest = m
	int m2 = m/2;
	int m2Rest = m - m2;

	string xl = x.substr(0, m2);
	string xr = x.substr(m2, m2Rest);
	string yl = y.substr(0, m2);
	string yr = y.substr(m2, m2Rest);

	InfInt z0 = karatsubaMult(xr, yr);
	InfInt z1 = karatsubaMult(add(xl, xr), add(yl, yr));
	InfInt z2 = karatsubaMult(xl, yl);
	*result = (z2 * basePower(*INFINTBASE10, 2*m2) + ((z1-z2-z0) * basePower(*INFINTBASE10, m2)) + z0);

	return *result;
}
Exemple #2
0
void Seeker::seekConvertions()
{
	unsigned long long int st, fi, i;
	std::string::size_type sz = 0;

	st = stoull(_initNum, &sz, 0);
	st = st == 0 ? 0 : st;
	fi = stoull(_finishNum, &sz, 0);
	fi = fi == 0 ? ipow(_base, _v) : fi;
	unsigned long long int TOTAL = fi - st;
	cout << "Begin looking in diapasone: " << st << " to " << fi << endl;
	double duration, start = clock();

	for (i = st; i < fi; i++)
	{
		duration = (clock() - start) / (double)CLOCKS_PER_SEC;
		convertNum2Seq(_sequence, i, _base, _v);
		if (duration > SHOW_TIME)
		{
			cout << "Done: " << (i-st)*100./TOTAL << "%" << endl;
			start = clock();
			writeTEMPNum(i);
			printSeq(_sequence, _v, "tmp");
		}
		if (isSuiteToBrookRaiserChovla(_sequence, _v))
		{
			if (isTP(_sequence, _v))
			{
				writeSeq2File();
				printSeq(_sequence, _v, "GOOD!");
			}
		}
	}
}
int main(){

	uint count = 0;
	uint limit = 10000;

	for(ullint i = 1; i < limit; i++){
		uint iterations = 0;
		string s1, s2;
		ullint ly;
		do{
			if(iterations){
				s1 = intToString(ly);
			}else{
				s1 = intToString(i);
			}
			s2 = s1;
			reverse(s2.begin(), s2.end());
			ly = stoull(s1) + stoull(s2);
			iterations++;
		}while(iterations < 30 && !isPalindrome(ly));

		if(iterations == 30){
			count++;
		}

	}

	cout << count << endl;

	return 0;

}
void Hss::get_autn_info(uint64_t imsi, uint64_t &key, uint64_t &rand_num) {
	MYSQL_RES *query_res;
	MYSQL_ROW query_res_row;
	int i;
	int num_fields;
	string query;

	query_res = NULL;
	query = "select key_id, rand_num from autn_info where imsi = " + to_string(imsi);
	cout << "hss_getautninfo:" << query << endl;
	g_sync.mlock(mysql_client_mux);
	mysql_client.handle_query(query, &query_res);
	g_sync.munlock(mysql_client_mux);
	num_fields = mysql_num_fields(query_res);
	cout << "hss_getautninfo:" << " fetched" << endl;
	query_res_row = mysql_fetch_row(query_res);
	if (query_res_row == 0) {
		g_utils.handle_type1_error(-1, "mysql_fetch_row error: hss_getautninfo");
	}
	for (i = 0; i < num_fields; i++) {
		string query_res_field;

		query_res_field = query_res_row[i];
		if (i == 0) {
			key = stoull(query_res_field);
		}
		else {
			rand_num = stoull(query_res_field);
		}
	}
	mysql_free_result(query_res);
}
Exemple #5
0
int CHgzComboBox::GetWindowHexArray(unsigned char * pHex)
{
	CString str;
	GetWindowText(str);

	CStringArray arr;
	hgzExtractSubStrings(arr, str, _T(" +"));
	//unsigned int *pi = new unsigned int[arr.GetSize()];
	int i;
	int n = 0;
	for (i = 0; i < arr.GetSize(); i++)
	{
		long long x;
		int j = 0;
		x = stoull((tstring)arr[i].GetString(), 0, 16);
		if      (x <= 0xFF)  j = 1;
		else if (x <= 0xFFFF)  j = 2;
		else if (x <= 0xFFFFFF)  j = 3;
		else if (x <= 0xFFFFFFFF)  j = 4;
		else if (x <= 0xFFFFFFFFFF)  j = 5;
		else if (x <= 0xFFFFFFFFFFFF)  j = 6;
		else if (x <= 0xFFFFFFFFFFFFFF)  j = 7;
		else if (x <= 0xFFffFFffFFffFFff)  j = 8;
		hgzRevertByteOrder((unsigned char *)&x, j);
		for (int m = 0; m < j; m++) {
			pHex[n+m] = ((unsigned char *)&x)[m];
		}
		n += j;
	}

	//delete [] pi;
	return n;
}
Exemple #6
0
    std::shared_ptr<Response> request_read() {
      std::shared_ptr<Response> response(new Response());

      try {
        size_t bytes_transferred = boost::asio::read_until(*socket, response->content_buffer, "\r\n\r\n");

        size_t num_additional_bytes = response->content_buffer.size() - bytes_transferred;

        parse_response_header(response, response->content);

        auto header_it = response->header.find("Content-Length");
        if (header_it != response->header.end()) {
          auto content_length = stoull(header_it->second);
          if (content_length>num_additional_bytes) {
            boost::asio::read(*socket, response->content_buffer,
              boost::asio::transfer_exactly(content_length - num_additional_bytes));
          }
        }
        else if ((header_it = response->header.find("Transfer-Encoding")) != response->header.end() && header_it->second == "chunked") {
          boost::asio::streambuf streambuf;
          std::ostream content(&streambuf);

          std::streamsize length;
          std::string buffer;
          do {
            size_t bytes_transferred = boost::asio::read_until(*socket, response->content_buffer, "\r\n");
            std::string line;
            getline(response->content, line);
            bytes_transferred -= line.size() + 1;
            line.pop_back();
            length = stol(line, 0, 16);

            auto num_additional_bytes = static_cast<std::streamsize>(response->content_buffer.size() - bytes_transferred);

            if ((2 + length)>num_additional_bytes) {
              boost::asio::read(*socket, response->content_buffer,
                boost::asio::transfer_exactly(2 + length - num_additional_bytes));
            }

            buffer.resize(static_cast<size_t>(length));
            response->content.read(&buffer[0], length);
            content.write(&buffer[0], length);

            //Remove "\r\n"
            response->content.get();
            response->content.get();
          } while (length>0);

          std::ostream response_content_output_stream(&response->content_buffer);
          response_content_output_stream << content.rdbuf();
        }
      }
      catch (const std::exception& e) {
        socket_error = true;
        throw std::invalid_argument(e.what());
      }

      return response;
    }
Exemple #7
0
void PosField::parse(const char* start, const char* end) throw (VCFException) {
	text.assign(start, end);
	if (!regex_match(text, pos_regex)) {
		value = numeric_limits<long long unsigned int>::min();
		throw VCFException(__FILE__, __FUNCTION__, __LINE__, "Error while parsing POS field.");
	}
	value = stoull(text, nullptr, 10);
}
Exemple #8
0
void HSS::set_key_id() {

	query = "select key_id from ue_data where imsi = " + to_string(ue_data.imsi) + " and msisdn = " + to_string(ue_data.msisdn);
	db_client.perform_query(query.c_str());
	query_res = mysql_fetch_row(db_client.result);
	handle_query_error();
	res_row = query_res[0];	
	ue_data.key_id = stoull(res_row);
}
Exemple #9
0
AgentService::AgentService( Context* cct ){
    this->cct = cct;
    flush_op_count = new Count();
    int tp_size = stoi(this->cct->config->configValues["agent_threads_num"]);
    threadpool = new ThreadPool(tp_size);
    process_tp = new ThreadPool(2);
    cache_total_size = stoull(this->cct->config->configValues["cache_total_size"]);
    cache_dirty_ratio_min = stof(this->cct->config->configValues["cache_dirty_ratio_min"]);
    cache_dirty_ratio_max = stof(this->cct->config->configValues["cache_dirty_ratio_max"]);
    object_size = stoull(this->cct->config->configValues["object_size"]);
    cache_flush_interval = stoi(this->cct->config->configValues["cache_flush_interval"]);
    cache_evict_interval = stoi(this->cct->config->configValues["cache_evict_interval"]);
    cache_flush_queue_depth = stoi(this->cct->config->configValues["cache_flush_queue_depth"]);
    cache_ratio_max = stof(this->cct->config->configValues["cache_ratio_max"]);
    cache_ratio_health = stof(this->cct->config->configValues["cache_ratio_health"]);
    process_tp->schedule(boost::bind(&AgentService::_process_flush, this));
    process_tp->schedule(boost::bind(&AgentService::_process_evict, this));
    log_print("AgentService constructed\n");
}
Exemple #10
0
 void Response::get_header( const string& name, unsigned long long& value, const unsigned long long default_value ) const
 {
     try
     {
         value = stoull( get_header( name ) );
     }
     catch ( const invalid_argument& )
     {
         value = default_value;
     }
 }
Exemple #11
0
void HSS::set_autn_tokens() {
	int i;

	curr_time = time(0);
	local_time = localtime(&curr_time);
	curr_sec = local_time->tm_sec;
	query = "select * from ue_autn where autn like '%" + to_string(curr_sec) + "'";
	db_client.perform_query(query.c_str());
	num_fields = mysql_num_fields(db_client.result);
	query_res = mysql_fetch_row(db_client.result);
	handle_query_error();
	for (i = 0; i < num_fields; i++) {
		res_row = query_res[i];
		if (i == 0) {
			ue_data.autn_num = stoull(res_row);
		}
		else {
			ue_data.rand_num = stoull(res_row);
		}
	}
}
sai_status_t internal_redis_get_stats_process(
        _In_ sai_object_type_t object_type,
        _In_ uint32_t count,
        _Out_ uint64_t *counter_list,
        _In_ swss::KeyOpFieldsValuesTuple &kco)
{
    SWSS_LOG_ENTER();

    // key:         sai_status
    // field:       stat_id
    // value:       stat_value

    const auto &key = kfvKey(kco);
    const auto &values = kfvFieldsValues(kco);

    auto str_sai_status = key;

    sai_status_t status;

    sai_deserialize_status(str_sai_status, status);

    if (status == SAI_STATUS_SUCCESS)
    {
        uint32_t i = 0;
        for (const auto &v : values)
        {
            if (i >= count)
            {
                SWSS_LOG_ERROR("Received more values than expected");
                status = SAI_STATUS_FAILURE;
                break;
            }

            uint64_t value = 0;

            value = stoull(fvValue(v));
            counter_list[i] = value;
            i++;
        }
    }

    return status;
}
Exemple #13
0
    int getLuckyRemainder(string X) {
        uint64_t totalSetCnt = pow(2, X.size());
        uint64_t result = 0;
        for(int i = 0; i < (int)totalSetCnt; ++i) {
            string powsetBits = bitset<50>(i).to_string();
            string generated;
            int startJ = 50 - X.size();
            for(int j = 50 - startJ; j < 50; ++j ) {
                if(powsetBits[j] == '1') {
                    generated += X[j - startJ];
                }
            }
            if(!generated.empty()) {
                result += (stoull(generated));
            }
        }
        return (int)(result % 9);

    }
Exemple #14
0
int main(int argc, char *argv[]){
    int status = 0;
    struct sigaction act;
    pthread_t conn_thread, d_thread, p_thread, n_thread;
    enum conn_type d = CONN_DRIVER, p = CONN_PREV, n = CONN_NEXT;

    bool create = false;
    char *path = NULL, *next = NULL, *prev = NULL;
    unsigned long long int size = -1;

    int sig;
    act.sa_handler = handleExit;
    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask, SIGINT);
    sigaddset(&act.sa_mask, SIGTERM);
    sigaddset(&act.sa_mask, SIGQUIT);
    sigaddset(&act.sa_mask, SIGABRT);
    act.sa_flags = 0;

    sigaction(SIGINT, &act, NULL);
    sigaction(SIGTERM, &act, NULL);
    sigaction(SIGQUIT, &act, NULL);
    sigaction(SIGABRT, &act, NULL);

    if(argc < 3){
        printf("Usage: command [flags]\n");
        printf("-c PATH\tcreate lsvd_disk with pathname PATH\n");
        printf("-o PATH\topen existing lsvd_disk with pathname PATH\n");
        printf("-p NAME\tconnect replica to upstream host with NAME\n");
        printf("-n NAME\tconnect replica to downstream host with NAME\n");
        printf("-s SIZE\twhen -c used, initialize lsvd_disk with size SIZE Megabytes\n");
        exit(1);
    }    
    
    rmgr = new ReplicaManager();
    cmgr = new ConnectionManager();

    for (int i = 1; i < argc; i++){
        if (argv[i][0] != '-'){
            printf("Invalid flag\n");
        }
        switch(argv[i][1]){
            case 'c':
                if (i+1 < argc && path == NULL){
                    create = true;
                    printf("Path: %s\n", argv[i+1]);
                    path = argv[i+1];
                    i++;
                }
                break;
            case 'o':
                if (i+1 < argc && path == NULL){
                    create = false;
                    printf("Path: %s\n", argv[i+1]);
                    path = argv[i+1];
                    i++;
                }
                break;
            case 'p':
                if (i+1 < argc && prev == NULL){
                    printf("Previous name : %s\n", argv[i+1]);
                    prev = argv[i+1];
                    cmgr->update(CONN_PREV, prev);
                    cmgr->connect(CONN_PREV);
                    i++;
                }
                break;
            case 'n':
                if (i+1 < argc && next == NULL){
                    printf("Next name : %s\n");
                    next = argv[i+1];
                    cmgr->update(CONN_NEXT, next);
                    i++;
                }
                break;
            case 's':
                if (i+1 < argc && size == -1){
                    std::string size_str(argv[i+1]);
                    try {
                        size = stoull(size_str) * MB;
                    } catch(std::exception &e){
                        printf("Invalid size, using default\n");
                        size = DEFAULT_SIZE;
                    }
                    i++;
                }
                break;
            default:
                printf("Invalid option \n");
                exit(1);
        }
    }

    if (size == -1){
        size = DEFAULT_SIZE;
    }

    if (path != NULL){
        if (create){
            printf("Creating volume of size %lld Bytes\n", size);
            status = rmgr->create(path, size/LSVD_SECTORSIZE);
        } else {
            status = rmgr->open(path);
        }
    } else {
        printf("Invalid input parameters\n");
        exit(1);
    }

    if (status < 0){
        perror("LSVD open error\n");
        exit(1);
    }

    // Already established connection in 'p'
    if (prev != NULL && sendSyncRequest() < 0){
        perror("ERROR sync problem!");
        exit(1);
    }
   
    pthread_create(&d_thread, NULL, handleConnection, &d);
    pthread_create(&p_thread, NULL, handleConnection, &p);
    pthread_create(&n_thread, NULL, handleConnection, &n);

    pthread_join(d_thread, NULL);
    pthread_join(p_thread, NULL);
    pthread_join(n_thread, NULL);

    printf("Deleting rmgr, cmgr\n");

    delete rmgr;    // Wait for all threads to finish then delete rmgr
    delete cmgr;

    printf("Exiting main\n");
    return 0;
}
Exemple #15
0
	unsigned long long operator()(const std::string& s) {
		return stoull(s);
	}
Exemple #16
0
void TrafficSimulation::import_vehicles(std::string vehicles_file)
{
	// load input file
	std::ifstream infile;
	infile.exceptions(std::ifstream::badbit);
	try {
		infile.open(vehicles_file);

		// read and match lines
		std::string line;

		for (uint_fast32_t line_num = 1; std::getline(infile, line);
			 ++line_num) {
			// split by fields
			std::vector<std::string> fields = nonstd::split(line, ':');

			// 4 fields are required (time, name, from, to)
			if (fields.size() < 4) {
				std::cerr << "E: Line " << line_num << " of input file \""
						  << vehicles_file
						  << "\" is not valid. See documentation "
							 "for correct syntax. Skipping..." << std::endl;
				continue;
			}

#ifndef NDEBUG
			std::cout << "Fields:" << std::endl;
			for (auto &f : fields) {
				std::cout << f << std::endl;
			}
			std::cout << "Matched vehicle on line " << line_num << std::endl
					  << "name: " << fields[1] << std::endl
					  << "from: " << fields[2] << std::endl
					  << "to: " << fields[3] << std::endl
					  << "starttime: " << fields[0] << std::endl;
#endif

			// create vehicle; parse starttime, name, from and to
			try {
				Vehicle veh(*this, fields[2], fields[3], stoull(fields[0]),
							fields[1]);

				// parse optional properties
				for (int i = 4; i < fields.size(); ++i) {
					// split property field by =
					std::vector<std::string> property =
						nonstd::split(fields[i], '=');

					// assign property
					switch (nonstd::hash(property[0].c_str())) {
					case nonstd::hash("traffic_increase_caused"):
						veh.traffic_increase_caused = stof(property[1]);
						break;
					case nonstd::hash("max_speed"):
						veh.max_speed = stoul(property[1]);
						break;
					}
				}

				// add vehicle to simulation
				vehicles.push_back(veh);

				std::cout << "I: Vehicle " << veh.name
						  << " loaded for simulation" << std::endl;
			}
			// vehicle construction errors
			catch (const std::runtime_error &e) {
				std::cerr << "E: " << vehicles_file << ":" << line_num
						  << " Vehicle on line " << line_num
						  << "could'n be loaded for simulation. " << e.what()
						  << std::endl;
			}
		}
	}
	// input file errors
	catch (const std::ifstream::failure &e) {
		std::cerr << "E: Couldn't read file '" << vehicles_file << " "
				  << e.what() << std::endl;
	}
}
WSObjNumeric_JSON::operator unsigned long long int() const {
    string s(token->ptr,(unsigned long) token->len);
    return stoull(s);
}
Exemple #18
0
uint32_t Telecom::get_mmei(uint16_t mmegi, uint8_t mmec) {
	return stoull(to_string(mmegi) + to_string(mmec));
}
Exemple #19
0
uint16_t Telecom::get_plmn_id(uint16_t mcc, uint16_t mnc) {
	return stoull(to_string(mcc) + to_string(mnc));
}
Exemple #20
0
uint64_t Telecom::get_guti(uint64_t gummei, uint64_t m_tmsi) {
	return stoull(to_string(gummei) + to_string(m_tmsi));
}
Exemple #21
0
uint64_t Telecom::get_imsi(uint16_t plmn_id, uint64_t msisdn) {
	return stoull(to_string(plmn_id) + to_string(msisdn));
}
Exemple #22
0
uint64_t Telecom::get_gummei(uint16_t plmn_id, uint32_t mmei) {
	return stoull(to_string(plmn_id) + to_string(mmei));
}
        std::shared_ptr<Response> request(const std::string& request_type, const std::string& path, std::ostream& content, 
                const std::map<std::string, std::string>& header=std::map<std::string, std::string>()) {
            std::string corrected_path=path;
            if(corrected_path=="")
                corrected_path="/";
            
            content.seekp(0, std::ios::end);
            size_t content_length=content.tellp();
            content.seekp(0, std::ios::beg);
            
            boost::asio::streambuf write_buffer;
            std::ostream write_stream(&write_buffer);
            write_stream << request_type << " " << corrected_path << " HTTP/1.1\r\n";
            write_stream << "Host: " << host << "\r\n";
            for(auto& h: header) {
                write_stream << h.first << ": " << h.second << "\r\n";
            }
            if(content_length>0)
                write_stream << "Content-Length: " << std::to_string(content_length) << "\r\n";
            write_stream << "\r\n";
            if(content_length>0)
                write_stream << content.rdbuf();
            
            std::shared_ptr<Response> response(new Response());
            
            try {
                connect();
                              
                boost::asio::write(*socket, write_buffer);
                
                size_t bytes_transferred = boost::asio::read_until(*socket, response->content_buffer, "\r\n\r\n");
                
                size_t num_additional_bytes=response->content_buffer.size()-bytes_transferred;
                
                parse_response_header(response, response->content);
                                
                if(response->header.count("Content-Length")>0) {
                    boost::asio::read(*socket, response->content_buffer, 
                            boost::asio::transfer_exactly(stoull(response->header["Content-Length"])-num_additional_bytes));
                }
                else if(response->header.count("Transfer-Encoding")>0 && response->header["Transfer-Encoding"]=="chunked") {
                    boost::asio::streambuf streambuf;
                    std::ostream content(&streambuf);
                    
                    size_t length;
                    std::string buffer;
                    do {
                        size_t bytes_transferred = boost::asio::read_until(*socket, response->content_buffer, "\r\n");
                        std::string line;
                        getline(response->content, line);
                        bytes_transferred-=line.size()+1;
                        line.pop_back();
                        length=stoull(line, 0, 16);

                        size_t num_additional_bytes=response->content_buffer.size()-bytes_transferred;
                    
                        if((2+length)>num_additional_bytes) {
                            boost::asio::read(*socket, response->content_buffer, 
                                boost::asio::transfer_exactly(2+length-num_additional_bytes));
                        }
                                                
                        buffer.resize(length);
                        response->content.read(&buffer[0], length);
                        content.write(&buffer[0], length);

                        //Remove "\r\n"
                        response->content.get();
                        response->content.get();
                    } while(length>0);
                    
                    std::ostream response_content_output_stream(&response->content_buffer);
                    response_content_output_stream << content.rdbuf();
                }
            }
            catch(const std::exception& e) {
                socket_error=true;
                throw std::invalid_argument(e.what());
            }
            
            return response;
        }
uint64_t _parse_decimal_integer_string(std::string s) {
  return stoull(s);
}
Exemple #25
0
 int superpalindromesInRange(string L, string R) {
     vector<ULL> v{
         1, 4, 9, 121, 484, 10201, 12321, 14641, 40804, 44944, 1002001, 1234321, 4008004, 100020001, 102030201, 104060401, 121242121, 123454321, 125686521, 400080004 ,404090404, 10000200001l, 10221412201l, 12102420121l, 12345654321l, 40000800004l , 1000002000001l, 1002003002001l, 1004006004001l, 1020304030201l, 1022325232201l, 1024348434201l, 1210024200121l, 1212225222121l, 1214428244121l, 1232346432321l, 1234567654321l, 4000008000004l, 4004009004004l, 100000020000001l, 100220141022001l, 102012040210201l, 102234363432201l, 121000242000121l, 121242363242121l, 123212464212321l, 123456787654321l, 400000080000004l, 10000000200000001l, 10002000300020001l, 10004000600040001l, 10020210401202001l, 10022212521222001l, 10024214841242001l, 10201020402010201l, 10203040504030201l, 10205060806050201l, 10221432623412201l, 10223454745432201l, 12100002420000121l, 12102202520220121l, 12104402820440121l, 12122232623222121l, 12124434743442121l, 12321024642012321l, 12323244744232321l, 12343456865434321l, 12345678987654321l, 40000000800000004l, 40004000900040004l
     };
     return upper_bound(v.begin(), v.end(), stoull(R)) - lower_bound(v.begin(), v.end(), stoull(L));
 }