// File: nikosgalanis[P]Vectors-Similarity-Search-and-Clustering/programs/LSH/../../algorithms/Search/LSH/headers/lsh.h
// Function: LSH<double>::RangeSearch[abi:cxx11](std::vector<double, std::allocator<double>>, double, int)
list<pair<int,T>> RangeSearch(vector<T> query_vector, double radius, int c) {
					list<pair<int,T>> result;

					int i = 0;
					int visited = 0;
					// Traverse all the hash tables. aka 1 ... L
					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
						// find the bucket that the query hashes into
						int index = it->assign_to_bucket(query_vector);
						// access that specific bucket
						list<int> bucket = lsh_tables.at(i)[index];
						// get all the indexes of the vectors in the bucket
						for (std::list<int>::iterator bucket_it = bucket.begin(); bucket_it != bucket.end(); bucket_it++) {
							// increase the visited items
							visited++;
							
							// calculate the distance between the selected vector and our query vector
							T distance = metrics::ManhatanDistance(feature_vectors.at(*bucket_it), query_vector, space_dim);
							
							// create the new pair
							pair<int, T> new_pair = make_pair(*bucket_it, distance);

							// check if the pair is already on a list
							if (find(result.begin(), result.end(), new_pair) != result.end()) {
								continue;
							}

							// if the distance is smaller than the radius, push it in our result list
							if (distance < (T)(radius * c)) {
								result.push_back(new_pair);
							}
							// if (visited > 20 * L) {
							//     return result;
							// }
						}
						i++;
					}
					return result;
				}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movq %rdx, 0x48(%rsp)
movq %rdi, 0x50(%rsp)
movq %rdi, %rax
movq %rax, 0x58(%rsp)
movq %rdi, 0x170(%rsp)
movq %rsi, 0x168(%rsp)
movq %rdx, 0x160(%rsp)
movsd %xmm0, 0x158(%rsp)
movl %ecx, 0x154(%rsp)
movq 0x168(%rsp), %rax
movq %rax, 0x60(%rsp)
movb $0x0, 0x153(%rsp)
callq 0x8900
movq 0x60(%rsp), %rdi
movl $0x0, 0x14c(%rsp)
movl $0x0, 0x148(%rsp)
addq $0x20, %rdi
callq 0x9430
movq %rax, 0x140(%rsp)
movq 0x60(%rsp), %rdi
addq $0x20, %rdi
callq 0x9480
movq %rax, 0x138(%rsp)
leaq 0x140(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x9460
testb $0x1, %al
jne 0x7c1b
jmp 0x7fb1
leaq 0x140(%rsp), %rdi
callq 0x95f0
movq 0x48(%rsp), %rsi
movq %rax, 0x40(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x4500
jmp 0x7c41
movq 0x40(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x9610
movl %eax, 0x3c(%rsp)
jmp 0x7c59
leaq 0x118(%rsp), %rdi
callq 0x34b0
movl 0x3c(%rsp), %eax
movq 0x60(%rsp), %rdi
movl %eax, 0x134(%rsp)
addq $0x38, %rdi
movslq 0x14c(%rsp), %rsi
callq 0x94b0
movq %rax, 0x30(%rsp)
jmp 0x7c8e
movq 0x30(%rsp), %rdi
movslq 0x134(%rsp), %rsi
callq 0x92d0
movq %rax, %rsi
leaq 0xf0(%rsp), %rdi
callq 0xe9d0
jmp 0x7cb2
leaq 0xf0(%rsp), %rdi
callq 0xccb0
movq %rax, 0xe8(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0xcce0
movq %rax, 0xe0(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0xcd10
testb $0x1, %al
jne 0x7cfa
jmp 0x7f6b
movq 0x60(%rsp), %rax
movl 0x148(%rsp), %ecx
incl %ecx
movl %ecx, 0x148(%rsp)
addq $0x50, %rax
movq %rax, 0x20(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0xcd80
movq 0x20(%rsp), %rdi
movslq (%rax), %rsi
callq 0x62e0
movq %rax, 0x28(%rsp)
jmp 0x7d39
movq 0x28(%rsp), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x4500
jmp 0x7d4d
movq 0x48(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x4500
jmp 0x7d61
movq 0x60(%rsp), %rax
movl 0x18(%rax), %edx
leaq 0xc0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x8910
movsd %xmm0, 0x18(%rsp)
jmp 0x7d86
leaq 0xa8(%rsp), %rdi
callq 0x34b0
leaq 0xc0(%rsp), %rdi
callq 0x34b0
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0xcd80
movq %rax, %rdi
leaq 0xd8(%rsp), %rsi
callq 0xf520
movsd %xmm0, 0x8(%rsp)
movl %eax, 0x14(%rsp)
jmp 0x7dd8
movq 0x50(%rsp), %rdi
movsd 0x8(%rsp), %xmm0
movl 0x14(%rsp), %eax
movl %eax, 0x98(%rsp)
movsd %xmm0, 0xa0(%rsp)
callq 0x7a80
movq 0x50(%rsp), %rdi
movq %rax, 0x88(%rsp)
callq 0x7ad0
movq %rax, 0x80(%rsp)
movq 0x88(%rsp), %rdi
movq 0x80(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0xf560
movq %rax, (%rsp)
jmp 0x7e39
movq 0x50(%rsp), %rdi
movq (%rsp), %rax
movq %rax, 0x90(%rsp)
callq 0x7ad0
movq %rax, 0x78(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x7ab0
testb $0x1, %al
jne 0x7e6f
jmp 0x7f15
jmp 0x7f52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x7fda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x34b0
jmp 0x7fda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x7fa2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x7f03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x34b0
leaq 0xc0(%rsp), %rdi
callq 0x34b0
jmp 0x7fa2
movsd 0xd8(%rsp), %xmm1
movsd 0x158(%rsp), %xmm0
cvtsi2sdl 0x154(%rsp), %xmm2
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x7f50
movq 0x50(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x8a50
jmp 0x7f4e
jmp 0x7f50
jmp 0x7f52
leaq 0xe8(%rsp), %rdi
xorl %esi, %esi
callq 0xf5c0
movq %rax, 0x70(%rsp)
jmp 0x7cc7
movl 0x14c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14c(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x9350
leaq 0x140(%rsp), %rdi
xorl %esi, %esi
callq 0x96e0
movq %rax, 0x68(%rsp)
jmp 0x7be7
leaq 0xf0(%rsp), %rdi
callq 0x9350
jmp 0x7fda
movb $0x1, 0x153(%rsp)
testb $0x1, 0x153(%rsp)
jne 0x7fcd
movq 0x50(%rsp), %rdi
callq 0x8000
movq 0x58(%rsp), %rax
addq $0x178, %rsp            # imm = 0x178
retq
movq 0x50(%rsp), %rdi
callq 0x8000
movq 0x110(%rsp), %rdi
callq 0x2370
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)