<commit_before>'''Imports'''
import sys
import argparse

'''Parse'''
def parse_red_file(filename):
    nodes = {}
    node_counter = 0
    edge_counter = 0
    parsing_nodes = True
    parsing_edges = False

    with open(filename) as f:
        lines = f.readlines()

        first_line = lines[0].split(' ')
        total_nodes = int(first_line[0])
        total_edges = int(first_line[1])
        cardinality = int(first_line[2])

        second_line = lines[1].split(' ')
        s = second_line[0]
        t = second_line[1].rstrip()

        for line in lines[1:]:
            line = line.rstrip()
            if parsing_edges:
                string_integers = line.split(' ')
                if len(string_integers) > 2:
                    node_id_1 = string_integers[0]
                    edge_type = string_integers[1]
                    node_id_2 = string_integers[2]

                    if edge_type == "--":
                        nodes[node_id_1].add_edge_out(node_id_2)
                        nodes[node_id_1].add_edge_in(node_id_2)
                        nodes[node_id_2].add_edge_out(node_id_1)
                        nodes[node_id_2].add_edge_in(node_id_1)

                    elif edge_type == "->":
                        nodes[node_id_1].add_edge_out(node_id_2)
                        nodes[node_id_2].add_edge_in(node_id_1)

                    edge_counter += 1
                    if edge_counter == total_edges:
                        parsing_edges = False
                    continue
                else:
                    parsing_edges = False

            if parsing_nodes:
                node = line.split(' ')
                red = (len(node) > 1)
                nodes[node[0]] = Node(red)
                node_counter += 1
                if node_counter > total_nodes:
                    parsing_nodes = False
                    parsing_edges = True
                continue

    return (nodes,s,t, cardinality, total_nodes, total_edges)

'''Parse end'''

'''Helper methods'''

class Node:
    def __init__(self, red):
        self.red = red
        #self.id = node_id_string
        self.edges_out = set([])
        self.edges_in = set([])

    def add_edge_out(self, node_id_string):
        self.edges_out.add(node_id_string)

    def add_edge_in(self, node_id_string): 
        self.edges_in.add(node_id_string)   
    
    def __str__(self):
        pass

def output(instance_name, nodes_len, a_res, f_res, m_res, n_res, s_res, latex):
    instance_name = instance_name.replace(".txt","").replace("../data/","") 

    res = "{:<20}".format(instance_name) + "|"
    res += "{:>8}".format(str(nodes_len)) + " |"
    res += "{:>6}".format(str(a_res)    ) + " |"
    res += "{:>6}".format(str(f_res)    ) + " |"
    res += "{:>6}".format(str(m_res)    ) + " |"
    res += "{:>6}".format(str(n_res)    ) + " |"
    res += "{:>6}".format(str(s_res)    )
    
    if latex:
        return res.replace("|", "&")
    else:
        return "|| " + res + " ||"

'''Helper methods end'''

'''Algorithm'''
#altenate
def a(nodes, start_node_id, end_node_id, cardinality, total_edges):
    visited = set([start_node_id])
    start_node = nodes[start_node_id]
    queue = [start_node]
    while len(queue) > 0:
        node = queue.pop(0)
        for node_id in node.edges_out:
            if node_id not in visited:
                if nodes[node_id].red != node.red: #if not the same colour
                    if node_id == end_node_id:
                        return True<commit_msg>final edits to make DFS not BFS<commit_after>'''Imports'''
import sys
import argparse

'''Parse'''
def parse_red_file(filename):
    nodes = {}
    node_counter = 0
    edge_counter = 0
    parsing_nodes = True
    parsing_edges = False

    with open(filename) as f:
        lines = f.readlines()

        first_line = lines[0].split(' ')
        total_nodes = int(first_line[0])
        total_edges = int(first_line[1])
        cardinality = int(first_line[2])

        second_line = lines[1].split(' ')
        s = second_line[0]
        t = second_line[1].rstrip()

        for line in lines[1:]:
            line = line.rstrip()
            if parsing_edges:
                string_integers = line.split(' ')
                if len(string_integers) > 2:
                    node_id_1 = string_integers[0]
                    edge_type = string_integers[1]
                    node_id_2 = string_integers[2]

                    if edge_type == "--":
                        nodes[node_id_1].add_edge_out(node_id_2)
                        nodes[node_id_1].add_edge_in(node_id_2)
                        nodes[node_id_2].add_edge_out(node_id_1)
                        nodes[node_id_2].add_edge_in(node_id_1)

                    elif edge_type == "->":
                        nodes[node_id_1].add_edge_out(node_id_2)
                        nodes[node_id_2].add_edge_in(node_id_1)

                    edge_counter += 1
                    if edge_counter == total_edges:
                        parsing_edges = False
                    continue
                else:
                    parsing_edges = False

            if parsing_nodes:
                node = line.split(' ')
                red = (len(node) > 1)
                nodes[node[0]] = Node(red)
                node_counter += 1
                if node_counter > total_nodes:
                    parsing_nodes = False
                    parsing_edges = True
                continue

    return (nodes,s,t, cardinality, total_nodes, total_edges)

'''Parse end'''

'''Helper methods'''

class Node:
    def __init__(self, red):
        self.red = red
        #self.id = node_id_string
        self.edges_out = set([])
        self.edges_in = set([])

    def add_edge_out(self, node_id_string):
        self.edges_out.add(node_id_string)

    def add_edge_in(self, node_id_string): 
        self.edges_in.add(node_id_string)   
    
    def __str__(self):
        pass

def output(instance_name, nodes_len, a_res, f_res, m_res, n_res, s_res, latex):
    instance_name = instance_name.replace(".txt","").replace("../data/","") 

    res = "{:<20}".format(instance_name) + "|"
    res += "{:>8}".format(str(nodes_len)) + " |"
    res += "{:>6}".format(str(a_res)    ) + " |"
    res += "{:>6}".format(str(f_res)    ) + " |"
    res += "{:>6}".format(str(m_res)    ) + " |"
    res += "{:>6}".format(str(n_res)    ) + " |"
    res += "{:>6}".format(str(s_res)    )
    
    if latex:
        return res.replace("|", "&")
    else:
        return "|| " + res + " ||"

'''Helper methods end'''

'''Algorithm'''
#altenate
def a(nodes, start_node_id, end_node_id, cardinality, total_edges):
    visited = set([start_node_id])
    start_node = nodes[start_node_id]
    queue = [start_node]
    while len(queue) > 0:
        node = queue.pop() # this makes it DFS, if we use pop(0) its BFS.
        for node_id in node.edges_out:
            if node_id not in visited:
                if nodes[node_id].red != node.red: #if not the same colour
                    if node_id == end_node_id:
                        return True
{'fraction_non_alphanumeric': 0.12914558740865656, 'fraction_numerical': 0.011804384485666104, 'mean_word_length': 1.7510630073444144, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 25, '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': '5409865', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2263, 'n_words': 425}