// File: /workspace/github_cpp_makefile_star2_O2/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 $0xf8, %rsp
movl %ecx, %ebp
movsd %xmm0, 0x8(%rsp)
movq %rsi, %r15
movq %rdi, 0x8(%rdi)
movq %rdi, (%rdi)
movq %rdi, (%rsp)
andq $0x0, 0x10(%rdi)
leaq 0x80(%rsp), %rdi
movq %rdx, 0x30(%rsp)
movq %rdx, %rsi
callq 0x31a2
leaq 0x80(%rsp), %rsi
movq %r15, %rdi
callq 0x4f46
movl %eax, %ebx
leaq 0x80(%rsp), %rdi
callq 0x2f56
movl %ebx, 0x14(%rsp)
movslq %ebx, %rax
imulq $0x18, %rax, %rsi
addq 0x28(%r15), %rsi
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
callq 0x56c8
leaq 0x40(%r15), %rax
movq %rax, 0x38(%rsp)
cvtsi2sd %ebp, %xmm0
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %r14d, %r14d
leaq 0xe0(%rsp), %r13
leaq 0xc8(%rsp), %rbp
movq %rbx, %r12
movq (%r12), %r12
cmpq %rbx, %r12
je 0x48b0
movslq 0x10(%r12), %rsi
movq 0x38(%rsp), %rdi
callq 0x3cce
movq %r13, %rdi
movq %rax, %rsi
callq 0x31a2
movq %rbp, %rdi
movq 0x30(%rsp), %rsi
callq 0x31a2
movl 0x20(%r15), %edx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4bd7
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rdi
callq 0x2f56
movq %r13, %rdi
callq 0x2f56
movl 0x10(%r12), %eax
movl %eax, 0x40(%rsp)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
ucomisd 0x28(%rsp), %xmm0
jae 0x48a1
movq (%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x4c0e
incl %r14d
cmpl 0x10(%r15), %r14d
jb 0x481d
jmp 0x48b7
cmpl $0x2, 0x14(%r15)
jae 0x48d7
leaq 0x58(%rsp), %rdi
callq 0x57ee
movq (%rsp), %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rcx
movq $0x0, 0x20(%rsp)
leaq 0xb0(%rsp), %rbp
leaq 0x98(%rsp), %rbx
movl %ecx, 0x18(%rsp)
movl 0x14(%rsp), %r12d
xorl %r13d, %r13d
movl 0x24(%r15), %eax
cmpq %rax, %r13
jae 0x4a08
movl %ecx, 0x1c(%rsp)
movl %r13d, %edi
movl %r12d, %esi
callq 0x676d
cmpl 0x18(%rsp), %eax
jne 0x49f0
imulq $0x18, %r13, %rsi
addq 0x28(%r15), %rsi
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x56c8
movq (%r12), %r12
leaq 0x40(%rsp), %rax
cmpq %rax, %r12
je 0x49d7
movslq 0x10(%r12), %rsi
movq 0x38(%rsp), %rdi
callq 0x3cce
movq %rbp, %rdi
movq %rax, %rsi
callq 0x31a2
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
callq 0x31a2
movl 0x20(%r15), %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x4bd7
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x2f56
movq %rbp, %rdi
callq 0x2f56
movl 0x10(%r12), %eax
movl %eax, 0x70(%rsp)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
ucomisd 0x28(%rsp), %xmm0
jae 0x49c3
movq (%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x4c0e
incl %r14d
cmpl 0x10(%r15), %r14d
jb 0x493a
movb $0x1, %al
movq %rax, 0x20(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x57ee
leaq 0x40(%rsp), %rax
cmpq %rax, %r12
jne 0x4a11
movl 0x14(%rsp), %r12d
movl 0x1c(%rsp), %ecx
incl %ecx
incq %r13
cmpl 0x14(%r15), %ecx
jb 0x48ff
jmp 0x48b7
incl 0x18(%rsp)
jmp 0x48fc
leaq 0x58(%rsp), %rdi
callq 0x57ee
testb $0x1, 0x20(%rsp)
jne 0x48c1
movq (%rsp), %rdi
callq 0x4af4
jmp 0x48c1
jmp 0x4a48
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x2f56
jmp 0x4ab7
movq %rax, %rbx
jmp 0x4ab7
jmp 0x4a77
jmp 0x4a77
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x2f56
jmp 0x4a66
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x2f56
jmp 0x4aad
jmp 0x4aa0
movq %rax, %rbx
jmp 0x4aad
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x2f56
jmp 0x4a91
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x2f56
jmp 0x4aa3
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x57ee
leaq 0x58(%rsp), %rdi
callq 0x57ee
movq (%rsp), %rdi
callq 0x4af4
movq %rbx, %rdi
callq 0x2380