// File: /workspace/github_cpp_makefile_star2_O3/aleperno[P]Datos/HashingPerceptron.cpp
// Function: HashingPerceptron::HashingPerceptron(char*, int, float, unsigned int, float)
HashingPerceptron::HashingPerceptron(char* path, int token_size, float learning_rate, unsigned int hash_size, float init) {

	ifstream myfile;
	myfile.open(path);

	Parser* parser = new Parser();

	//NO USO MAPPER
	//this->mapper = NULL;
	//El largo de la frase debe estar aca
	this->phrase_lenght = token_size;
	//Largo del hash
	this->hash_size = hash_size;
	clock_t inicio = clock();
	if(myfile.is_open())
	{
		printf("Began to represent reviews as vectors using hashing trick\n");

		string linea;
		while( getline(myfile,linea) )
		{
			vector<string> tokenized_columns = parser->tokenizeColumns(linea);
			string movie_id = tokenized_columns[0];
			//this->strToInt(tokenized_columns[1]);
			int sentiment = (tokenized_columns[1] == "0") ? 0:1;
			string review = tokenized_columns[2];

			vector<string> tokenized_words = parser->tokenizeReviews(review);
			//this->show_vec_str(tokenized_words);
			pair<int,vector<unsigned int>> par_aux;
			vector<unsigned int> vec_pos = this->getVector(tokenized_words);
			par_aux = make_pair(sentiment,vec_pos);
			this->test_vec.push_back(par_aux);
			//movie_id -> sentiment, [words]
			this->aux_map_2[movie_id] = par_aux;

		}
	}
	clock_t final = clock();
	double secs = double(final - inicio) / CLOCKS_PER_SEC;
	float min = floor(secs/60);
	float sec = secs - min*60;
	printf("Took %0.0f:%.3f\n",min,sec);
	delete parser;
	this->learning_rate = learning_rate;
	this->threshold = 0.5;

	this->weights = vector<float>(this->hash_size,init);
	cout << "Weights were initialized with " << this->weights[0] << endl;
	this->Initialize();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x388, %rsp            # imm = 0x388
movl %ecx, %ebx
movss %xmm0, -0x64(%rbp)
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %r13
movss %xmm1, -0x68(%rbp)
leaq 0x8(%rdi), %rax
xorl %ecx, %ecx
movl %ecx, 0x8(%rdi)
movq %rcx, 0x10(%rdi)
movq %rax, 0x18(%rdi)
movq %rax, 0x20(%rdi)
movq %rcx, 0x28(%rdi)
leaq 0x38(%rdi), %rax
movq %rax, -0x70(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%rdi)
movq %rcx, 0x48(%rdi)
leaq 0x58(%rdi), %rax
movq %rax, -0x78(%rbp)
leaq 0x60(%rdi), %rax
movl %ecx, 0x60(%rdi)
movq %rcx, 0x68(%rdi)
movq %rax, 0x70(%rdi)
movq %rax, 0x78(%rdi)
leaq 0x88(%rdi), %rax
movq %rax, -0x80(%rbp)
movups %xmm0, 0x80(%rdi)
movups %xmm0, 0x90(%rdi)
leaq -0x3b0(%rbp), %rdi
callq 0x3280
leaq -0x3b0(%rbp), %rdi
movq %r15, %rsi
movl $0x8, %edx
callq 0x3170
movl $0x60, %edi
callq 0x3230
movq %rax, %r12
movq %rax, %rdi
callq 0x3e80
leaq -0x3b0(%rbp), %r15
movl %r14d, 0x30(%r13)
movl %ebx, 0x34(%r13)
callq 0x3180
movq %rax, %rbx
leaq -0x338(%rbp), %rdi
callq 0x30c0
testb %al, %al
je 0x70b6
movq %r12, -0x38(%rbp)
movq %rbx, -0xc8(%rbp)
movq %r13, -0x30(%rbp)
leaq 0x352c(%rip), %rdi      # 0xa2d5
callq 0x3350
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x110(%rbp), %r14
leaq -0x190(%rbp), %r12
movq -0x3b0(%rbp), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %edx
movq %r15, %rdi
leaq -0x60(%rbp), %rsi
callq 0x3410
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
leaq -0x140(%rbp), %rbx
jne 0x7095
leaq -0x130(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x3cbe
leaq -0xe0(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %rbx, %rdx
callq 0x4032
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
je 0x6e5b
callq 0x3210
movq -0xe0(%rbp), %rax
movq %r14, %rbx
movq %r14, -0x120(%rbp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x120(%rbp), %rdi
callq 0x3cbe
movq -0xe0(%rbp), %rdi
addq $0x20, %rdi
leaq 0x332c(%rip), %rsi      # 0xa1c0
callq 0x30f0
xorl %r14d, %r14d
testl %eax, %eax
setne %r15b
movq -0xe0(%rbp), %rax
leaq -0xb0(%rbp), %rcx
movq %rcx, -0xc0(%rbp)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x3cbe
leaq -0xf0(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
addq %rsi, %rdx
leaq -0x100(%rbp), %r13
movq %r13, %rdi
callq 0x3cbe
leaq -0x178(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r13, %rdx
callq 0x41aa
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
cmpq %rax, %rdi
je 0x6f27
callq 0x3210
movl $0x0, -0xa0(%rbp)
leaq -0x98(%rbp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq -0x1a8(%rbp), %r13
movq %r13, %rdi
leaq -0x178(%rbp), %rsi
callq 0x8014
movq %r12, %rdi
movq -0x30(%rbp), %rsi
movq %r13, %rdx
callq 0x7366
movb %r15b, %r14b
movq %r13, %rdi
callq 0x4b12
movl %r14d, -0x160(%rbp)
leaq -0x158(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x826c
movl -0x160(%rbp), %eax
movl %eax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
movq -0x158(%rbp), %rax
movq %rax, -0x98(%rbp)
movups -0x150(%rbp), %xmm0
movups %xmm0, -0x90(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq $0x0, 0x10(%r14)
testq %rdi, %rdi
movq %rbx, %r14
leaq -0x3b0(%rbp), %r15
je 0x6ff2
callq 0x3210
movq -0x158(%rbp), %rdi
testq %rdi, %rdi
je 0x6ff2
callq 0x3210
movq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x80a2
movq -0x78(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x80ea
movl -0xa0(%rbp), %ecx
movl %ecx, (%rax)
addq $0x8, %rax
movq %rax, %rdi
leaq -0x98(%rbp), %rsi
callq 0x8b8a
movq -0x190(%rbp), %rdi
testq %rdi, %rdi
je 0x703e
callq 0x3210
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x704f
callq 0x3210
leaq -0x178(%rbp), %rdi
callq 0x4b12
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x7073
callq 0x3210
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x7084
callq 0x3210
leaq -0xe0(%rbp), %rdi
callq 0x4b12
jmp 0x6dcf
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x70a7
callq 0x3210
movq -0x30(%rbp), %r13
movq -0xc8(%rbp), %rbx
movq -0x38(%rbp), %r12
callq 0x3180
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x30b2(%rip), %xmm0     # 0xa180
movsd %xmm0, -0x38(%rbp)
divsd 0x30ad(%rip), %xmm0     # 0xa188
callq 0x33b0
cvtsd2ss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
mulss 0x30ad(%rip), %xmm1     # 0xa1a0
cvtss2sd %xmm1, %xmm1
addsd -0x38(%rbp), %xmm1
cvtsd2ss %xmm1, %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x30b7(%rip), %rdi      # 0xa1c2
movb $0x2, %al
callq 0x3060
movq (%r12), %rax
movq %r12, %rdi
callq *0x8(%rax)
movss -0x64(%rbp), %xmm0
movss %xmm0, 0x50(%r13)
movl $0x3f000000, 0x54(%r13) # imm = 0x3F000000
movl 0x34(%r13), %esi
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rdx
leaq -0x120(%rbp), %rcx
callq 0x816a
movq 0x38(%r13), %rdi
movq -0x60(%rbp), %rax
movq %rax, 0x38(%r13)
movq -0x58(%rbp), %rax
movq %rax, 0x40(%r13)
movq -0x50(%rbp), %rax
movq %rax, 0x48(%r13)
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
testq %rdi, %rdi
je 0x718a
callq 0x3210
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x718a
callq 0x3210
movq 0x6e47(%rip), %rdi      # 0xdfd8
leaq 0x303b(%rip), %rsi      # 0xa1d3
movl $0x1e, %edx
callq 0x3290
movq -0x70(%rbp), %rax
movq (%rax), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
movq 0x6e21(%rip), %rdi      # 0xdfd8
callq 0x3380
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3190
movq %r13, %rdi
callq 0x755a
leaq -0x3b0(%rbp), %rdi
callq 0x30d0
addq $0x388, %rsp            # imm = 0x388
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7225
movq %rax, %r15
movq %r12, %rdi
jmp 0x7322
jmp 0x7225
jmp 0x7225
movq %rax, %r15
jmp 0x7333
movq %rax, %r15
jmp 0x7327
jmp 0x729e
movq %rax, %r15
jmp 0x72f4
movq %rax, %r15
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
je 0x72a1
callq 0x3210
jmp 0x72a1
movq %rax, %r15
movq -0x30(%rbp), %r13
leaq -0x50(%rbp), %r14
jmp 0x730d
jmp 0x72ab
movq %rax, %r15
jmp 0x72dc
movq %rax, %r15
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
cmpq %rax, %rdi
je 0x72dc
callq 0x3210
jmp 0x72dc
movq %rax, %r15
leaq -0x1a8(%rbp), %rdi
callq 0x4b12
jmp 0x72bf
movq %rax, %r15
jmp 0x72bf
movq %rax, %r15
movq -0x30(%rbp), %r13
leaq -0x50(%rbp), %r14
jmp 0x7319
movq %rax, %r15
movq -0x190(%rbp), %rdi
testq %rdi, %rdi
je 0x72bf
callq 0x3210
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x72d0
callq 0x3210
leaq -0x178(%rbp), %rdi
callq 0x4b12
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x72f4
callq 0x3210
movq -0x30(%rbp), %r13
leaq -0x50(%rbp), %r14
movq -0x120(%rbp), %rdi
cmpq %rbx, %rdi
je 0x730d
callq 0x3210
leaq -0xe0(%rbp), %rdi
callq 0x4b12
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0x7327
callq 0x3210
leaq -0x3b0(%rbp), %rdi
callq 0x30d0
movq -0x80(%rbp), %rdi
callq 0x81f6
movq -0x78(%rbp), %rdi
callq 0x8438
movq -0x70(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x7356
callq 0x3210
movq %r13, %rdi
callq 0x84ce
movq %r15, %rdi
callq 0x33e0