class Tangle::Directed::Acyclic::PartialOrder

Implement a Partial Order for vertices in a DAG.

Attributes

graph[R]
vertex[R]

Public Class Methods

[](graph, *vertices) click to toggle source

Wrap a set of vertices, or all vertices, in a graph in a parial ordering, such that the elements in the returned set are comparable by u <= v iff v is an ancestor of u.

# File lib/tangle/directed/acyclic/partial_order.rb, line 14
def self.[](graph, *vertices)
  vertices = graph.vertices if vertices.empty?
  vertices.map { |vertex| new(graph, vertex) }
end
new(graph, vertex) click to toggle source
# File lib/tangle/directed/acyclic/partial_order.rb, line 25
def initialize(graph, vertex)
  @graph = graph
  @vertex = vertex
end

Protected Instance Methods

<=>(other) click to toggle source
# File lib/tangle/directed/acyclic/partial_order.rb, line 30
def <=>(other)
  raise GraphError unless graph == other.graph
  return 0 if vertex == other.vertex
  return -1 if graph.successor?(vertex, other.vertex)

  1
end