// File: 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
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x35da0
leaq -0x40(%rbp), %rdi
callq 0x35dc0
movq -0xd8(%rbp), %rax
cmpq $0x0, 0x88(%rax)
jne 0x35a3b
movq 0x325f4(%rip), %rdi     # 0x67fe8
leaq 0x104f1(%rip), %rsi     # 0x45eec
callq 0x83d0
movq %rax, -0xe0(%rbp)
jmp 0x35a09
movq -0xe0(%rbp), %rdi
movq 0x32581(%rip), %rsi     # 0x67f98
callq 0x8410
jmp 0x35a1e
movl $0x1, -0x50(%rbp)
jmp 0x35c53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x35c6e
movq -0xd8(%rbp), %rax
cmpq $0x0, 0x90(%rax)
jne 0x35a89
movq 0x32595(%rip), %rdi     # 0x67fe8
leaq 0x104d2(%rip), %rsi     # 0x45f2c
callq 0x83d0
movq %rax, -0xe8(%rbp)
jmp 0x35a68
movq -0xe8(%rbp), %rdi
movq 0x32522(%rip), %rsi     # 0x67f98
callq 0x8410
jmp 0x35a7d
movl $0x1, -0x50(%rbp)
jmp 0x35c53
movq -0xd8(%rbp), %rax
movq 0x88(%rax), %rsi
movq 0x90(%rax), %rdx
movq (%rsi), %rax
movq (%rax), %rax
leaq -0x68(%rbp), %rdi
callq *%rax
jmp 0x35aac
leaq -0x20(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x35de0
leaq -0x68(%rbp), %rdi
callq 0x35e10
leaq -0x20(%rbp), %rdi
callq 0x35e70
movq %rax, -0x70(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x35ee0
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x35ea0
testb $0x1, %al
jne 0x35af2
jmp 0x35c4c
leaq -0x70(%rbp), %rdi
callq 0x35fb0
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x35fd0
jmp 0x35b0c
movq -0xd8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x35f10
movq %rax, -0xf0(%rbp)
jmp 0x35b28
movq -0xf0(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x36010
movq -0x28(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x36040
jmp 0x35b5c
movq -0xf8(%rbp), %rsi
movq -0xd8(%rbp), %rdi
leaq -0xb8(%rbp), %rdx
callq 0x35c90
jmp 0x35b78
leaq -0xb8(%rbp), %rdi
callq 0x36130
leaq -0x40(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x36190
jmp 0x35b93
leaq -0x40(%rbp), %rdi
callq 0x36200
movq -0xd8(%rbp), %rcx
movl 0x98(%rcx), %ecx
cmpq %rcx, %rax
jbe 0x35c3c
leaq -0x40(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x36290
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x362c0
movq -0x108(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x36220
movq %rax, -0x100(%rbp)
jmp 0x35bf8
movq -0x100(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x35c3c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x36010
jmp 0x35c6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x36130
jmp 0x35c6e
jmp 0x35c3e
leaq -0x70(%rbp), %rdi
callq 0x36300
jmp 0x35acf
movl $0x0, -0x50(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x36130
leaq -0x20(%rbp), %rdi
callq 0x35e10
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x36130
leaq -0x20(%rbp), %rdi
callq 0x35e10
movq -0x48(%rbp), %rdi
callq 0x86c0
nopl (%rax)