<commit_before>//= require stdlib.js

class Graph

  constructor: (nodeDatas, relDatas) ->
    @nodes = []
    @nodeHash = {}
    @relationships = []

    for nodeData in nodeDatas
      node = new Node(nodeData.id)
      @nodeHash[node.id] = node
      @nodes.push(node)

    for relData in relDatas
      start_node = @nodeHash[relData.start_node]
      end_node = @nodeHash[relData.end_node]
      rel = new Relationship(relData.id, relData.data.rel_type, start_node, end_node)
      @relationships.push(rel)
      start_node.addOutgoing(rel)
      end_node.addIncoming(rel)


  load: (nodeId) ->
    for node in @nodes
      return node if node.id == nodeId

    throw "no such node in graph: " + nodeId if !node

  areConnected: (nodeA, nodeB, activeRels) ->

    activeRels ?= @relationships

    # Make sure we don't destroy the input:
    mutableActiveRels = activeRels.slice(0)

    return @innerAreConnected(nodeA, nodeB, mutableActiveRels)

  innerAreConnected: (nodeA, nodeB, activeRels) ->
    connected = false
    for rel in nodeA.both()
      if activeRels.contains(rel)
        # Remove the relationship already traversed so that
        # next iteration does not traverse "backwards" again
        activeRels.remove(activeRels.indexOf(rel))<commit_msg>refactoring<commit_after>//= require stdlib.js

class Graph

  constructor: (nodeDatas, relDatas) ->
    @nodes = []
    @nodeHash = {}
    @relationships = []

    for nodeData in nodeDatas
      node = new Node(nodeData.id)
      @nodeHash[node.id] = node
      @nodes.push(node)

    for relData in relDatas
      start_node = @nodeHash[relData.start_node]
      end_node = @nodeHash[relData.end_node]
      rel = new Relationship(relData.id, relData.data.rel_type, start_node, end_node)
      @relationships.push(rel)
      start_node.addOutgoing(rel)
      end_node.addIncoming(rel)


  load: (nodeId) ->
    for node in @nodes
      return node if node.id == nodeId

    throw "no such node in graph: " + nodeId if !node

  areConnected: (nodeA, nodeB, activeRels=@relationships) ->
    # Make sure we don't destroy the input:
    mutableActiveRels = activeRels.slice(0)

    @innerAreConnected(nodeA, nodeB, mutableActiveRels)

  innerAreConnected: (nodeA, nodeB, activeRels) ->
    connected = false
    for rel in nodeA.both()
      if activeRels.contains(rel)
        # Remove the relationship already traversed so that
        # next iteration does not traverse "backwards" again
        activeRels.remove(activeRels.indexOf(rel))
{'fraction_non_alphanumeric': 0.10075667064914377, 'fraction_numerical': 0.0007964954201513341, 'mean_word_length': 3.0713128038897892, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1533488', 'n_tokens_mistral': 842, 'n_tokens_neox': 809, 'n_words': 204}