<commit_before>#include "graphstate.h"

/* TODO: implement graphstate.cpp */

/* Destructor */
GraphState::~GraphState()
{

}

/* Selects the first child of the selected region, if it exists */
void GraphState::selectAChild()
{
    if (!selected->getChildren().isEmpty())
        selected = selected->getChildren().first();
}

/* Selects the parent of the selected node, if not already root. */
void GraphState::selectParent()
{
    if (!selected->isRoot())
        selected = selected->getParent();
}

/* Recursively selects the parent of the selection until we reach root */
void GraphState::selectRoot()
{
    while (!selected->isRoot())
        selected = selected->getParent();
}

/* Selects the previous sibling of the parent's getChildren list */
void GraphState::selectLeftSibling()
{
    /* Root doesn't have any siblings */
    if (selected->isRoot())
        return;

    /* List has the selected item and all its siblings */
    QList<GraphElement*> list = selected->getParent()->getChildren();

    GraphElement* previous = NULL;

    for (GraphElement* prev : list)
    {
        if (prev == selected)
            break;
        previous = prev;
    }

    /* Nothing to the left */
    if (previous == NULL)
       selected = list.last();
    else /* Choose the previous as the new selection */
        selected = previous;
}

/* Select the next right sibling */
void GraphState::selectRightSibling()
{
    /* Root doesn't have any siblings */
    if (selected->isRoot())
        return;

    /* List has the selected item and all its siblings */
    QList<GraphElement*> list = selected->getParent()->getChildren();

    GraphElement* next = NULL;
    QList<GraphElement*>::const_reverse_iterator it = list.rbegin();
    for (; it != list.rend(); ++it)
    {
        if (*it == selected)
            break;
        next = *it;
    }

    /* Nothing to the right */
    if (next == NULL)
       selected = list.front();
    else /* Choose the next as the new selection */
        selected = next;
}


/* Add */
void GraphState::addChildCut()
{

}
void GraphState::addChildDoubleCut()
{

}
void GraphState::addChildStatement(QString s)
{

}

/* Remove */
void GraphState::removeAndSaveOrphans()
{

}
void GraphState::removeAndBurnTheOrphanage()
{

}

/* Surround with cut */
void GraphState::surroundWithCut()
{

}
void GraphState::surroundWithDoubleCut()
{

}<commit_msg>Completed implementation for adding cut, double cut, and statement<commit_after>#include "graphstate.h"

/* TODO: implement graphstate.cpp */

/* Destructor */
GraphState::~GraphState()
{

}

/* Selects the first child of the selected region, if it exists */
void GraphState::selectAChild()
{
    if (!selected->getChildren().isEmpty())
        selected = selected->getChildren().first();
}

/* Selects the parent of the selected node, if not already root. */
void GraphState::selectParent()
{
    if (!selected->isRoot())
        selected = selected->getParent();
}

/* Recursively selects the parent of the selection until we reach root */
void GraphState::selectRoot()
{
    while (!selected->isRoot())
        selected = selected->getParent();
}

/* Selects the previous sibling of the parent's getChildren list */
void GraphState::selectLeftSibling()
{
    /* Root doesn't have any siblings */
    if (selected->isRoot())
        return;

    /* List has the selected item and all its siblings */
    QList<GraphElement*> list = selected->getParent()->getChildren();

    GraphElement* previous = NULL;

    for (GraphElement* prev : list)
    {
        if (prev == selected)
            break;
        previous = prev;
    }

    /* Nothing to the left */
    if (previous == NULL)
       selected = list.last();
    else /* Choose the previous as the new selection */
        selected = previous;
}

/* Select the next right sibling */
void GraphState::selectRightSibling()
{
    /* Root doesn't have any siblings */
    if (selected->isRoot())
        return;

    /* List has the selected item and all its siblings */
    QList<GraphElement*> list = selected->getParent()->getChildren();

    GraphElement* next = NULL;
    QList<GraphElement*>::const_reverse_iterator it = list.rbegin();
    for (; it != list.rend(); ++it)
    {
        if (*it == selected)
            break;
        next = *it;
    }

    /* Nothing to the right */
    if (next == NULL)
       selected = list.front();
    else /* Choose the next as the new selection */
        selected = next;
}

/* Adds a cut to the selected node's children */
void GraphState::addChildCut()
{
    /* Statements cannot have children */
    if (selected->isStatement())
        return;

    GraphElement newCut = GraphElement::Cut(selected);
    selected->addChild(&newCut);

    selected = &newCut;
}

/* Adds a double cut to the selected region */
void GraphState::addChildDoubleCut()
{
    /* Statements cannot have children */
    if (selected->isStatement())
        return;

    GraphElement newOuterCut = GraphElement::Cut(selected);
    GraphElement newInnerCut = GraphElement::Cut(&newOuterCut);
    newOuterCut.addChild(&newInnerCut);

    selected->addChild(&newOuterCut);
    selected = &newInnerCut;
}

/* Adds a child statement with the string s */
void GraphState::addChildStatement(QString s)
{
    if (selected->isStatement())
        return;

    GraphElement newStatement = GraphElement::Statement(selected,s);
    selected->addChild(&newStatement);
    selected = &newStatement;
}

/* Remove */
void GraphState::removeAndSaveOrphans()
{

}
void GraphState::removeAndBurnTheOrphanage()
{

}

/* Surround with cut */
void GraphState::surroundWithCut()
{

}
void GraphState::surroundWithDoubleCut()
{

}
{'fraction_non_alphanumeric': 0.1315000881367883, 'fraction_numerical': 0.0, 'mean_word_length': 3.0644699140401146, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3656797', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1601, 'n_words': 478}