// File: /workspace/github_cpp_makefile_star2_O1/panosfoto[P]NGramGraphParallel/src/NGramGraph.cpp
// Function: NGramGraph::createGraph()
void NGramGraph::createGraph()
{
    vector<Atom<std::string>> atoms;
    typename Graph(std::string)::vertex_descriptor currentVertex;
    vector<typename Graph(std::string)::vertex_descriptor> preceding_atoms;

    if (splitter == nullptr)
    {
        // TODO : throw exception for missing splitter
        std::cerr << "NGramGraph::createGraph() : Error: missing splitter. Exiting..." << std::endl; return;
    }
    if (payload == nullptr)
    {
        // TODO : throw exception for missing payload
        std::cerr << "NGramGraph::createGraph() : Error: missing payload. Exiting..." << std::endl; return;
    }
    // split payload to get the n-grams (atoms)
    atoms = splitter->splitPayloadToAtoms(payload);

    // add the atoms to the graph
    for(typename vector<Atom<std::string>>::iterator itCurrentAtom = atoms.begin() ; itCurrentAtom != atoms.end() ; ++itCurrentAtom)
    {
        // add or locate current vertex (atom) in the graph
        currentVertex = addVertex(*itCurrentAtom);

        // add edges from current vertex (atom) to its neighbors
        createEdgesToNeighbors(currentVertex, preceding_atoms);

        // update preceding atoms vector:
        // add current vertex to the neighbors (preceding atoms vector)
        preceding_atoms.push_back(currentVertex);
        // if the number of current neighbors exceeds the correlation window, then remove the first (the oldest) one
        if (preceding_atoms.size() > CorrelationWindow)
            preceding_atoms.erase(preceding_atoms.begin());
    }
    // DEBUG
//    std::cout << "Num of vertices: " << boost::num_vertices(graph) << std::endl << "Num of edges: " << boost::num_edges(graph) << std::endl;
//    std::cout << "---------\nBoost print:" << std:: endl;
//    boost::print_graph(graph);
//    std::cout << "---------\nGraphviz print:" << std:: endl;
//    printGraphviz();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
xorl %eax, %eax
movq %rax, -0x50(%rbp)
movq %rax, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
movq 0x88(%rdi), %rsi
testq %rsi, %rsi
je 0x13cfb
movq %rdi, %rbx
movq 0x90(%rdi), %rdx
testq %rdx, %rdx
je 0x13d09
movq (%rsi), %rax
leaq -0xb8(%rbp), %rdi
callq *(%rax)
xorps %xmm0, %xmm0
leaq -0xd0(%rbp), %rdi
movaps %xmm0, (%rdi)
movaps -0x60(%rbp), %xmm0
movq -0x50(%rbp), %rax
leaq -0xb8(%rbp), %r14
movups (%r14), %xmm1
movaps %xmm1, -0x60(%rbp)
movq 0x10(%r14), %rcx
movq %rcx, -0x50(%rbp)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
movups %xmm1, (%r14)
movq $0x0, 0x10(%r14)
callq 0x13e12
movq %r14, %rdi
callq 0x13e12
movq -0x60(%rbp), %r12
cmpq -0x58(%rbp), %r12
je 0x13d4f
leaq -0x88(%rbp), %r13
leaq 0x10f65(%rip), %r14     # 0x24b50
movq %r14, -0xa0(%rbp)
movq %r13, -0x98(%rbp)
movq 0x8(%r12), %rsi
movq 0x10(%r12), %rdx
addq %rsi, %rdx
leaq -0x98(%rbp), %rdi
callq 0x7db0
movq %rbx, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x13e58
movq %rax, -0x48(%rbp)
movq %r14, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
cmpq %r13, %rdi
je 0x13c3d
callq 0x6290
movq -0x48(%rbp), %r14
leaq -0x78(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x13f5e
movq -0x78(%rbp), %r15
cmpq -0x70(%rbp), %r15
je 0x13c74
movq (%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movsd 0x239f(%rip), %xmm0     # 0x16008
callq 0x13fde
addq $0x8, %r15
jmp 0x13c52
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x13c82
callq 0x6290
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x13ca4
movq -0x48(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, -0x38(%rbp)
leaq 0x10eae(%rip), %r14     # 0x24b50
jmp 0x13cb8
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x14d94
leaq 0x10e98(%rip), %r14     # 0x24b50
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq %rdx, %rax
subq %rdi, %rax
sarq $0x3, %rax
movl 0x98(%rbx), %ecx
cmpq %rcx, %rax
jbe 0x13ceb
leaq 0x8(%rdi), %rsi
cmpq %rdx, %rsi
je 0x13ce6
subq %rsi, %rdx
callq 0x6440
addq $-0x8, -0x38(%rbp)
addq $0x28, %r12
cmpq -0x58(%rbp), %r12
jne 0x13beb
jmp 0x13d4f
movl $0x3f, %edx
leaq 0x7a04(%rip), %rsi      # 0x1b70b
jmp 0x13d15
movl $0x3e, %edx
leaq 0x7a36(%rip), %rsi      # 0x1b74b
movq 0x112c4(%rip), %rbx     # 0x24fe0
movq %rbx, %rdi
callq 0x6300
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x62a0
movsbl %al, %esi
movq 0x1129e(%rip), %rdi     # 0x24fe0
callq 0x6030
movq %rax, %rdi
callq 0x61e0
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x13d5d
callq 0x6290
leaq -0x60(%rbp), %rdi
callq 0x13e12
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x13d94
jmp 0x13d94
movq %rax, %rbx
movq %r14, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
cmpq %r13, %rdi
jne 0x13da5
jmp 0x13daa
movq %rax, %rbx
jmp 0x13daa
movq %rax, %rbx
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x13daa
callq 0x6290
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x13db8
callq 0x6290
leaq -0x60(%rbp), %rdi
callq 0x13e12
movq %rbx, %rdi
callq 0x6490
nop