// File: /workspace/github_cpp_makefile_star2_O2/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 $0xa8, %rsp
movl %r9d, %ebx
movl %r8d, %r12d
movl %ecx, %r13d
movq %rdx, %rbp
movl %esi, %r15d
movl 0xe8(%rsp), %eax
movl 0xe0(%rsp), %r14d
movq 0xf0(%rsp), %rsi
movl %r15d, (%rdi)
movl %ebp, 0x4(%rdi)
movl %ecx, 0x8(%rdi)
movl %r8d, 0xc(%rdi)
movl %r9d, 0x10(%rdi)
movl %eax, 0x14(%rdi)
movl %r14d, 0x18(%rdi)
leaq 0x20(%rdi), %rax
movq %rax, 0x28(%rdi)
movq %rax, 0x10(%rsp)
movq %rax, 0x20(%rdi)
leaq 0x38(%rdi), %rax
movq %rax, 0x18(%rsp)
leaq 0x50(%rdi), %rax
xorpd %xmm0, %xmm0
movupd %xmm0, 0x30(%rdi)
movupd %xmm0, 0x40(%rdi)
movq %rax, 0x28(%rsp)
movq %rax, %rdi
callq 0x3c32
movq 0x62a5(%rip), %rax      # 0x9fc0
movq (%rax), %rdi
subq $0x8, %rsp
leaq 0x264d(%rip), %rsi      # 0x6376
movl %r15d, %edx
movq %rbp, %rcx
movl %r13d, %r8d
movl %r12d, %r9d
xorl %eax, %eax
pushq %r14
movl 0xf8(%rsp), %r10d
movq %r10, %r14
pushq %r10
pushq %rbx
callq 0x2240
addq $0x20, %rsp
leaq 0x50(%rsp), %rdi
callq 0x2180
movl %r14d, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x20(%rsp)
movl %r15d, %r14d
leaq 0x58(%rsp), %r15
movl %r14d, 0x8(%rsp)
subl $0x1, %r14d
jb 0x3daf
movq %r15, %rdi
movl 0xe0(%rsp), %esi
movsd 0x20(%rsp), %xmm0
movl %ebp, %edx
movl %r13d, %ecx
movl %ebx, %r8d
callq 0x48b0
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x495e
movq %r15, %rdi
callq 0x5222
jmp 0x3d75
movl %r13d, %eax
movq %rax, 0x20(%rsp)
imulq $0x18, %rax, %r14
xorl %ebp, %ebp
leaq 0x58(%rsp), %r15
leaq 0x30(%rsp), %r13
cmpl 0x8(%rsp), %ebp
je 0x3e32
movl %r12d, %ebx
movq %r15, %rdi
movq 0x20(%rsp), %rsi
movq %r13, %rdx
callq 0x496a
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x3e16
movq %r13, 0x38(%rsp)
movq %r13, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
movq 0x58(%rsp), %rdi
addq %r12, %rdi
movq %r13, %rsi
callq 0x49bc
movq %r13, %rdi
callq 0x5744
addq $0x18, %r12
jmp 0x3de3
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x49d8
movq %r15, %rdi
callq 0x4a04
incl %ebp
movl %ebx, %r12d
jmp 0x3dc7
movl %r12d, %ebx
xorl %r12d, %r12d
leaq 0x90(%rsp), %rbp
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x8(%rsp)
cmpq 0x10(%rsp), %rax
je 0x3ef8
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x4a26
leaq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x4a44
movq 0x8(%rsp), %rax
leaq 0x10(%rax), %r13
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x3ee6
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x3af2
movq %rbp, %rdi
movq %rax, %rsi
callq 0x3152
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4a9e
movl %eax, %r14d
movq %rbp, %rdi
callq 0x2f06
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x4a26
movslq %r14d, %rcx
imulq $0x18, %rcx, %rdi
addq (%rax), %rdi
movl %r15d, 0x30(%rsp)
leaq 0x30(%rsp), %rsi
callq 0x4afc
incq %r15
jmp 0x3e88
incq %r12
leaq 0x58(%rsp), %rdi
callq 0x4a04
jmp 0x3e4a
leaq 0x48(%rsp), %rdi
callq 0x2180
movq 0x60cf(%rip), %rdi      # 0x9fd8
leaq 0x24d1(%rip), %rsi      # 0x63e1
callq 0x21b0
movq %rax, %rbx
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x20f0
movq %rbx, %rdi
callq 0x22a0
leaq 0x24c8(%rip), %rsi      # 0x63fe
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20d0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x3fb6
jmp 0x3f77
movq %rax, %rbx
jmp 0x3f9d
jmp 0x3f77
jmp 0x3f77
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x5222
jmp 0x3fac
movq %rax, %rbx
jmp 0x3fac
jmp 0x3f9f
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x2f06
jmp 0x3fa2
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x5744
jmp 0x3fa2
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x4a04
movq 0x28(%rsp), %rdi
callq 0x2e8e
movq 0x18(%rsp), %rdi
callq 0x4b08
movq 0x10(%rsp), %rdi
callq 0x5d48
movq %rbx, %rdi
callq 0x2340