// File: /workspace/github_cpp_makefile_star2_O3/nikosgalanis[P]Vectors-Similarity-Search-and-Clustering/programs/LSH/../../algorithms/Search/LSH/headers/lsh.h
// Function: LSH<double>::LSH(unsigned int, unsigned long, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>>)
LSH(uint32_t L, uint64_t m, uint32_t M,
				uint32_t n_points, uint32_t k,
				uint32_t space_dim, uint32_t w, std::vector<std::vector<T>> init_vectors) : 
				L(L), m(m), M(M), n_points(n_points), k(k), w(w), space_dim(space_dim), feature_vectors(init_vectors) {
					/**
					 Preprocessing: We want to uniformly select L amplified h.fs g1, .., g_l.
					 Afterwards, we are going to initialize all of the hash tables, before hashing the 
					 vectors.
					 **/
					// calculate the time of the initialization
					time_t start, finish;
					fprintf(stdout, "LSH initialization with parameters: L = %d, m = %ld, M = %d, n_points = %d "
					"k = %d, w = %d, space_dim = %d\n", L, m, M, n_points, k, w, space_dim);
					time(&start);
					for (uint32_t i = 0; i < L; i++) {
						lsh::AmplifiedHashFunction ampl(space_dim, w, m, M, k);
						// Insert each amplified hash fn into the apropriate list
						amplified_hash_fns.push_back(ampl);
					}
					
					// initialize all of our hash tables
					for (uint32_t i = 0; i < L; i++) {
						// for each hash table
						lsh_hash_table current_hash(M);
						for (uint32_t j = 0; j < M; j++) {
							// create n buckets, that each one has a list of integers (a.k.a indices of the vectros)
							list<int> current_list;
							current_hash[j] = current_list;
						}
						lsh_tables.push_back(current_hash);
					}
					
					// insert every vector given to us into every hash table
					int i = 0;
					for (std::list<lsh::AmplifiedHashFunction>::iterator it = amplified_hash_fns.begin(); 
					it != amplified_hash_fns.end(); it++) {
						// refer to the correct hash table in the vetor of hashes
						lsh_hash_table current_table = lsh_tables.at(i);
						// insert each vector in the i-th hash table
						for (uint32_t n = 0; n < n_points; n++) {
							// compute the bucket that the vector will be inserted
							int index = it->assign_to_bucket(feature_vectors.at(n));
							// insert the index of the vector in the correct bucket
							lsh_tables.at(i)[index].push_back(n);
						}
						i++;
					}

					// lsh initialization done. print the time differenct
					time(&finish);
				   	cout << "Initialization completed in " << difftime(finish, start) << " seconds" << endl;
				}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %r9d, %ebx
movl %r8d, %r14d
movl %ecx, %r15d
movq %rdx, %rbp
movl %esi, %r13d
movq %rdi, %r12
movl 0xf8(%rsp), %eax
movl 0xf0(%rsp), %ecx
movq 0x100(%rsp), %rsi
movl %r13d, (%rdi)
movl %ebp, 0x4(%rdi)
movl %r15d, 0x8(%rdi)
movl %r8d, 0xc(%rdi)
movl %r9d, 0x10(%rdi)
movl %eax, 0x14(%rdi)
movl %ecx, 0x18(%rdi)
leaq 0x20(%rdi), %rax
movq %rax, 0x28(%rdi)
movq %rax, 0x18(%rsp)
movq %rax, 0x20(%rdi)
leaq 0x38(%rdi), %rax
movq %rax, 0x30(%rsp)
addq $0x50, %rdi
xorpd %xmm0, %xmm0
movupd %xmm0, 0x30(%r12)
movupd %xmm0, 0x40(%r12)
movq %rdi, 0x38(%rsp)
callq 0x47b2
movq 0x56e2(%rip), %rax      # 0x9fb8
movq (%rax), %rdi
subq $0x8, %rsp
leaq 0x2aec(%rip), %rsi      # 0x73d0
movl %r13d, %edx
movq %rbp, 0x28(%rsp)
movq %rbp, %rcx
movl %r15d, %r8d
movl %r14d, 0x1c(%rsp)
movl %r14d, %r9d
xorl %eax, %eax
movl 0xf8(%rsp), %r10d
pushq %r10
movl 0x108(%rsp), %r14d
pushq %r14
movq %rbx, %rbp
pushq %rbx
callq 0x22b0
addq $0x20, %rsp
leaq 0x60(%rsp), %rdi
callq 0x21e0
testl %r13d, %r13d
je 0x4a4d
movl %r15d, 0x8(%rsp)
leaq 0x30(%r12), %r15
movl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, (%rsp)
leaq 0x68(%rsp), %rbx
movl %r13d, 0x2c(%rsp)
movq 0x18(%rsp), %r14
movq %rbx, %rdi
movl 0xf0(%rsp), %esi
movsd (%rsp), %xmm0
movq 0x20(%rsp), %rdx
movl 0x8(%rsp), %ecx
movl %ebp, %r8d
callq 0x583e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x620a
movq %rax, %rdi
movq %r14, %rsi
callq 0x2060
incq (%r15)
movq %rbx, %rdi
callq 0x61d8
decl %r13d
jne 0x4959
movl 0x8(%rsp), %ebx
movl %ebx, %r14d
xorl %r15d, %r15d
leaq 0x68(%rsp), %r13
leaq 0x40(%rsp), %rbp
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x5900
testl %ebx, %ebx
je 0x4a21
xorl %r13d, %r13d
movq %rbp, 0x48(%rsp)
movq %rbp, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
leaq (,%r13,2), %rdi
addq %r13, %rdi
shlq $0x3, %rdi
addq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0x4a19
movq %rbp, %rsi
movq %rbp, %rdx
callq 0x63cc
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x4a19
movq (%rdi), %rbx
callq 0x2200
movq %rbx, %rdi
cmpq %rbp, %rbx
jne 0x4a09
incq %r13
cmpq %r14, %r13
jne 0x49c8
movq 0x30(%rsp), %rdi
leaq 0x68(%rsp), %r13
movq %r13, %rsi
callq 0x5988
movq %r13, %rdi
callq 0x59b4
incl %r15d
cmpl 0x2c(%rsp), %r15d
movl 0x8(%rsp), %ebx
jne 0x49b3
movq 0x18(%rsp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
cmpq %rax, %rcx
movl 0x14(%rsp), %ebx
je 0x4bbe
movl %ebx, %eax
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
leaq 0x68(%rsp), %r13
movq 0x38(%r12), %rax
movq 0x40(%r12), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %r15, %rdx
jbe 0x4c5f
leaq (%r15,%r15,2), %r14
leaq (%rax,%r14,8), %rsi
movq %r13, %rdi
callq 0x5a14
testl %ebx, %ebx
je 0x4b94
movq (%rsp), %rax
addq $0x10, %rax
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
movq 0x50(%r12), %rax
movq 0x58(%r12), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rbp, %rdx
jbe 0x4c4e
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
callq 0x382a
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x5aa6
movl %eax, %r13d
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x4b2d
callq 0x2200
movq 0x38(%r12), %rax
movq 0x40(%r12), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %r15, %rdx
jbe 0x4c4b
movq %r15, %rbx
movq (%rax,%r14,8), %r15
movl $0x18, %edi
callq 0x2220
movslq %r13d, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%r15,%rcx,8), %r13
movl %ebp, 0x10(%rax)
movq %rax, %rdi
movq %r13, %rsi
callq 0x2060
incq 0x10(%r13)
incq %rbp
cmpq 0x20(%rsp), %rbp
movq %rbx, %r15
jne 0x4ac4
incq %r15
leaq 0x68(%rsp), %r13
movq %r13, %rdi
callq 0x59b4
movq (%rsp), %rax
movq (%rax), %rax
movq %rax, (%rsp)
cmpq 0x18(%rsp), %rax
movl 0x14(%rsp), %ebx
jne 0x4a75
leaq 0x58(%rsp), %rdi
callq 0x21e0
movq 0x5409(%rip), %rdi      # 0x9fd8
leaq 0x2865(%rip), %rsi      # 0x743b
movl $0x1c, %edx
callq 0x2240
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x2100
movq 0x53e2(%rip), %rdi      # 0x9fd8
callq 0x2310
movq %rax, %rbx
leaq 0x2853(%rip), %rsi      # 0x7458
movl $0x8, %edx
movq %rax, %rdi
callq 0x2240
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2210
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2170
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rbp
leaq 0x26f0(%rip), %rdi      # 0x7345
movq %rbp, %rsi
xorl %eax, %eax
callq 0x22e0
leaq 0x26df(%rip), %rdi      # 0x7345
movq %r15, %rsi
xorl %eax, %eax
callq 0x22e0
movq %rax, %r14
jmp 0x4ce7
jmp 0x4c91
jmp 0x4c91
jmp 0x4c91
jmp 0x4c91
movq %rax, %r14
jmp 0x4cb3
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x61d8
jmp 0x4cdd
movq %rax, %r14
jmp 0x4cdd
movq %rax, %r14
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x4cb3
movq (%rdi), %rbx
callq 0x2200
movq %rbx, %rdi
cmpq %rbp, %rbx
jne 0x4ca3
jmp 0x4cd3
jmp 0x4cd0
jmp 0x4cd0
movq %rax, %r14
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x4cd3
callq 0x2200
jmp 0x4cd3
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x59b4
movq 0x38(%rsp), %rdi
callq 0x3546
movq 0x30(%rsp), %rdi
callq 0x5b0e
movq 0x18(%rsp), %rdi
callq 0x6be2
movq %r14, %rdi
callq 0x23c0
nop