// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
andq $0x0, -0x50(%rbp)
xorps %xmm0, %xmm0
andq $0x0, -0x30(%rbp)
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x40(%rbp)
movq 0x88(%rdi), %rsi
testq %rsi, %rsi
je 0x14df8
movq %rdi, %rbx
movq 0x90(%rdi), %rdx
testq %rdx, %rdx
je 0x14e01
movq (%rsi), %rax
leaq -0x90(%rbp), %rdi
callq *(%rax)
leaq -0x60(%rbp), %r14
leaq -0x90(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x15aa6
movq %r15, %rdi
callq 0x14ef6
movq (%r14), %r14
leaq -0xb8(%rbp), %r15
leaq -0x78(%rbp), %r12
cmpq -0x58(%rbp), %r14
je 0x14e1c
movq %r15, %rdi
movq %r14, %rsi
callq 0x14f7c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x14f22
movq %rax, -0x48(%rbp)
movq %r15, %rdi
callq 0x14f98
movq -0x48(%rbp), %r13
movq %r12, %rdi
leaq -0x40(%rbp), %rsi
callq 0x14fb0
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x14e80
movq %r12, %rdi
callq 0x15a92
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x15008
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 0x14def
leaq 0x8(%rdi), %rsi
cmpq %rdx, %rsi
je 0x14de7
subq %rsi, %rdx
callq 0x7480
movq -0x38(%rbp), %rdx
addq $-0x8, %rdx
movq %rdx, -0x38(%rbp)
addq $0x28, %r14
jmp 0x14d56
leaq 0x90d1(%rip), %rsi      # 0x1ded0
jmp 0x14e08
leaq 0x9108(%rip), %rsi      # 0x1df10
movq 0x171d1(%rip), %rdi     # 0x2bfe0
callq 0x72e0
movq %rax, %rdi
callq 0x7170
leaq -0x40(%rbp), %rdi
callq 0x15a92
leaq -0x60(%rbp), %rdi
callq 0x14ef6
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14e63
jmp 0x14e63
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x15a92
jmp 0x14e66
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x14f98
jmp 0x14e66
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x15a92
leaq -0x60(%rbp), %rdi
callq 0x14ef6
movq %rbx, %rdi
callq 0x74d0