// 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>::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 $0x1438, %rsp           # imm = 0x1438
movl %r9d, %ebp
movl %ecx, %r15d
movq %rdx, %r14
movl %esi, %ebx
movq %rdi, %r13
movl 0x1478(%rsp), %r12d
movl 0x1470(%rsp), %eax
movq 0x1480(%rsp), %rsi
movl %ebx, (%rdi)
movq %rdx, 0x8(%rdi)
movl %ecx, 0x10(%rdi)
movl %r8d, (%rsp)
movl %r8d, 0x14(%rdi)
movl %r9d, 0x18(%rdi)
movl %eax, 0x1c(%rdi)
movl %r12d, 0x20(%rdi)
leaq 0x28(%rdi), %rax
movq %rax, 0x8(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x28(%rdi)
andq $0x0, 0x38(%rdi)
addq $0x40, %rdi
movq %rdi, 0x18(%rsp)
callq 0x3c74
leaq 0x58(%r13), %rax
movq %rax, 0x60(%r13)
movq %rax, 0x28(%rsp)
movq %rax, 0x58(%r13)
leaq 0x70(%r13), %rax
movq %rax, 0x20(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x68(%r13)
movupd %xmm0, 0x78(%r13)
movq 0x722c(%rip), %rax      # 0xafc0
movq (%rax), %rdi
subq $0x8, %rsp
leaq 0x35f4(%rip), %rsi      # 0x7396
movl %ebx, %edx
movq %r14, %rcx
movl %r15d, %r8d
movl 0x8(%rsp), %r9d
xorl %eax, %eax
pushq %r12
movl 0x1480(%rsp), %r10d
movq %r10, %r15
pushq %r10
movq %rbp, 0x50(%rsp)
pushq %rbp
callq 0x2280
addq $0x20, %rsp
leaq 0x48(%rsp), %rdi
callq 0x21a0
movl %ebx, %eax
cvtsi2sd %rax, %xmm0
callq 0x2190
cvttsd2si %xmm0, %rax
movl %eax, 0x24(%r13)
movl %r15d, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, (%rsp)
leaq 0xb0(%rsp), %r15
movl %ebx, 0x14(%rsp)
subl $0x1, %ebx
jb 0x3e3a
movl 0x24(%r13), %ecx
movq %r15, %rdi
movl %r12d, %esi
movsd (%rsp), %xmm0
movl %r14d, %edx
callq 0x4d18
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x4e6a
movq %r15, %rdi
callq 0x4e76
jmp 0x3e07
xorl %ebx, %ebx
cmpl 0x24(%r13), %ebx
jae 0x3e74
movq %r15, 0xb8(%rsp)
movq %r15, 0xb0(%rsp)
andq $0x0, 0xc0(%rsp)
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x4e90
movq %r15, %rdi
callq 0x57ee
incl %ebx
jmp 0x3e3c
leaq 0xb0(%rsp), %rdi
callq 0x4ebc
leaq 0xb0(%rsp), %rdi
callq 0x2250
xorl %esi, %esi
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
divl %ecx
cmpl $0x1, %edx
adcl $0x0, %edx
leaq 0x88(%rsp), %r14
movq %rdx, (%r14)
movabsq $0x100000000, %rax      # imm = 0x100000000
leaq 0x90(%rsp), %r12
movq %rax, (%r12)
leaq 0x50(%rsp), %r15
leaq 0x30(%rsp), %rbx
movl %esi, (%rsp)
cmpl 0x14(%rsp), %esi
je 0x3f48
leaq 0x80(%rsp), %rax
movq %rax, 0x50(%rsp)
movq $0x1, 0x58(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%rax)
movl $0x3f800000, 0x70(%rsp) # imm = 0x3F800000
movupd %xmm0, -0x8(%rax)
xorl %ebp, %ebp
cmpl 0x24(%r13), %ebp
jae 0x3f2c
movq %r12, %rdi
movq %r14, %rsi
callq 0x4f12
testl %eax, %eax
movl %ebp, 0x30(%rsp)
setne 0x34(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x5a66
incl %ebp
jmp 0x3f01
movq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x4f1a
movq %r15, %rdi
callq 0x61f4
movl (%rsp), %esi
incl %esi
jmp 0x3eca
movl 0x38(%rsp), %r12d
xorl %ebx, %ebx
leaq 0x98(%rsp), %r14
leaq 0x50(%rsp), %r15
cmpq %rbx, %r12
je 0x3fae
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x3cce
movq %r14, %rdi
movq %rax, %rsi
callq 0x31a2
movq %r13, %rdi
movq %r14, %rsi
callq 0x4f46
movl %eax, %ebp
movq %r14, %rdi
callq 0x2f56
movslq %ebp, %rax
imulq $0x18, %rax, %rdi
movq 0x8(%rsp), %rax
addq (%rax), %rdi
movl %ebx, 0x50(%rsp)
movq %r15, %rsi
callq 0x5056
incq %rbx
jmp 0x3f5c
leaq 0x40(%rsp), %rdi
callq 0x21a0
movq 0x7019(%rip), %rdi      # 0xafd8
leaq 0x3450(%rip), %rsi      # 0x7416
callq 0x21d0
movq %rax, %rbx
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x20f0
movq %rbx, %rdi
callq 0x22e0
leaq 0x3447(%rip), %rsi      # 0x7433
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20d0
leaq 0xb0(%rsp), %rdi
callq 0x5062
addq $0x1438, %rsp           # imm = 0x1438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4068
jmp 0x4051
movq %rax, %r14
jmp 0x40a7
jmp 0x4068
movq %rax, %r14
leaq 0x98(%rsp), %rdi
callq 0x2f56
jmp 0x407c
jmp 0x4068
jmp 0x406f
movq %rax, %r14
leaq 0xb0(%rsp), %rdi
callq 0x57ee
jmp 0x4089
movq %rax, %r14
jmp 0x4089
movq %rax, %r14
leaq 0xb0(%rsp), %rdi
callq 0x4e76
jmp 0x4089
movq %rax, %r14
jmp 0x407c
jmp 0x406f
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x61f4
leaq 0xb0(%rsp), %rdi
callq 0x5062
movq 0x20(%rsp), %rdi
callq 0x5072
movq 0x28(%rsp), %rdi
callq 0x6730
movq 0x18(%rsp), %rdi
callq 0x2ede
movq 0x8(%rsp), %rdi
callq 0x5094
movq %r14, %rdi
callq 0x2380
nop