class Tangle::Edge

An edge in an undirected graph, connecting two vertices

Attributes

name[R]

Public Class Methods

new(vertex1, vertex2 = vertex1, name: nil, **kwargs) click to toggle source

Create a new edge between vertices

Edge.new(vtx1) => Edge (loop) Edge.new(vtx1, vtx2) => Edge

End users should probably use Graph#add_edge instead.

# File lib/tangle/edge.rb, line 22
def initialize(vertex1, vertex2 = vertex1, name: nil, **kwargs)
  @name = name
  initialize_vertices(vertex1, vertex2)
  initialize_mixins(**kwargs)
end

Public Instance Methods

[](from_vertex) click to toggle source
# File lib/tangle/edge.rb, line 28
def [](from_vertex)
  @vertices[from_vertex]
end
include?(vertex) click to toggle source
# File lib/tangle/edge.rb, line 36
def include?(vertex)
  each_vertex.include?(vertex)
end
loop?() click to toggle source
# File lib/tangle/edge.rb, line 40
def loop?
  @loop
end
walk(from_vertex) click to toggle source
# File lib/tangle/edge.rb, line 32
def walk(from_vertex)
  @vertices.fetch(from_vertex)
end

Private Instance Methods

initialize_vertices(vertex1, vertex2) click to toggle source
# File lib/tangle/edge.rb, line 46
def initialize_vertices(vertex1, vertex2)
  @loop = vertex1 == vertex2
end