// 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>::Hypercube(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>>>>)
Hypercube(const uint32_t k, uint64_t m, uint32_t threshold, uint32_t max_probes, 
		uint32_t n_points, uint32_t w, uint32_t space_dim, std::vector<std::vector<T>> init_vectors) : 
		k(k), m(m), threshold(threshold), max_probes(max_probes), n_points(n_points), 
		w(w), space_dim(space_dim), feature_vectors(init_vectors) {
			//measure the time that it takes to initialize the hypercube
			time_t start, finish;
			fprintf(stdout, "Hypercube initialization with parameters: k = %d, m = %ld, threshold = %d"
			" max_probes = %d, npoints = %d, w = %d, spacedim = %d\n", k, m, threshold, max_probes, n_points, w, space_dim);
			time(&start);

			// we have a bit swquence of k bits, thus the size of the hypercube table will be 2^k
			n_buckets = (uint32_t)pow(2, k);

			// Initialize the hash functions of each bucket
			for (uint32_t i = 0; i < k; i++) {
				lsh::HashFunction hash_fn(space_dim, w, m, n_buckets);
				// Insert each amplified hash fn into the apropriate list
				hash_fns.push_back(hash_fn);         
			}

			// initialize the hypercube table
			for (uint32_t i = 0; i < n_buckets; i++) {
				std::list<int> current_list;
				hypercube.push_back(current_list);
			}

			// define the generator and the random distribution for the mapping
			std::random_device mch;
			std::default_random_engine generator(mch());
			std::uniform_int_distribution<int> distribution(0,1);
			
			// create the list of the f functions
			for (uint32_t i = 0; i < k; i++) {
				std::unordered_map<int,bool> current_map;
				// pre-map all the possible hash function outcomes to 0-1, so we buy time during initialization
				for (uint32_t i = 0; i < n_buckets; i++) {
					bool result = distribution(generator);
					current_map.insert({i, result});
				}
				flipped_coins.push_back(current_map);
			}

			// insert all of the points into the hypercube
			for (uint32_t i = 0; i < n_points; i++) {
				int bucket_int = hash_to_hypercube(feature_vectors.at(i));
				hypercube[bucket_int].push_back(i);
			}

			// hypercube initialization done. print the time differenct
			time(&finish);
			cout << "Initialization completed in " << difftime(finish, start) << " seconds" << endl;
		}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1448, %rsp           # imm = 0x1448
movl %r9d, %r13d
movl %ecx, %r15d
movq %rdx, %rbp
movl %esi, %ebx
movq %rdi, %r14
movl 0x1488(%rsp), %r12d
movl 0x1480(%rsp), %eax
movq 0x1490(%rsp), %rsi
movl %ebx, (%rdi)
movq %rdx, 0x8(%rdi)
movl %ecx, 0x10(%rdi)
movl %r8d, 0x8(%rsp)
movl %r8d, 0x14(%rdi)
movl %r9d, 0x18(%rdi)
movl %eax, 0x1c(%rdi)
movl %r12d, 0x20(%rdi)
leaq 0x28(%rdi), %rax
movq %rax, 0x18(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x28(%rdi)
movq $0x0, 0x38(%rdi)
addq $0x40, %rdi
movq %rdi, 0x38(%rsp)
callq 0x47dc
leaq 0x58(%r14), %rax
movq %rax, 0x60(%r14)
movq %rax, 0x28(%rsp)
movq %rax, 0x58(%r14)
leaq 0x70(%r14), %rax
movq %rax, 0x20(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x68(%r14)
movupd %xmm0, 0x78(%r14)
movq 0x769e(%rip), %rax      # 0xbfb8
movq (%rax), %rdi
subq $0x8, %rsp
leaq 0x3ae8(%rip), %rsi      # 0x8410
movl %ebx, %edx
movq %rbp, %rcx
movl %r15d, %r8d
movl 0x10(%rsp), %r9d
xorl %eax, %eax
pushq %r12
movl 0x1490(%rsp), %r15d
pushq %r15
movq %r13, 0x58(%rsp)
pushq %r13
callq 0x22f0
addq $0x20, %rsp
leaq 0x60(%rsp), %rdi
callq 0x2200
movl %ebx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
callq 0x21f0
cvttsd2si %xmm0, %rax
movq %r14, 0x8(%rsp)
movl %eax, 0x24(%r14)
movl %ebx, 0x14(%rsp)
testl %ebx, %ebx
je 0x49ef
movq 0x8(%rsp), %rax
leaq 0x68(%rax), %r14
movl %r15d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x48(%rsp)
leaq 0xc0(%rsp), %rbx
movl 0x14(%rsp), %r15d
movq 0x28(%rsp), %r13
movq 0x8(%rsp), %rax
movl 0x24(%rax), %ecx
movq %rbx, %rdi
movl %r12d, %esi
movsd 0x48(%rsp), %xmm0
movl %ebp, %edx
callq 0x5f5a
movq %r13, %rdi
movq %rbx, %rsi
callq 0x675e
movq %rax, %rdi
movq %r13, %rsi
callq 0x2060
incq (%r14)
movq %rbx, %rdi
callq 0x6110
decl %r15d
jne 0x49ae
movq 0x8(%rsp), %r15
cmpl $0x0, 0x24(%r15)
je 0x4a53
xorl %ebp, %ebp
leaq 0xc0(%rsp), %rbx
movq %rbx, 0xc8(%rsp)
movq %rbx, 0xc0(%rsp)
movq $0x0, 0xd0(%rsp)
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x6134
movq 0xc0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x4a4b
movq (%rdi), %r14
callq 0x2220
movq %r14, %rdi
cmpq %rbx, %r14
jne 0x4a3b
incl %ebp
cmpl 0x24(%r15), %ebp
jb 0x4a05
leaq 0xc0(%rsp), %rdi
callq 0x6160
leaq 0xc0(%rsp), %rdi
callq 0x22c0
movl 0x14(%rsp), %esi
movl %eax, %ecx
leaq (%rcx,%rcx,2), %rcx
shrq $0x20, %rcx
movl %eax, %edx
subl %ecx, %edx
shrl %edx
addl %ecx, %edx
shrl $0x1e, %edx
movl %edx, %ecx
shll $0x1f, %ecx
orl %edx, %ecx
leal (%rax,%rcx), %edx
cmpl $0x1, %edx
adcl %eax, %ecx
movq %rcx, 0x50(%rsp)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x68(%rsp)
testl %esi, %esi
je 0x4b64
xorl %r14d, %r14d
leaq 0x88(%rsp), %r12
leaq 0x50(%rsp), %rbp
leaq 0x68(%rsp), %rbx
leaq 0x30(%rsp), %r15
leaq 0xb8(%rsp), %rax
movq %rax, 0x88(%rsp)
movq $0x1, 0x90(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%rax)
movl $0x3f800000, 0xa8(%rsp) # imm = 0x3F800000
movupd %xmm0, -0x8(%rax)
movq 0x8(%rsp), %rax
cmpl $0x0, 0x24(%rax)
je 0x4b41
xorl %r13d, %r13d
movq %rbx, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x6b34
testl %eax, %eax
movl %r13d, 0x30(%rsp)
setne 0x34(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x6cbc
incl %r13d
movq 0x8(%rsp), %rax
cmpl 0x24(%rax), %r13d
jb 0x4b0e
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x61ca
movq %r12, %rdi
callq 0x73a0
incl %r14d
cmpl 0x14(%rsp), %r14d
jne 0x4acb
movq 0x40(%rsp), %rax
testl %eax, %eax
je 0x4c19
movl %eax, %r15d
xorl %ebp, %ebp
leaq 0x70(%rsp), %r12
xorl %r14d, %r14d
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rdx
cmpq %r14, %rdx
jbe 0x4cb3
addq %rbp, %rsi
movq %r12, %rdi
callq 0x3860
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x6232
movl %eax, %ebx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x4bd2
callq 0x2220
movq 0x18(%rsp), %rax
movq (%rax), %r13
movl $0x18, %edi
callq 0x2240
movslq %ebx, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (,%rcx,8), %rbx
addq %r13, %rbx
movl %r14d, 0x10(%rax)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2060
incq 0x10(%rbx)
incq %r14
addq $0x18, %rbp
cmpl %r14d, %r15d
jne 0x4b7e
leaq 0x58(%rsp), %rdi
callq 0x2200
movq 0x73ae(%rip), %rdi      # 0xbfd8
leaq 0x385f(%rip), %rsi      # 0x8490
movl $0x1c, %edx
callq 0x2260
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x2110
movq 0x7387(%rip), %rdi      # 0xbfd8
callq 0x2350
movq %rax, %rbx
leaq 0x384d(%rip), %rsi      # 0x84ad
movl $0x8, %edx
movq %rax, %rdi
callq 0x2260
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2180
leaq 0xc0(%rsp), %rdi
callq 0x2210
addq $0x1448, %rsp           # imm = 0x1448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x36cb(%rip), %rdi      # 0x8385
movq %r14, %rsi
xorl %eax, %eax
callq 0x2320
jmp 0x4d7e
jmp 0x4cf1
jmp 0x4d18
movq %rax, %r14
jmp 0x4d6c
jmp 0x4cf1
jmp 0x4d31
jmp 0x4cf1
jmp 0x4cf1
movq %rax, %r14
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x4d41
callq 0x2220
jmp 0x4d41
movq %rax, %r14
jmp 0x4d41
movq %rax, %r14
movq 0xc0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x4d4e
movq (%rdi), %r15
callq 0x2220
movq %r15, %rdi
cmpq %rbx, %r15
jne 0x4d06
jmp 0x4d4e
movq %rax, %r14
jmp 0x4d4e
movq %rax, %r14
leaq 0xc0(%rsp), %rdi
callq 0x6110
jmp 0x4d4e
jmp 0x4d31
movq %rax, %r14
leaq 0x88(%rsp), %rdi
callq 0x73a0
leaq 0xc0(%rsp), %rdi
callq 0x2210
movq 0x20(%rsp), %rdi
callq 0x63c8
movq 0x28(%rsp), %rdi
callq 0x7892
movq 0x38(%rsp), %rdi
callq 0x3578
movq 0x18(%rsp), %rdi
callq 0x6402
movq %r14, %rdi
callq 0x2400
movq %rax, %rdi
callq 0x35b7