// File: /workspace/github_cpp_makefile_star2_O2/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 $0x378, %rsp            # imm = 0x378
movl %ecx, %ebx
movss %xmm0, -0x3c(%rbp)
movl %edx, %r14d
movss %xmm1, -0x40(%rbp)
leaq 0x8(%rdi), %rax
andl $0x0, 0x8(%rdi)
andq $0x0, 0x10(%rdi)
movq %rax, 0x18(%rdi)
movq %rax, 0x20(%rdi)
andq $0x0, 0x28(%rdi)
movq %rsi, %r15
leaq 0x38(%rdi), %rax
movq %rax, -0x30(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%rdi)
andq $0x0, 0x48(%rdi)
leaq 0x58(%rdi), %rax
movq %rax, -0x48(%rbp)
leaq 0x60(%rdi), %rax
andl $0x0, 0x60(%rdi)
andq $0x0, 0x68(%rdi)
movq %rax, 0x70(%rdi)
movq %rax, 0x78(%rdi)
leaq 0x88(%rdi), %rax
movq %rax, -0x50(%rbp)
movups %xmm0, 0x80(%rdi)
movq %rdi, -0x38(%rbp)
movups %xmm0, 0x90(%rdi)
leaq -0x3a0(%rbp), %rdi
callq 0x3280
leaq -0x3a0(%rbp), %rdi
pushq $0x8
popq %rdx
movq %r15, %rsi
callq 0x3180
pushq $0x60
popq %rdi
callq 0x3230
movq %rax, %r13
movq %rax, %rdi
callq 0x3b88
movq -0x38(%rbp), %r15
movl %r14d, 0x30(%r15)
movl %ebx, 0x34(%r15)
callq 0x3190
movq %rax, %rbx
leaq -0x328(%rbp), %rdi
callq 0x30c0
testb %al, %al
je 0x64f6
leaq 0x2f9f(%rip), %rdi      # 0x92a5
callq 0x3370
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x90(%rbp), %r15
leaq -0x148(%rbp), %r12
leaq -0x3a0(%rbp), %rdi
movq %r15, %rsi
callq 0x3080
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x64e6
movq %r12, %rdi
movq %r15, %rsi
callq 0x3300
leaq -0x70(%rbp), %rdi
movq %r13, %r14
movq %r13, %rsi
movq %r12, %rdx
callq 0x3cd0
movq %rbx, %r15
movq %r12, %rdi
callq 0x3130
movq -0x70(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x3300
movq -0x70(%rbp), %rdi
addq $0x20, %rdi
leaq 0x2dff(%rip), %rsi      # 0x9190
callq 0x5fed
movl %eax, %ebx
movq -0x70(%rbp), %rsi
addq $0x40, %rsi
leaq -0x128(%rbp), %r12
movq %r12, %rdi
callq 0x3300
leaq -0x198(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x3300
leaq -0xc8(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x3dd6
movq %r13, %rdi
callq 0x3130
andl $0x0, -0xb0(%rbp)
leaq -0xa8(%rbp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq -0x160(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x70a0
leaq -0x178(%rbp), %r12
movq %r12, %rdi
movq -0x38(%rbp), %rsi
movq %r13, %rdx
callq 0x670e
xorb $0x1, %bl
movzbl %bl, %ebx
movq %r13, %rdi
callq 0x44ca
movl %ebx, -0x108(%rbp)
leaq -0x100(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x72b4
movq %r12, %r13
leaq -0xb0(%rbp), %r12
movq %r12, %rdi
leaq -0x108(%rbp), %rsi
callq 0x70f4
movq %rbx, %rdi
callq 0x75b8
movq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0x7118
movq %r15, %rbx
leaq -0xe8(%rbp), %r15
movq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x7154
movq %rax, %rdi
movq %r12, %rsi
callq 0x71be
movq %r13, %rdi
callq 0x75b8
leaq -0xa8(%rbp), %rdi
callq 0x75b8
leaq -0xc8(%rbp), %rdi
callq 0x44ca
leaq -0x128(%rbp), %rdi
callq 0x3130
movq %r15, %rdi
callq 0x3130
leaq -0x70(%rbp), %rdi
callq 0x44ca
leaq -0x90(%rbp), %r15
leaq -0x148(%rbp), %r12
movq %r14, %r13
jmp 0x6329
leaq -0x90(%rbp), %rdi
callq 0x3130
movq -0x38(%rbp), %r15
callq 0x3190
subq %rbx, %rax
cvtsi2sd %rax, %xmm0
divsd 0x2c45(%rip), %xmm0     # 0x9150
movsd %xmm0, -0x58(%rbp)
divsd 0x2c40(%rip), %xmm0     # 0x9158
callq 0x33b0
cvtsd2ss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm0
mulss 0x2c43(%rip), %xmm1     # 0x9170
cvtss2sd %xmm1, %xmm1
addsd -0x58(%rbp), %xmm1
cvtsd2ss %xmm1, %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x2c4d(%rip), %rdi      # 0x9192
movb $0x2, %al
callq 0x3050
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
movss -0x3c(%rbp), %xmm0
movss %xmm0, 0x50(%r15)
movl $0x3f000000, 0x54(%r15) # imm = 0x3F000000
movl 0x34(%r15), %esi
leaq -0x90(%rbp), %rdi
leaq -0x40(%rbp), %rdx
leaq -0xe8(%rbp), %rcx
callq 0x71e2
leaq -0x90(%rbp), %rbx
movq -0x30(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7f56
movq %rbx, %rdi
callq 0x756a
movq 0x7a2f(%rip), %rdi      # 0xdfd8
leaq 0x2bf3(%rip), %rsi      # 0x91a3
callq 0x3220
movq (%r14), %rcx
movss (%rcx), %xmm0
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
callq 0x3140
movq -0x38(%rbp), %rdi
callq 0x689e
leaq -0x3a0(%rbp), %rdi
callq 0x30d0
addq $0x378, %rsp            # imm = 0x378
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6604
movq %rax, %rbx
movq %r13, %rdi
callq 0x3210
jmp 0x6607
jmp 0x6604
movq %rax, %rbx
movq -0x30(%rbp), %r14
jmp 0x66d7
movq %rax, %rbx
movq -0x30(%rbp), %r14
jmp 0x66e3
movq %rax, %rbx
jmp 0x66d7
jmp 0x6676
movq %rax, %rbx
jmp 0x66b2
movq %rax, %rbx
leaq -0x148(%rbp), %rdi
callq 0x3130
jmp 0x6679
movq %rax, %rbx
movq -0x30(%rbp), %r14
jmp 0x66c2
jmp 0x667f
movq %rax, %rbx
jmp 0x66a6
movq %rax, %rbx
leaq -0x198(%rbp), %rdi
callq 0x3130
jmp 0x66a6
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
callq 0x44ca
jmp 0x668e
movq %rax, %rbx
jmp 0x668e
movq %rax, %rbx
movq -0x30(%rbp), %r14
jmp 0x66cb
movq %rax, %rbx
leaq -0x178(%rbp), %rdi
callq 0x75b8
leaq -0xa8(%rbp), %rdi
callq 0x75b8
leaq -0xc8(%rbp), %rdi
callq 0x44ca
leaq -0x128(%rbp), %rdi
callq 0x3130
movq -0x30(%rbp), %r14
leaq -0xe8(%rbp), %rdi
callq 0x3130
leaq -0x70(%rbp), %rdi
callq 0x44ca
leaq -0x90(%rbp), %rdi
callq 0x3130
leaq -0x3a0(%rbp), %rdi
callq 0x30d0
movq -0x50(%rbp), %rdi
callq 0x7242
movq -0x48(%rbp), %rdi
callq 0x743a
movq %r14, %rdi
callq 0x756a
movq -0x38(%rbp), %rdi
callq 0x74d2
movq %rbx, %rdi
callq 0x33e0