// File: /workspace/github_cpp_makefile_star2_O1/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 $0xc8, %rsp
movl %r9d, %ebx
movl %r8d, %r14d
movl %ecx, %r15d
movq %rdx, %rbp
movl %esi, %r13d
movq %rdi, %r12
movl 0x108(%rsp), %eax
movl 0x100(%rsp), %ecx
movq 0x110(%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, 0x40(%rsp)
addq $0x50, %rdi
xorpd %xmm0, %xmm0
movupd %xmm0, 0x30(%r12)
movupd %xmm0, 0x40(%r12)
movq %rdi, 0x48(%rsp)
callq 0x4796
movq 0x56fe(%rip), %rax      # 0x9fb8
movq (%rax), %rdi
subq $0x8, %rsp
leaq 0x2b28(%rip), %rsi      # 0x73f0
movl %r13d, %edx
movq %rbp, 0x40(%rsp)
movq %rbp, %rcx
movl %r15d, %r8d
movl %r14d, 0x1c(%rsp)
movl %r14d, %r9d
xorl %eax, %eax
movl 0x108(%rsp), %r10d
pushq %r10
movl 0x118(%rsp), %r14d
pushq %r14
movq %rbx, %rbp
pushq %rbx
callq 0x22b0
addq $0x20, %rsp
leaq 0x70(%rsp), %rdi
callq 0x21e0
testl %r13d, %r13d
je 0x4a33
movl %r15d, 0x8(%rsp)
leaq 0x30(%r12), %r15
movl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x78(%rsp), %rbx
movl %r13d, 0x28(%rsp)
movq 0x18(%rsp), %r14
movq %rbx, %rdi
movl 0x100(%rsp), %esi
movsd 0x30(%rsp), %xmm0
movq 0x38(%rsp), %rdx
movl 0x8(%rsp), %ecx
movl %ebp, %r8d
callq 0x582e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x61ce
movq %rax, %rdi
movq %r14, %rsi
callq 0x2060
incq (%r15)
movq %rbx, %rdi
callq 0x619c
decl %r13d
jne 0x493e
movl 0x8(%rsp), %ebx
movl %ebx, %r14d
xorl %r15d, %r15d
leaq 0x78(%rsp), %r13
leaq 0x50(%rsp), %rbp
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x58f0
testl %ebx, %ebx
je 0x4a07
xorl %r13d, %r13d
movq %rbp, 0x58(%rsp)
movq %rbp, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
leaq (,%r13,2), %rdi
addq %r13, %rdi
shlq $0x3, %rdi
addq 0x78(%rsp), %rdi
cmpq %rbp, %rdi
je 0x49e5
movq %rbp, %rsi
movq %rbp, %rdx
callq 0x6390
movq 0x50(%rsp), %rdi
cmpq %rbp, %rdi
je 0x49ff
movq (%rdi), %rbx
callq 0x2200
movq %rbx, %rdi
cmpq %rbp, %rbx
jne 0x49ef
incq %r13
cmpq %r14, %r13
jne 0x49ae
movq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %r13
movq %r13, %rsi
callq 0x597c
movq %r13, %rdi
callq 0x59a8
incl %r15d
cmpl 0x28(%rsp), %r15d
movl 0x8(%rsp), %ebx
jne 0x4999
movq 0x18(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x20(%rsp)
cmpq %rax, %rcx
movl 0x14(%rsp), %ebx
je 0x4bb8
movl %ebx, %eax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
leaq 0x78(%rsp), %r15
leaq 0xb0(%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 %r14, %rdx
jbe 0x4c5b
movq %r14, 0x8(%rsp)
leaq (%r14,%r14,2), %rcx
movq %rcx, 0x38(%rsp)
leaq (%rax,%rcx,8), %rsi
movq %r15, %rdi
callq 0x59fe
testl %ebx, %ebx
je 0x4b87
movq 0x20(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x30(%rsp)
xorl %r15d, %r15d
xorl %ebp, %ebp
movq 0x50(%r12), %rsi
movq 0x58(%r12), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rdx
cmpq %rbp, %rdx
jbe 0x4c4a
addq %r15, %rsi
movq %r13, %rdi
callq 0x3810
movq 0x30(%rsp), %rdi
movq %r13, %r14
movq %r13, %rsi
callq 0x5a90
movl %eax, %r13d
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x4b19
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 0x8(%rsp), %rdx
jbe 0x4c45
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rbx
movl $0x18, %edi
callq 0x2220
movslq %r13d, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rbx,%rcx,8), %r13
movl %ebp, 0x10(%rax)
movq %rax, %rdi
movq %r13, %rsi
callq 0x2060
incq 0x10(%r13)
incq %rbp
addq $0x18, %r15
cmpl %ebp, 0x28(%rsp)
movq %r14, %r13
jne 0x4ac1
movq 0x8(%rsp), %r14
incq %r14
leaq 0x78(%rsp), %r15
movq %r15, %rdi
callq 0x59a8
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
cmpq 0x18(%rsp), %rax
movl 0x14(%rsp), %ebx
jne 0x4a64
leaq 0x68(%rsp), %rdi
callq 0x21e0
movq 0x540f(%rip), %rdi      # 0x9fd8
leaq 0x288b(%rip), %rsi      # 0x745b
movl $0x1c, %edx
callq 0x2240
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x2100
movq 0x53e8(%rip), %rdi      # 0x9fd8
callq 0x2310
movq %rax, %rbx
leaq 0x2879(%rip), %rsi      # 0x7478
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 $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rbp
leaq 0x2714(%rip), %rdi      # 0x7365
movq %rbp, %rsi
xorl %eax, %eax
callq 0x22e0
leaq 0x2703(%rip), %rdi      # 0x7365
movq %r14, %rsi
xorl %eax, %eax
callq 0x22e0
movq %rax, %r14
jmp 0x4ce3
jmp 0x4c8d
jmp 0x4c8d
jmp 0x4c8d
jmp 0x4c8d
movq %rax, %r14
jmp 0x4caf
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x619c
jmp 0x4cd9
movq %rax, %r14
jmp 0x4cd9
movq %rax, %r14
movq 0x50(%rsp), %rdi
cmpq %rbp, %rdi
je 0x4caf
movq (%rdi), %rbx
callq 0x2200
movq %rbx, %rdi
cmpq %rbp, %rbx
jne 0x4c9f
jmp 0x4ccf
jmp 0x4ccc
jmp 0x4ccc
movq %rax, %r14
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x4ccf
callq 0x2200
jmp 0x4ccf
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x59a8
movq 0x48(%rsp), %rdi
callq 0x3528
movq 0x40(%rsp), %rdi
callq 0x5af8
movq 0x18(%rsp), %rdi
callq 0x6ba8
movq %r14, %rdi
callq 0x23c0
nop