// File: /workspace/github_cpp_makefile_star2_O2/rtackx[P]ComSim/community.cpp
// Function: Community::aggregate(Graph*&, std::unordered_set<unsigned int, std::hash<unsigned int>, std::equal_to<unsigned int>, std::allocator<unsigned int>>&)
void Community::aggregate(Graph*& graph_projection, unordered_set<unsigned int>& list_remaining_nodes)
{
	Node* node;
	unsigned int index_com_similar;
	float max_similarity;
	unordered_map<unsigned int, float> map_similar_community;
	unordered_map<unsigned int, vector<unsigned int>> map_community_tmp;
	unordered_map<unsigned int, vector<unsigned int>> map_best_similarity;
	vector<unsigned int> list_similarity;
	
	for(auto& index : list_remaining_nodes)
	{
		node = graph_projection->list_nodes[index];

		max_similarity = 0.0;
		for(auto& neighbor : node->neighbor_weights)
		{
			if(map_community.find(neighbor.first->index) != map_community.end())
			{	
				for(auto& index_com : map_community[neighbor.first->index])
				{
					map_similar_community.emplace(make_pair(index_com, 0.0));
					map_similar_community[index_com] += neighbor.second;
				}
			}
			else
			{
				if(neighbor.second >= max_similarity)
				{
					if(neighbor.second > max_similarity)
						list_similarity.clear();

					max_similarity = neighbor.second;
					list_similarity.push_back(neighbor.first->index);
				}
			}
		}

		max_similarity = 0.0;
		index_com_similar = -1;

		for(auto& e : map_similar_community)
		{
			if(e.second > max_similarity)
			{
				max_similarity = e.second;
				index_com_similar = e.first;
			}
		}
		map_similar_community.clear();
		
		if(index_com_similar == -1)
			map_best_similarity[list_similarity[rand() % list_similarity.size()]].push_back(index);
		else
		{
			map_community_tmp[index].push_back(index_com_similar);
			
			// Add neighors of "index" into community
			if(map_best_similarity.find(index) != map_best_similarity.end())
			{
				for(auto& index_neighbor : map_best_similarity[index])
					map_community_tmp[index_neighbor].push_back(index_com_similar);
			}
		}
	}
	
	// Saving modification
	for(auto& e : map_community_tmp)
	{
		for(auto& index_com : e.second)
			map_community[e.first].push_back(index_com);

		list_remaining_nodes.erase(e.first);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, 0x38(%rsp)
movq %rdi, %r14
leaq 0x100(%rsp), %rax
movq %rax, -0x30(%rax)
pushq $0x1
popq %rcx
movq %rcx, -0x28(%rax)
leaq 0xe0(%rsp), %rsi
xorps %xmm0, %xmm0
movups %xmm0, (%rsi)
movl $0x3f800000, %eax       # imm = 0x3F800000
movl %eax, 0x10(%rsi)
movups %xmm0, 0x18(%rsi)
leaq 0xc8(%rsp), %rsi
movq %rsi, -0x30(%rsi)
movq %rcx, -0x28(%rsi)
leaq 0xa8(%rsp), %rbp
movups %xmm0, (%rbp)
movl %eax, 0x10(%rbp)
movups %xmm0, 0x18(%rbp)
leaq 0x90(%rsp), %rsi
movq %rsi, -0x30(%rsi)
movq %rcx, -0x28(%rsi)
movups %xmm0, -0x20(%rsi)
movl %eax, -0x10(%rsi)
movups %xmm0, -0x8(%rsi)
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq %rdx, 0x30(%rsp)
leaq 0x10(%rdx), %rax
movq %rax, 0x28(%rsp)
addq $0x10, %r14
leaq 0xd0(%rsp), %r13
leaq 0x50(%rsp), %rbx
movq %r14, 0x48(%rsp)
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x75ff
leaq 0x8(%rcx), %rax
movq %rax, 0x40(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x28(%rsp)
movl 0x8(%rcx), %ecx
movq (%rax,%rcx,8), %r12
addq $0x40, %r12
xorps %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
movq (%r12), %r12
testq %r12, %r12
je 0x7511
movq 0x8(%r12), %rsi
movq %r14, %rdi
callq 0x8510
testq %rax, %rax
je 0x74cc
movq 0x8(%r12), %rsi
movq %r14, %rdi
callq 0x80bc
movq %rbp, %r14
movq (%rax), %r15
movq 0x8(%rax), %rbp
cmpq %rbp, %r15
je 0x74bf
movl (%r15), %eax
movl %eax, 0x50(%rsp)
andq $0x0, 0x58(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x886e
movss 0x10(%r12), %xmm0
movss %xmm0, 0x4(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x8b98
movss 0x4(%rsp), %xmm0
addss (%rax), %xmm0
movss %xmm0, (%rax)
addq $0x4, %r15
jmp 0x7476
movq %r14, %rbp
movq 0x48(%rsp), %r14
jmp 0x7440
movss 0x10(%r12), %xmm0
ucomiss 0xc(%rsp), %xmm0
jb 0x7440
movss %xmm0, 0x4(%rsp)
jbe 0x74f7
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x74f7
movq %rax, 0x18(%rsp)
movq 0x8(%r12), %rsi
leaq 0x10(%rsp), %rdi
callq 0x774a
movss 0x4(%rsp), %xmm0
jmp 0x743a
xorps %xmm0, %xmm0
pushq $-0x1
popq %rax
leaq 0xe0(%rsp), %rcx
movq 0x40(%rsp), %r15
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x753e
movss 0xc(%rcx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x7524
movl 0x8(%rcx), %eax
movaps %xmm1, %xmm0
jmp 0x7524
movl %eax, 0x8(%rsp)
movq %r13, %rdi
callq 0x7a1a
cmpl $-0x1, 0x8(%rsp)
je 0x75c4
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x80bc
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x774a
leaq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0x8510
testq %rax, %rax
je 0x7401
leaq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0x80bc
movq (%rax), %r15
movq 0x8(%rax), %r12
cmpq %r12, %r15
je 0x7401
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x80bc
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x774a
addq $0x4, %r15
jmp 0x7598
callq 0x2090
cltq
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
xorl %edx, %edx
divq %rsi
leaq (%rcx,%rdx,4), %rsi
leaq 0x60(%rsp), %rdi
callq 0x80bc
movq %rax, %rdi
movq %r15, %rsi
callq 0x774a
jmp 0x7401
movq 0x30(%rsp), %r13
movq (%rbp), %rbp
testq %rbp, %rbp
je 0x7647
leaq 0x8(%rbp), %rbx
movq 0x10(%rbp), %r15
movq 0x18(%rbp), %r12
cmpq %r12, %r15
je 0x763a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x80bc
movq %rax, %rdi
movq %r15, %rsi
callq 0x774a
addq $0x4, %r15
jmp 0x7619
movq %r13, %rdi
movq %rbx, %rsi
callq 0x8c64
jmp 0x7604
leaq 0x10(%rsp), %rdi
callq 0x7a84
leaq 0x60(%rsp), %rdi
callq 0x784a
leaq 0x98(%rsp), %rdi
callq 0x784a
leaq 0xd0(%rsp), %rdi
callq 0x79fe
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x769b
jmp 0x769b
jmp 0x769b
jmp 0x769b
jmp 0x769b
jmp 0x769b
jmp 0x769b
jmp 0x769b
jmp 0x769b
jmp 0x769b
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x7a84
leaq 0x60(%rsp), %rdi
callq 0x784a
leaq 0x98(%rsp), %rdi
callq 0x784a
leaq 0xd0(%rsp), %rdi
callq 0x79fe
movq %rbx, %rdi
callq 0x23a0