<commit_before>#!/usr/bin/python
"""
Implementation of a graph class and a shortest path algorithm.

author: edelsonc
created: 10/08/2016
"""
import priorityQueue as pQ


class Graph(object):
    """
    A simple implementation of a directed unweighted graph
    """
    def __init__(self):
        """
        Initializes an empty graph object

        Create New Graph
        ----------------
        >>> graph = Graph()
        >>> graph.vertexList
        []
        >>> graph.connections
        {}
        """
        self.vertexList = []
        self.connections = {}

    def addVertex(self, vertex):
        """
        Adds a vertex to the graph object. Makes sure that the vertex is not
        already a part of the graph

        Arguments
        ---------
        vertex -- new graph vertex

        Adding New Vertex
        -----------------
        >>> graph = Graph()
        >>> graph.addVertex("A")
        >>> graph.vertexList
        ['A']
        >>> graph.connections
        {'A': []}

        Adding Pre-existing Vertex
        --------------------------
        >>> graph.addVertex("A")
        >>> graph.vertexList
        ['A']
        """
        if vertex in self.vertexList:
            return

        self.vertexList.append(vertex)
        self.connections[vertex] = []

    def addConn(self, v1, v2):
        """
        Adds a connection (edge) to the graph, making sure that both vertices
        are in the graph. If a vertex isn't in the graph, it is added first.

        Arguments
        ---------
        v1, v2 -- vertices connected via an edge; edge goes from v1 -> v2

        Adding Connection for Two Existing Vertices
        -------------------------------------------
        >>> graph = Graph()
        >>> graph.addVertex("A")
        >>> graph.addVertex("B")
        >>> graph.addConn("A", "B")
        >>> graph.connections['B']
        []

        Adding Edge for One Missing Vertex
        ----------------------------------
        >>> graph.addConn("A", "C")
        >>> graph.vertexList
        ['A', 'B', 'C']
        >>> graph.connections['A']
        ['B', 'C']
        """
        if v1 not in self.vertexList:
            self.addVertex(v1)
        if v2 not in self.vertexList:
            self.addVertex(v2)

        self.connections[v1].append(v2)

    def hasVert(self, vert):
        """
        Checks if a vertex is in the graph vertex list. Returns a boolean.

        Arguments
        ---------
        vert -- vertex that is checked for in graph

        Check Inserted Vertex
        ---------------------
        >>> graph = Graph()
        >>> graph.addVertex("A")
        >>> graph.hasVert("A")
        True<commit_msg>Updated Graph.addConn() so that it does re add existing connections<commit_after>#!/usr/bin/python
"""
Implementation of a graph class and a shortest path algorithm.

author: edelsonc
created: 10/08/2016
"""
import priorityQueue as pQ


class Graph(object):
    """
    A simple implementation of a directed unweighted graph
    """
    def __init__(self):
        """
        Initializes an empty graph object

        Create New Graph
        ----------------
        >>> graph = Graph()
        >>> graph.vertexList
        []
        >>> graph.connections
        {}
        """
        self.vertexList = []
        self.connections = {}

    def addVertex(self, vertex):
        """
        Adds a vertex to the graph object. Makes sure that the vertex is not
        already a part of the graph

        Arguments
        ---------
        vertex -- new graph vertex

        Adding New Vertex
        -----------------
        >>> graph = Graph()
        >>> graph.addVertex("A")
        >>> graph.vertexList
        ['A']
        >>> graph.connections
        {'A': []}

        Adding Pre-existing Vertex
        --------------------------
        >>> graph.addVertex("A")
        >>> graph.vertexList
        ['A']
        """
        if vertex in self.vertexList:
            return

        self.vertexList.append(vertex)
        self.connections[vertex] = []

    def addConn(self, v1, v2):
        """
        Adds a connection (edge) to the graph, making sure that both vertices
        are in the graph. If a vertex isn't in the graph, it is added first.

        Arguments
        ---------
        v1, v2 -- vertices connected via an edge; edge goes from v1 -> v2

        Adding Connection for Two Existing Vertices
        -------------------------------------------
        >>> graph = Graph()
        >>> graph.addVertex("A")
        >>> graph.addVertex("B")
        >>> graph.addConn("A", "B")
        >>> graph.connections['B']
        []

        Adding Edge for One Missing Vertex
        ----------------------------------
        >>> graph.addConn("A", "C")
        >>> graph.vertexList
        ['A', 'B', 'C']
        >>> graph.connections['A']
        ['B', 'C']
        """
        if v1 not in self.vertexList:
            self.addVertex(v1)
        if v2 not in self.vertexList:
            self.addVertex(v2)

        if v2 in self.connections[v1]:
            return

        self.connections[v1].append(v2)

    def hasVert(self, vert):
        """
        Checks if a vertex is in the graph vertex list. Returns a boolean.

        Arguments
        ---------
        vert -- vertex that is checked for in graph

        Check Inserted Vertex
        ---------------------
        >>> graph = Graph()
        >>> graph.addVertex("A")
        >>> graph.hasVert("A")
        True
{'fraction_non_alphanumeric': 0.17461468721668177, 'fraction_numerical': 0.007615593834995467, 'mean_word_length': 1.3572649572649573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 125, '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': '3029426', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1389, 'n_words': 441}