#include "socketio.hpp"
#include "BigInt64.hpp"
#include <xoshiro.hpp>
#include <iostream>
#include <chrono>
unsigned long long nanoTime(){
	using namespace std;
	using namespace std::chrono;
	return duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count();
}
template<typename T>
std::ostream& operator<<(std::ostream& out, std::vector<T> o){
	out << "[";
	for(unsigned int i = 0;i < o.size();i++){
		if(o[i] == '\r')continue;
		out << o[i];
		if(i < o.size() - 1)
			out << ", ";
	}
	return out << "]";
}
template<>
std::ostream& operator<< <char>(std::ostream& out, std::vector<char> o){
	for(unsigned int i = 0;i < o.size();i++){
		out << o[i];
	}
	return out;
}
int main(){
	xoshiro_256 gen(42);
	BigInt a(gen, 2);
	a[0] >>= 30;
	std::cout << a.toString() << std::endl;
	a.bitshiftLeft(1);
	std::cout << a.toString() << std::endl;
	for(unsigned int i = 2;true;i *= 2){
		BigInt a(gen, i);
		BigInt b(gen, i);
		auto t1 = nanoTime();
		a = a.mult(b);
		auto t2 = nanoTime();
		std::cout << i << ", " << ((double)((t2 - t1) / 1000) / 1000.0d) << " ms \t\t" << (std::hash<BigInt>()(a) % 10) << std::endl;
	}
}
int mian(){
	cppsocket sock("192.168.178.79", 80);
	//cppsocket sock("127.0.0.1", 80);
	std::vector<char> toSend(10);
	for(unsigned int i = 0;i < toSend.size();i++){
		toSend[i] = (char)(i * i) % 10 + 'a';
	}
	//std::cout << errno << std::endl;
	try{
		for(int i = 0;i < 100;i++){
			sock.write(toSend);
			std::cout << "Rec" << std::endl;
			std::cout << sock.receive() << std::endl;
			//std::this_thread::sleep_for(std::chrono::milliseconds(1));
		}
	}
	catch(std::exception& e){
		std::cout << e.what() << std::endl;
	}
	//std::cout << "Sent "  << std::to_string(toSend.size()) << ", Receiving..." << std::endl;
	//sock.write(std::vector<char>(1,1));
	//std::vector<char> vec = sock.receive();
	//std::cout << (vec == toSend);
	//std::cout << vec << std::endl;
	//vec = sock.receive();
	//std::cout << vec << std::endl;
	return 0;
}