// File: /workspace/github_cpp_makefile_star2_O3/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 $0xb8, %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 0x13b88
movq %rdi, %rbx
movq 0x90(%rdi), %rdx
testq %rdx, %rdx
je 0x13b96
movq (%rsi), %rax
leaq -0xc0(%rbp), %rdi
callq *(%rax)
movaps -0x60(%rbp), %xmm0
movq -0x50(%rbp), %rax
leaq -0xc0(%rbp), %r14
movaps (%r14), %xmm1
movaps %xmm1, -0x60(%rbp)
movq 0x10(%r14), %rcx
movq %rcx, -0x50(%rbp)
leaq -0xd8(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x13ca6
movq %r14, %rdi
callq 0x13ca6
movq -0x60(%rbp), %r13
cmpq -0x58(%rbp), %r13
je 0x13bdc
leaq -0x88(%rbp), %r12
leaq 0x11103(%rip), %rax     # 0x24b70
movq %rax, -0xa0(%rbp)
movq %r12, -0x98(%rbp)
movq 0x8(%r13), %rsi
movq 0x10(%r13), %rdx
addq %rsi, %rdx
leaq -0x98(%rbp), %rdi
callq 0x7d54
movq %rbx, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x13cf6
movq %rax, %r14
movq %rax, -0x48(%rbp)
leaq 0x110c1(%rip), %rax     # 0x24b70
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
je 0x13acb
callq 0x6290
movq -0x48(%rbp), %r14
leaq -0x78(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x13dfc
movq -0x78(%rbp), %r15
cmpq -0x70(%rbp), %r15
je 0x13b06
movq (%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movsd 0x2515(%rip), %xmm0     # 0x16008
callq 0x13e7c
addq $0x8, %r15
cmpq -0x70(%rbp), %r15
jne 0x13ae2
movq -0x78(%rbp), %r15
testq %r15, %r15
je 0x13b13
movq %r15, %rdi
callq 0x6290
movq -0x38(%rbp), %rdx
cmpq -0x30(%rbp), %rdx
je 0x13b2e
movq -0x48(%rbp), %rax
movq %rax, (%rdx)
addq $0x8, %rdx
movq %rdx, -0x38(%rbp)
jmp 0x13b42
leaq -0x40(%rbp), %rdi
movq %rdx, %rsi
leaq -0x48(%rbp), %rdx
callq 0x14c3c
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rdi
movq %rdx, %rax
subq %rdi, %rax
sarq $0x3, %rax
movl 0x98(%rbx), %ecx
cmpq %rcx, %rax
jbe 0x13b78
leaq 0x8(%rdi), %rsi
cmpq %rdx, %rsi
je 0x13b70
subq %rsi, %rdx
callq 0x6440
movq -0x38(%rbp), %rdx
addq $-0x8, %rdx
movq %rdx, -0x38(%rbp)
addq $0x28, %r13
cmpq -0x58(%rbp), %r13
jne 0x13a66
jmp 0x13bdc
movl $0x3f, %edx
leaq 0x7b77(%rip), %rsi      # 0x1b70b
jmp 0x13ba2
movl $0x3e, %edx
leaq 0x7ba9(%rip), %rsi      # 0x1b74b
movq 0x1143f(%rip), %rbx     # 0x24fe8
movq %rbx, %rdi
callq 0x6300
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x62a0
movsbl %al, %esi
movq 0x11419(%rip), %rdi     # 0x24fe8
callq 0x6030
movq %rax, %rdi
callq 0x61e0
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x13bea
callq 0x6290
leaq -0x60(%rbp), %rdi
callq 0x13ca6
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x13c28
jmp 0x13c28
movq %rax, %rbx
leaq 0x10f5d(%rip), %rax     # 0x24b70
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
jne 0x13c39
jmp 0x13c3e
movq %rax, %rbx
jmp 0x13c3e
movq %rax, %rbx
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x13c3e
callq 0x6290
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x13c4c
callq 0x6290
leaq -0x60(%rbp), %rdi
callq 0x13ca6
movq %rbx, %rdi
callq 0x6490
nop