Sha256: ee85115fb735c12c150e6a03c1580c55419045385261ea0a74f189be593f1805

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module Tangle
  #
  # The protected bits of Graph
  #
  module GraphProtected
    protected

    # Insert a prepared vertex into the graph
    #
    def insert_vertex(vertex)
      raise ArgumentError unless vertex.graph.eql?(self)

      @edges_by_vertex[vertex] = []
      @vertices_by_name[vertex.name] = vertex unless vertex.name.nil?
      @vertices_by_id[vertex.vertex_id] = vertex
    end

    # Insert a prepared edge into the graph
    #
    def insert_edge(edge)
      raise ArgumentError unless edge.graph.eql?(self)

      @edges << edge
      edge.vertices.each do |vertex|
        @edges_by_vertex[vertex] << edge
      end
      edge
    end

    def with_vertices(vertices = [])
      initialize_vertices

      vertices.each do |vertex|
        insert_vertex(vertex.clone_into(self))
      end
      self
    end

    def with_edges(edges = [])
      initialize_edges

      edges.each do |edge|
        new_edge = edge.clone_into(self)
        insert_edge(new_edge) unless new_edge.nil?
      end
      self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tangle-0.7.0 lib/tangle/graph_protected.rb