class Seafoam::Graph
A graph, with properties, nodes, and edges. We don't encapsulate the graph too much - be careful.
Attributes
blocks[R]
edges[R]
nodes[R]
props[R]
Public Class Methods
new(props = nil)
click to toggle source
# File lib/seafoam/graph.rb, line 7 def initialize(props = nil) @props = props || {} @nodes = {} @edges = [] @blocks = [] end
Public Instance Methods
create_block(id, node_ids)
click to toggle source
Add a new basic block with given id and node id list.
# File lib/seafoam/graph.rb, line 33 def create_block(id, node_ids) nodes = node_ids.select { |n| @nodes.key? n }.map { |n| @nodes[n] } block = Block.new(id, nodes) @blocks.push block block end
create_edge(from, to, props = nil)
click to toggle source
Create an edge between two nodes.
# File lib/seafoam/graph.rb, line 23 def create_edge(from, to, props = nil) props ||= {} edge = Edge.new(from, to, props) @edges.push edge from.outputs.push edge to.inputs.push edge edge end
create_node(id, props = nil)
click to toggle source
Create a node.
# File lib/seafoam/graph.rb, line 15 def create_node(id, props = nil) props ||= {} node = Node.new(id, props) @nodes[id] = node node end