// File: 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:
subq $0x1c8, %rsp            # imm = 0x1C8
movq 0x1e0(%rsp), %rax
movq %rax, 0x90(%rsp)
movl 0x1d8(%rsp), %eax
movl 0x1d0(%rsp), %eax
movq %rdi, 0x1c0(%rsp)
movl %esi, 0x1bc(%rsp)
movq %rdx, 0x1b0(%rsp)
movl %ecx, 0x1ac(%rsp)
movl %r8d, 0x1a8(%rsp)
movl %r9d, 0x1a4(%rsp)
movq 0x1c0(%rsp), %rdi
movq %rdi, 0x88(%rsp)
movl 0x1bc(%rsp), %eax
movl %eax, (%rdi)
movl 0x1b0(%rsp), %eax
movl %eax, 0x4(%rdi)
movl 0x1ac(%rsp), %eax
movl %eax, 0x8(%rdi)
movl 0x1a8(%rsp), %eax
movl %eax, 0xc(%rdi)
movl 0x1a4(%rsp), %eax
movl %eax, 0x10(%rdi)
movl 0x1d8(%rsp), %eax
movl %eax, 0x14(%rdi)
movl 0x1d0(%rsp), %eax
movl %eax, 0x18(%rdi)
addq $0x20, %rdi
movq %rdi, 0x78(%rsp)
callq 0x9080
movq 0x88(%rsp), %rdi
addq $0x38, %rdi
movq %rdi, 0x80(%rsp)
callq 0x9090
movq 0x88(%rsp), %rdi
movq 0x90(%rsp), %rsi
addq $0x50, %rdi
movq %rdi, 0x98(%rsp)
callq 0x6510
jmp 0x6702
movq 0x108af(%rip), %rax     # 0x16fb8
movq (%rax), %rdi
movl 0x1bc(%rsp), %edx
movq 0x1b0(%rsp), %rcx
movl 0x1ac(%rsp), %r8d
movl 0x1a8(%rsp), %r9d
movl 0x1a4(%rsp), %r11d
movl 0x1d8(%rsp), %r10d
movl 0x1d0(%rsp), %eax
leaq 0x9c3d(%rip), %rsi      # 0x10386
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x2270
leaq 0x188(%rsp), %rdi
callq 0x2180
movl $0x0, 0x17c(%rsp)
movl 0x17c(%rsp), %eax
cmpl 0x1bc(%rsp), %eax
jae 0x6857
movl 0x1d0(%rsp), %esi
movl 0x1d8(%rsp), %eax
cvtsi2sd %rax, %xmm0
movl 0x1b0(%rsp), %edx
movl 0x1ac(%rsp), %ecx
movl 0x1a4(%rsp), %r8d
leaq 0x140(%rsp), %rdi
callq 0x90a0
jmp 0x67c1
movq 0x88(%rsp), %rdi
addq $0x20, %rdi
leaq 0x140(%rsp), %rsi
callq 0x91d0
jmp 0x67dc
leaq 0x140(%rsp), %rdi
callq 0x9210
movl 0x17c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x17c(%rsp)
jmp 0x6775
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x6c7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x6c71
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x9210
jmp 0x6c71
movl $0x0, 0x13c(%rsp)
movl 0x13c(%rsp), %eax
cmpl 0x1bc(%rsp), %eax
jae 0x69dd
movl 0x1ac(%rsp), %eax
movq %rax, 0x68(%rsp)
leaq 0x11f(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x9220
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
leaq 0x120(%rsp), %rdi
callq 0x9230
jmp 0x68ad
leaq 0x11f(%rsp), %rdi
callq 0x92b0
movl $0x0, 0x118(%rsp)
movl 0x118(%rsp), %eax
cmpl 0x1ac(%rsp), %eax
jae 0x6979
leaq 0x100(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x92c0
movl 0x118(%rsp), %eax
movl %eax, %esi
leaq 0x120(%rsp), %rdi
callq 0x92d0
movq 0x60(%rsp), %rsi
movq %rax, %rdi
callq 0x92f0
jmp 0x6910
leaq 0x100(%rsp), %rdi
callq 0x9350
movl 0x118(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x118(%rsp)
jmp 0x68c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x11f(%rsp), %rdi
callq 0x92b0
jmp 0x6c71
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x9350
jmp 0x69cb
movq 0x88(%rsp), %rdi
addq $0x38, %rdi
leaq 0x120(%rsp), %rsi
callq 0x9360
jmp 0x6994
leaq 0x120(%rsp), %rdi
callq 0x93d0
movl 0x13c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x13c(%rsp)
jmp 0x6862
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x93d0
jmp 0x6c71
movq 0x88(%rsp), %rdi
movl $0x0, 0xfc(%rsp)
addq $0x20, %rdi
callq 0x9430
movq %rax, 0xf0(%rsp)
movq 0x88(%rsp), %rdi
addq $0x20, %rdi
callq 0x9480
movq %rax, 0xe8(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x9460
testb $0x1, %al
jne 0x6a38
jmp 0x6bf1
movq 0x88(%rsp), %rdi
addq $0x38, %rdi
movslq 0xfc(%rsp), %rsi
callq 0x94b0
movq %rax, 0x58(%rsp)
jmp 0x6a58
movq 0x58(%rsp), %rsi
leaq 0xd0(%rsp), %rdi
callq 0x94f0
jmp 0x6a6c
movl $0x0, 0xcc(%rsp)
movl 0xcc(%rsp), %eax
cmpl 0x1a8(%rsp), %eax
jae 0x6ba5
leaq 0xf0(%rsp), %rdi
callq 0x95f0
movq 0x88(%rsp), %rdi
movq %rax, 0x48(%rsp)
addq $0x50, %rdi
movl 0xcc(%rsp), %eax
movl %eax, %esi
callq 0x62e0
movq %rax, 0x50(%rsp)
jmp 0x6abe
movq 0x50(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x4500
jmp 0x6ad2
movq 0x48(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x9610
movl %eax, 0x44(%rsp)
jmp 0x6aea
leaq 0xb0(%rsp), %rdi
callq 0x34b0
movl 0x44(%rsp), %eax
movq 0x88(%rsp), %rdi
movl %eax, 0xc8(%rsp)
addq $0x38, %rdi
movslq 0xfc(%rsp), %rsi
callq 0x94b0
movq %rax, 0x38(%rsp)
jmp 0x6b22
movq 0x38(%rsp), %rdi
movslq 0xc8(%rsp), %rsi
callq 0x92d0
movq %rax, %rdi
movl 0xcc(%rsp), %eax
movl %eax, 0xac(%rsp)
leaq 0xac(%rsp), %rsi
callq 0x96a0
jmp 0x6b54
jmp 0x6b56
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x6a77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x6bdf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x34b0
jmp 0x6bdf
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x93d0
leaq 0xf0(%rsp), %rdi
xorl %esi, %esi
callq 0x96e0
movq %rax, 0xa0(%rsp)
jmp 0x6a01
leaq 0xd0(%rsp), %rdi
callq 0x93d0
jmp 0x6c71
leaq 0x180(%rsp), %rdi
callq 0x2180
movq 0x103d3(%rip), %rdi     # 0x16fd8
leaq 0x97e5(%rip), %rsi      # 0x103f1
callq 0x21b0
movq %rax, 0x30(%rsp)
jmp 0x6c18
movq 0x180(%rsp), %rdi
movq 0x188(%rsp), %rsi
callq 0x20d0
movq 0x30(%rsp), %rdi
callq 0x23b0
movq %rax, 0x28(%rsp)
jmp 0x6c3e
movq 0x28(%rsp), %rdi
leaq 0x97c4(%rip), %rsi      # 0x1040e
callq 0x21b0
movq %rax, 0x20(%rsp)
jmp 0x6c56
movq 0x20(%rsp), %rdi
movq 0x10366(%rip), %rsi     # 0x16fc8
callq 0x21d0
jmp 0x6c69
addq $0x1c8, %rsp            # imm = 0x1C8
retq
movq 0x98(%rsp), %rdi
callq 0x3510
movq 0x80(%rsp), %rdi
callq 0x9710
movq 0x78(%rsp), %rdi
callq 0x9770
movq 0x198(%rsp), %rdi
callq 0x2370
nopw %cs:(%rax,%rax)
nopl (%rax)