<commit_before>#include <fstream>
#include <json/json.h>
#include "GraphSerializer.hpp"

namespace tsp
{
    static bool validateGraph(const Json::Value &root)
    {
        return root.isObject() && root["nodes"].isArray();
    }

    bool GraphSerializer::deserialize(Graph &graph, std::istream& is)
    {
        Json::Value root;
        Json::Reader reader;

        if(!reader.parse(is, root, false))
            return false;
        if(!validateGraph(root))
            return false;

        // deserialize nodes
        Json::Value &nodes = root["nodes"];
        graph.resize(nodes.size());
        for(unsigned int i = 0; nodes.size(); ++i)
            graph[i] = Node(nodes[i]["id"].asInt(), nodes[i]["x"].asInt(), nodes[i]["y"].asInt());

        return true;
    }
<commit_msg>fix segmentation fault<commit_after>#include <fstream>
#include <json/json.h>
#include "GraphSerializer.hpp"

namespace tsp
{
    static bool validateGraph(const Json::Value &root)
    {
        return root.isObject() && root["nodes"].isArray();
    }

    bool GraphSerializer::deserialize(Graph &graph, std::istream& is)
    {
        Json::Value root;
        Json::Reader reader;

        if(!reader.parse(is, root, false))
            return false;
        if(!validateGraph(root))
            return false;

        // deserialize nodes
        Json::Value &nodes = root["nodes"];
        graph.resize(nodes.size());
        for(unsigned int i = 0; i < nodes.size(); ++i)
            graph[i] = Node(nodes[i]["id"].asInt(), nodes[i]["x"].asInt(), nodes[i]["y"].asInt());

        return true;
    }

{'fraction_non_alphanumeric': 0.1659361302442079, 'fraction_numerical': 0.0012523481527864746, 'mean_word_length': 2.5910112359550563, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '4200523', 'n_tokens_mistral': 490, 'n_tokens_neox': 480, 'n_words': 105}