// File: /workspace/github_cpp_makefile_star2_O3/nikosgalanis[P]Vectors-Similarity-Search-and-Clustering/programs/Hypercube/../../algorithms/Search/Hypercube/headers/hypercube.h
// Function: Hypercube<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;

			// store the visited vectors, to find out when we do reach the threshold
			uint32_t visited = 0;
			uint32_t probes_checked = 0;

			/**
			 Step 1: Hash the given vector with the random projection technique
			**/
			int bucket_int = hash_to_hypercube(query_vector);

			/**
			 Step 2: Search in the bucket that the query hashes for neighbors
			**/
			list<int> bucket = hypercube[bucket_int];
			// 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);

				// 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 we've reached the threshold, just return the result list
				if (visited >= threshold)
					return result;
			}

			// return if max probes were traversed
			if (++probes_checked >= max_probes)
				return result;

			/**
			 Step 3 .. n: If necessary, check all the buckets with hamming distance 1 .. n
						until the threshold is reached.
			**/
			// set the desired hamming distance to 1 initially
			int dist_count = 1;
			// while we are under the threshold
			while (true) {
				// parse through all the buckets
				for (uint32_t i = 0; i < n_buckets; i++) {
					// if the hamming distance from the bucket_int is the desired
					if (our_math::hamming_distance(i, bucket_int) == dist_count) {
						// check the bucket for neighbors in the range given
							list<int> bucket = hypercube[i];
							// 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);

								// 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 we've reached the threshold, just return the result list
								if (visited >= threshold)
									return result;
							}
					}
					// return if max probes were traversed
					if (++probes_checked >= max_probes)
						return result;
				}
				// again, if necessary, increase the hamming distance, so we check further buckets
				dist_count++;
			}
		}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %ecx, %ebp
movsd %xmm0, (%rsp)
movq %rsi, %r15
movq %rdi, %rbx
movq %rdi, 0x8(%rdi)
movq %rdi, (%rdi)
movq $0x0, 0x10(%rdi)
leaq 0xa0(%rsp), %rdi
movq %rdx, 0x38(%rsp)
movq %rdx, %rsi
callq 0x38aa
leaq 0xa0(%rsp), %rsi
movq %r15, %rdi
movq %rbx, 0x8(%rsp)
callq 0x6274
movl %eax, %r14d
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x597c
callq 0x2220
movl %r14d, 0x14(%rsp)
movslq %r14d, %rax
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x28(%r15), %rsi
leaq 0x88(%rsp), %r12
movq %r12, %rdi
callq 0x6a66
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd (%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
xorl %r13d, %r13d
leaq 0x70(%rsp), %rbp
movq %r12, %r14
movq (%r14), %r14
cmpq %r12, %r14
je 0x5b29
movslq 0x10(%r14), %rsi
movq 0x40(%r15), %rax
movq 0x48(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x5d70
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rsi
movq %rbp, %rdi
callq 0x38aa
leaq 0xd0(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x38aa
movslq 0x20(%r15), %rax
movq 0xd0(%rsp), %rdi
xorpd %xmm2, %xmm2
testq %rax, %rax
jle 0x5a55
movq 0x70(%rsp), %rcx
xorl %edx, %edx
movapd 0x27d7(%rip), %xmm1     # 0x8210
movsd (%rcx,%rdx,8), %xmm0
subsd (%rdi,%rdx,8), %xmm0
andpd %xmm1, %xmm0
addsd %xmm0, %xmm2
incq %rdx
cmpq %rdx, %rax
jne 0x5a39
jmp 0x5a5a
testq %rdi, %rdi
je 0x5a69
movsd %xmm2, (%rsp)
callq 0x2220
movsd (%rsp), %xmm2
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
movsd %xmm2, (%rsp)
je 0x5a82
callq 0x2220
movsd (%rsp), %xmm2
ucomisd 0x30(%rsp), %xmm2
jae 0x5ad5
movq %r13, 0x18(%rsp)
movq %r15, %r13
movq %r12, %r15
movq %rbp, %r12
movl 0x10(%r14), %ebp
movl $0x20, %edi
callq 0x2240
movl %ebp, 0x10(%rax)
movsd (%rsp), %xmm0
movsd %xmm0, 0x18(%rax)
movq %rax, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x2060
incq 0x10(%rbx)
movq %r12, %rbp
movq %r15, %r12
movq %r13, %r15
movq 0x18(%rsp), %r13
incl %r13d
cmpl 0x10(%r15), %r13d
jb 0x59bd
movb $0x1, %r12b
leaq 0x88(%rsp), %r14
movq (%r14), %rdi
cmpq %r14, %rdi
je 0x5b05
movq (%rdi), %r15
callq 0x2220
movq %r15, %rdi
cmpq %r14, %r15
jne 0x5af5
movq (%rbx), %rdi
cmpq %rbx, %rdi
sete %al
orb %al, %r12b
testb $0x1, %r12b
jne 0x5b52
movq (%rdi), %r14
callq 0x2220
movq %r14, %rdi
cmpq %rbx, %r14
jne 0x5b17
jmp 0x5b52
movl 0x14(%r15), %eax
cmpl $0x2, %eax
jae 0x5b67
leaq 0x88(%rsp), %r14
movq (%r14), %rdi
cmpq %r14, %rdi
je 0x5b52
movq (%rdi), %r15
callq 0x2220
movq %r15, %rdi
cmpq %r14, %r15
jne 0x5b42
movq %rbx, %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x24(%r15), %ecx
movl $0x1, %r9d
movq $0x0, 0x28(%rsp)
leaq 0x40(%rsp), %rbp
movl $0x1, %r10d
movl 0x14(%rsp), %r8d
testl %ecx, %ecx
je 0x5d4e
xorl %r14d, %r14d
movl %r10d, 0x24(%rsp)
movl %r8d, %ecx
xorl %r14d, %ecx
jle 0x5d30
xorl %edx, %edx
movl %ecx, %esi
movl %ecx, %edi
andl $0x1, %edi
addl %edi, %edx
shrl %esi
cmpl $0x1, %ecx
movl %esi, %ecx
ja 0x5baa
cmpl %r10d, %edx
jne 0x5d30
movl %r9d, 0x18(%rsp)
leaq (%r14,%r14,2), %rsi
shlq $0x3, %rsi
addq 0x28(%r15), %rsi
movq %rbp, %rdi
callq 0x6a66
movq %rbp, %r12
movq (%r12), %r12
cmpq %rbp, %r12
je 0x5cf4
movslq 0x10(%r12), %rsi
movq 0x40(%r15), %rax
movq 0x48(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x5d62
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x58(%rsp), %rdi
callq 0x38aa
leaq 0xb8(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x38aa
movslq 0x20(%r15), %rax
movq 0xb8(%rsp), %rdi
xorpd %xmm2, %xmm2
testq %rax, %rax
jle 0x5c7b
movq 0x58(%rsp), %rcx
xorl %edx, %edx
movapd 0x25b1(%rip), %xmm1     # 0x8210
movsd (%rcx,%rdx,8), %xmm0
subsd (%rdi,%rdx,8), %xmm0
andpd %xmm1, %xmm0
addsd %xmm0, %xmm2
incq %rdx
cmpq %rdx, %rax
jne 0x5c5f
jmp 0x5c80
testq %rdi, %rdi
je 0x5c8f
movsd %xmm2, (%rsp)
callq 0x2220
movsd (%rsp), %xmm2
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
movsd %xmm2, (%rsp)
je 0x5ca8
callq 0x2220
movsd (%rsp), %xmm2
ucomisd 0x30(%rsp), %xmm2
jae 0x5ce0
movl 0x10(%r12), %ebp
movl $0x20, %edi
callq 0x2240
movl %ebp, 0x10(%rax)
movsd (%rsp), %xmm0
movsd %xmm0, 0x18(%rax)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2060
incq 0x10(%rbx)
leaq 0x40(%rsp), %rbp
incl %r13d
cmpl 0x10(%r15), %r13d
jb 0x5bdf
movb $0x1, %al
movq %rax, 0x28(%rsp)
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5d18
movq (%rdi), %rbp
callq 0x2220
movq %rbp, %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rbp
leaq 0x40(%rsp), %rbp
jne 0x5cfe
cmpq %rbp, %r12
jne 0x5d58
movl 0x14(%r15), %eax
movl 0x14(%rsp), %r8d
movl 0x18(%rsp), %r9d
movl 0x24(%rsp), %r10d
incl %r9d
cmpl %eax, %r9d
jae 0x5ae2
incq %r14
movl 0x24(%r15), %ecx
cmpq %rcx, %r14
jb 0x5b9a
jmp 0x5d50
xorl %ecx, %ecx
incl %r10d
jmp 0x5b8a
movq 0x28(%rsp), %r12
jmp 0x5ae5
leaq 0x25fc(%rip), %rdi      # 0x8365
xorl %eax, %eax
callq 0x2320
leaq 0x25ee(%rip), %rdi      # 0x8365
xorl %eax, %eax
callq 0x2320
jmp 0x5d9b
movq %rax, %r14
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x5e17
callq 0x2220
jmp 0x5e17
movq %rax, %r14
jmp 0x5e1c
jmp 0x5dbc
jmp 0x5dbc
jmp 0x5dd7
jmp 0x5dbc
movq %rax, %r14
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x5df7
callq 0x2220
jmp 0x5df7
movq %rax, %r14
jmp 0x5df7
movq %rax, %r14
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x5dda
callq 0x2220
jmp 0x5dda
jmp 0x5dd7
movq %rax, %r14
leaq 0x40(%rsp), %r15
movq (%r15), %rdi
cmpq %r15, %rdi
je 0x5df7
movq (%rdi), %r12
callq 0x2220
movq %r12, %rdi
cmpq %r15, %r12
jne 0x5de7
leaq 0x88(%rsp), %r15
movq (%r15), %rdi
cmpq %r15, %rdi
je 0x5e17
movq (%rdi), %r12
callq 0x2220
movq %r12, %rdi
cmpq %r15, %r12
jne 0x5e07
movq 0x8(%rsp), %rbx
movq (%rbx), %rdi
cmpq %rbx, %rdi
je 0x5e34
movq (%rdi), %r15
callq 0x2220
movq %r15, %rdi
cmpq %rbx, %r15
jne 0x5e24
movq %r14, %rdi
callq 0x2400