// File: /workspace/github_cpp_makefile_star2_O1/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 0x3e70
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 0x70e7
movq %r12, -0x38(%rbp)
movq %rbx, -0xc8(%rbp)
movq %r13, -0x30(%rbp)
leaq 0x3510(%rip), %rdi      # 0xa2d5
callq 0x3350
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x130(%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 -0x160(%rbp), %rbx
jne 0x70c6
leaq -0x150(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x3cb2
leaq -0x100(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %rbx, %rdx
callq 0x4022
movq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rax
cmpq %rax, %rdi
je 0x6e77
callq 0x3210
movq -0x100(%rbp), %rax
movq %r14, %rbx
movq %r14, -0x140(%rbp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x140(%rbp), %rdi
callq 0x3cb2
movq -0x100(%rbp), %rdi
addq $0x20, %rdi
leaq 0x3310(%rip), %rsi      # 0xa1c0
callq 0x30f0
xorl %r14d, %r14d
testl %eax, %eax
setne %r15b
movq -0x100(%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 0x3cb2
leaq -0x110(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
addq %rsi, %rdx
leaq -0x120(%rbp), %r13
movq %r13, %rdi
callq 0x3cb2
leaq -0x178(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r13, %rdx
callq 0x4198
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x6f43
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 0x8038
movq %r12, %rdi
movq -0x30(%rbp), %rsi
movq %r13, %rdx
callq 0x7398
movb %r15b, %r14b
movq %r13, %rdi
callq 0x4b08
movl %r14d, -0xe8(%rbp)
leaq -0xe0(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x8286
movl -0xe8(%rbp), %eax
movl %eax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
movups -0x90(%rbp), %xmm0
movq -0xe0(%rbp), %rax
movq %rax, -0x98(%rbp)
movups -0xd8(%rbp), %xmm1
movups %xmm1, -0x90(%rbp)
movq %rdi, -0xe0(%rbp)
movups %xmm0, -0xd8(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq $0x0, 0x10(%r14)
testq %rdi, %rdi
movq %rbx, %r14
leaq -0x3b0(%rbp), %r15
je 0x7012
callq 0x3210
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x7023
callq 0x3210
movq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x80c6
movq -0x78(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x810e
movl -0xa0(%rbp), %ecx
movl %ecx, (%rax)
addq $0x8, %rax
movq %rax, %rdi
leaq -0x98(%rbp), %rsi
callq 0x8bc2
movq -0x190(%rbp), %rdi
testq %rdi, %rdi
je 0x706f
callq 0x3210
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x7080
callq 0x3210
leaq -0x178(%rbp), %rdi
callq 0x4b08
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x70a4
callq 0x3210
movq -0x140(%rbp), %rdi
cmpq %r14, %rdi
je 0x70b5
callq 0x3210
leaq -0x100(%rbp), %rdi
callq 0x4b08
jmp 0x6deb
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x70d8
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 0x3081(%rip), %xmm0     # 0xa180
movsd %xmm0, -0x38(%rbp)
divsd 0x307c(%rip), %xmm0     # 0xa188
callq 0x33b0
cvtsd2ss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
mulss 0x307c(%rip), %xmm1     # 0xa1a0
cvtss2sd %xmm1, %xmm1
addsd -0x38(%rbp), %xmm1
cvtsd2ss %xmm1, %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x3086(%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 -0x140(%rbp), %rcx
callq 0x818e
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 0x71ad
callq 0x3210
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x71bb
callq 0x3210
movq 0x6e16(%rip), %rdi      # 0xdfd8
leaq 0x300a(%rip), %rsi      # 0xa1d3
movl $0x1e, %edx
callq 0x3290
movq -0x70(%rbp), %rax
movq (%rax), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
movq 0x6df0(%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 0x758c
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 0x7256
movq %rax, %r15
movq %r12, %rdi
jmp 0x7353
jmp 0x7256
jmp 0x7256
movq %rax, %r15
jmp 0x7364
movq %rax, %r15
jmp 0x7358
jmp 0x72cf
movq %rax, %r15
jmp 0x7325
movq %rax, %r15
movq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rax
cmpq %rax, %rdi
je 0x72d2
callq 0x3210
jmp 0x72d2
movq %rax, %r15
movq -0x30(%rbp), %r13
leaq -0x50(%rbp), %r14
jmp 0x733e
jmp 0x72dc
movq %rax, %r15
jmp 0x730d
movq %rax, %r15
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x730d
callq 0x3210
jmp 0x730d
movq %rax, %r15
leaq -0x1a8(%rbp), %rdi
callq 0x4b08
jmp 0x72f0
movq %rax, %r15
jmp 0x72f0
movq %rax, %r15
movq -0x30(%rbp), %r13
leaq -0x50(%rbp), %r14
jmp 0x734a
movq %rax, %r15
movq -0x190(%rbp), %rdi
testq %rdi, %rdi
je 0x72f0
callq 0x3210
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x7301
callq 0x3210
leaq -0x178(%rbp), %rdi
callq 0x4b08
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x7325
callq 0x3210
movq -0x30(%rbp), %r13
leaq -0x50(%rbp), %r14
movq -0x140(%rbp), %rdi
cmpq %rbx, %rdi
je 0x733e
callq 0x3210
leaq -0x100(%rbp), %rdi
callq 0x4b08
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0x7358
callq 0x3210
leaq -0x3b0(%rbp), %rdi
callq 0x30d0
movq -0x80(%rbp), %rdi
callq 0x821a
movq -0x78(%rbp), %rdi
callq 0x8444
movq -0x70(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x7387
callq 0x3210
movq %r13, %rdi
callq 0x84da
movq %r15, %rdi
callq 0x33e0
nop