// 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>::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 0x4828
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 0x7652(%rip), %rax      # 0xbfb8
movq (%rax), %rdi
subq $0x8, %rsp
leaq 0x3a7c(%rip), %rsi      # 0x83f0
movl %ebx, %edx
movq %rbp, %rcx
movl %r15d, %r8d
movl 0x10(%rsp), %r9d
xorl %eax, %eax
pushq %r12
movl 0x1490(%rsp), %r10d
pushq %r10
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
movl %eax, 0x24(%r14)
movl %ebx, 0x14(%rsp)
testl %ebx, %ebx
movq %r14, %r15
movq %r14, 0x8(%rsp)
je 0x4a48
leaq 0x68(%r15), %r14
movl 0x1480(%rsp), %eax
movl %eax, %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 0x5f88
movq %r13, %rdi
movq %rbx, %rsi
callq 0x67a8
movq %rax, %rdi
movq %r13, %rsi
callq 0x2060
incq (%r14)
movq %rbx, %rdi
callq 0x6152
decl %r15d
jne 0x49fe
movq 0x8(%rsp), %r15
movl 0x24(%r15), %eax
testl %eax, %eax
je 0x4aa4
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 0x6176
movq 0xc0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x4a9c
movq (%rdi), %r14
callq 0x2220
movq %r14, %rdi
cmpq %rbx, %r14
jne 0x4a8c
incl %ebp
cmpl 0x24(%r15), %ebp
jb 0x4a56
leaq 0xc0(%rsp), %rdi
callq 0x61a2
leaq 0xc0(%rsp), %rdi
callq 0x22c0
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)
cmpl $0x0, 0x14(%rsp)
je 0x4bb4
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 0x4b91
xorl %r13d, %r13d
movq %rbx, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x6b6c
testl %eax, %eax
movl %r13d, 0x30(%rsp)
setne 0x34(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x6cf4
incl %r13d
movq 0x8(%rsp), %rax
cmpl 0x24(%rax), %r13d
jb 0x4b5e
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x620c
movq %r12, %rdi
callq 0x736a
incl %r14d
cmpl 0x14(%rsp), %r14d
jne 0x4b1b
movq 0x40(%rsp), %rax
testl %eax, %eax
je 0x4c68
movl %eax, %r15d
xorl %r14d, %r14d
movabsq $-0x5555555555555555, %rbp # imm = 0xAAAAAAAAAAAAAAAB
leaq 0x70(%rsp), %r12
movq 0x8(%rsp), %rcx
movq 0x40(%rcx), %rax
movq 0x48(%rcx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %rbp, %rdx
cmpq %r14, %rdx
jbe 0x4d02
leaq (%r14,%r14,2), %rcx
leaq (%rax,%rcx,8), %rsi
movq %r12, %rdi
callq 0x38aa
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x6274
movl %eax, %ebx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x4c25
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
cmpq %r15, %r14
jne 0x4bd6
leaq 0x58(%rsp), %rdi
callq 0x2200
movq 0x735f(%rip), %rdi      # 0xbfd8
leaq 0x37f0(%rip), %rsi      # 0x8470
movl $0x1c, %edx
callq 0x2260
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x2110
movq 0x7338(%rip), %rdi      # 0xbfd8
callq 0x2350
movq %rax, %rbx
leaq 0x37de(%rip), %rsi      # 0x848d
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 0x365c(%rip), %rdi      # 0x8365
movq %r14, %rsi
xorl %eax, %eax
callq 0x2320
jmp 0x4dcd
jmp 0x4d40
jmp 0x4d67
movq %rax, %r14
jmp 0x4dbb
jmp 0x4d40
jmp 0x4d80
jmp 0x4d40
jmp 0x4d40
movq %rax, %r14
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x4d90
callq 0x2220
jmp 0x4d90
movq %rax, %r14
jmp 0x4d90
movq %rax, %r14
movq 0xc0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x4d9d
movq (%rdi), %r15
callq 0x2220
movq %r15, %rdi
cmpq %rbx, %r15
jne 0x4d55
jmp 0x4d9d
movq %rax, %r14
jmp 0x4d9d
movq %rax, %r14
leaq 0xc0(%rsp), %rdi
callq 0x6152
jmp 0x4d9d
jmp 0x4d80
movq %rax, %r14
leaq 0x88(%rsp), %rdi
callq 0x736a
leaq 0xc0(%rsp), %rdi
callq 0x2210
movq 0x20(%rsp), %rdi
callq 0x63f6
movq 0x28(%rsp), %rdi
callq 0x786c
movq 0x38(%rsp), %rdi
callq 0x35c6
movq 0x18(%rsp), %rdi
callq 0x6436
movq %r14, %rdi
callq 0x2400
movq %rax, %rdi
callq 0x360b
nop