// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
movq %rdi, 0x8(%rdi)
movq %rdi, (%rdi)
movq $0x0, 0x10(%rdi)
leaq 0x88(%rsp), %rdi
movq %rdx, 0x30(%rsp)
movq %rdx, %rsi
movq %rbx, 0x8(%rsp)
callq 0x3860
leaq 0x88(%rsp), %rsi
movq %r15, %rdi
callq 0x6232
movl %eax, %ebx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x5926
callq 0x2220
movl %ebx, 0x1c(%rsp)
movslq %ebx, %rax
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x28(%r15), %rsi
leaq 0x38(%rsp), %r12
movq %r12, %rdi
callq 0x69aa
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %ebp, %ebp
leaq 0x70(%rsp), %r14
movq %r12, %rbx
xorl %r13d, %r13d
movq (%rbx), %rbx
cmpq %r12, %rbx
je 0x5a8f
movslq 0x10(%rbx), %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 0x5d3f
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rsi
movq %r14, %rdi
callq 0x3860
leaq 0xd0(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x3860
movslq 0x20(%r15), %rax
testq %rax, %rax
jle 0x59fe
movq 0x70(%rsp), %rcx
xorpd %xmm2, %xmm2
movq 0xd0(%rsp), %rdx
xorl %esi, %esi
movapd 0x284e(%rip), %xmm1     # 0x8230
movsd (%rcx,%rsi,8), %xmm0
subsd (%rdx,%rsi,8), %xmm0
andpd %xmm1, %xmm0
addsd %xmm0, %xmm2
incq %rsi
cmpq %rsi, %rax
jne 0x59e2
jmp 0x5a02
xorpd %xmm2, %xmm2
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
movsd %xmm2, 0x10(%rsp)
je 0x5a20
callq 0x2220
movsd 0x10(%rsp), %xmm2
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x5a35
callq 0x2220
movsd 0x10(%rsp), %xmm2
ucomisd 0x28(%rsp), %xmm2
jae 0x5a79
movq %r14, %r12
movl 0x10(%rbx), %r14d
movl $0x20, %edi
callq 0x2240
movl %r14d, 0x10(%rax)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x18(%rax)
movq %rax, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x2060
incq 0x10(%r14)
movq %r12, %r14
leaq 0x38(%rsp), %r12
incl %ebp
movl 0x10(%r15), %eax
cmpl %eax, %ebp
setae %cl
orb %cl, %r13b
cmpl %eax, %ebp
jb 0x5966
leaq 0x38(%rsp), %rax
cmpq %rax, %rbx
jne 0x5cd2
cmpl $0x2, 0x14(%r15)
jae 0x5acd
movq 0x38(%rsp), %rdi
leaq 0x38(%rsp), %r14
cmpq %r14, %rdi
je 0x5ac3
movq (%rdi), %rbx
callq 0x2220
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0x5ab3
movq 0x8(%rsp), %rax
jmp 0x5d1f
movl $0x1, %r8d
leaq 0xb8(%rsp), %rbx
movl $0x1, %r9d
movl 0x1c(%rsp), %edi
cmpl $0x0, 0x24(%r15)
setne %r10b
je 0x5cc5
xorl %r11d, %r11d
movl %r9d, 0x20(%rsp)
movl %edi, %ecx
xorl %eax, %eax
xorl %r11d, %ecx
jle 0x5b17
movl %ecx, %edx
movl %ecx, %esi
andl $0x1, %esi
addl %esi, %eax
shrl %edx
cmpl $0x1, %ecx
movl %edx, %ecx
ja 0x5b07
cmpl %r9d, %eax
jne 0x5ca3
movb %r10b, 0x7(%rsp)
movl %r8d, 0x24(%rsp)
movq %r11, 0x50(%rsp)
leaq (%r11,%r11,2), %rsi
shlq $0x3, %rsi
addq 0x28(%r15), %rsi
movq %rbx, %rdi
callq 0x69aa
movq %rbx, %r12
movq (%r12), %r12
cmpq %rbx, %r12
je 0x5c69
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 0x5d31
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x58(%rsp), %rdi
callq 0x3860
leaq 0xa0(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x3860
movslq 0x20(%r15), %rax
testq %rax, %rax
jle 0x5be2
movq 0x58(%rsp), %rcx
xorpd %xmm2, %xmm2
movq 0xa0(%rsp), %rdx
xorl %esi, %esi
movapd 0x266a(%rip), %xmm1     # 0x8230
movsd (%rcx,%rsi,8), %xmm0
subsd (%rdx,%rsi,8), %xmm0
andpd %xmm1, %xmm0
addsd %xmm0, %xmm2
incq %rsi
cmpq %rsi, %rax
jne 0x5bc6
jmp 0x5be6
xorpd %xmm2, %xmm2
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
movsd %xmm2, 0x10(%rsp)
je 0x5c04
callq 0x2220
movsd 0x10(%rsp), %xmm2
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x5c19
callq 0x2220
movsd 0x10(%rsp), %xmm2
ucomisd 0x28(%rsp), %xmm2
jae 0x5c53
movl 0x10(%r12), %r14d
movl $0x20, %edi
callq 0x2240
movl %r14d, 0x10(%rax)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x18(%rax)
movq %rax, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x2060
incq 0x10(%r14)
incl %ebp
movl 0x10(%r15), %eax
cmpl %eax, %ebp
setae %cl
orb %cl, %r13b
cmpl %eax, %ebp
jb 0x5b46
movq 0xb8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x5c86
movq (%rdi), %r14
callq 0x2220
movq %r14, %rdi
cmpq %rbx, %r14
jne 0x5c76
cmpq %rbx, %r12
movl 0x1c(%rsp), %edi
movl 0x24(%rsp), %r8d
movl 0x20(%rsp), %r9d
movb 0x7(%rsp), %r10b
movq 0x50(%rsp), %r11
jne 0x5cc5
incl %r8d
cmpl 0x14(%r15), %r8d
jae 0x5cc2
incq %r11
movl 0x24(%r15), %eax
cmpq %rax, %r11
setb %r10b
jb 0x5afc
jmp 0x5cc5
movb $0x1, %r13b
incl %r9d
testb $0x1, %r10b
je 0x5ae5
movq 0x38(%rsp), %rdi
leaq 0x38(%rsp), %r14
cmpq %r14, %rdi
je 0x5cf1
movq (%rdi), %rbx
callq 0x2220
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0x5ce1
movq 0x8(%rsp), %rax
movq (%rax), %rdi
cmpq %rax, %rdi
sete %cl
orb %cl, %r13b
testb $0x1, %r13b
jne 0x5d1f
movq (%rdi), %rbx
callq 0x2220
movq %rbx, %rdi
cmpq 0x8(%rsp), %rbx
movq 0x8(%rsp), %rax
jne 0x5d08
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x264d(%rip), %rdi      # 0x8385
xorl %eax, %eax
callq 0x2320
leaq 0x263f(%rip), %rdi      # 0x8385
xorl %eax, %eax
callq 0x2320
movq %rax, %r14
jmp 0x5dec
movq %rax, %r14
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x5dec
callq 0x2220
jmp 0x5dec
movq %rax, %r14
jmp 0x5df1
jmp 0x5d8f
jmp 0x5d8f
movq %rax, %r14
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x5dcf
callq 0x2220
jmp 0x5dcf
jmp 0x5d8f
movq %rax, %r14
jmp 0x5dcf
jmp 0x5dac
jmp 0x5dac
movq %rax, %r14
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x5daf
callq 0x2220
jmp 0x5daf
movq %rax, %r14
leaq 0xb8(%rsp), %rbx
movq (%rbx), %rdi
cmpq %rbx, %rdi
je 0x5dcf
movq (%rdi), %r15
callq 0x2220
movq %r15, %rdi
cmpq %rbx, %r15
jne 0x5dbf
leaq 0x38(%rsp), %rbx
movq (%rbx), %rdi
cmpq %rbx, %rdi
je 0x5dec
movq (%rdi), %r15
callq 0x2220
movq %r15, %rdi
cmpq %rbx, %r15
jne 0x5ddc
movq 0x8(%rsp), %rbx
movq (%rbx), %rdi
cmpq %rbx, %rdi
je 0x5e0b
movq (%rdi), %rbx
callq 0x2220
movq %rbx, %rdi
cmpq 0x8(%rsp), %rbx
jne 0x5df9
movq %r14, %rdi
callq 0x2400
nop