diff --git a/docs/∆-Nets: Interaction-Based System for Optimal Parallel λ-Reduction.pdf b/docs/∆-Nets: Interaction-Based System for Optimal Parallel λ-Reduction.pdf new file mode 100644 index 0000000..11e285a Binary files /dev/null and b/docs/∆-Nets: Interaction-Based System for Optimal Parallel λ-Reduction.pdf differ diff --git a/pkg/deltanet/deltanet.go b/pkg/deltanet/deltanet.go index be3f3ff..bea8298 100644 --- a/pkg/deltanet/deltanet.go +++ b/pkg/deltanet/deltanet.go @@ -2,8 +2,5 @@ package deltanet type Graph struct { - nodes []Node -} - -type Node interface { + Nodes []Node } diff --git a/pkg/deltanet/node.go b/pkg/deltanet/node.go new file mode 100644 index 0000000..91a77d0 --- /dev/null +++ b/pkg/deltanet/node.go @@ -0,0 +1,94 @@ +package deltanet + +/** ------------------------------------------------------------------------- */ + +// A connection between exactly two nodes in a graph. +type Edge struct { + A, B Node +} + +// Returns all nodes the edge is connected to. +func (e Edge) GetConnections() []Node { return []Node{e.A, e.B} } + +// Determines if a node is connected via this edge. +func (e Edge) IsConnected(n Node) bool { return e.A == n || e.B == n } + +// Swaps an edges connected with one node, for another. +func (e *Edge) Swap(from Node, to Node) { + if e.A == from { + e.A = to + } + if e.B == from { + e.B = to + } +} + +// Returns true if the edge is connected to each node via their pricniple ports. +func (e Edge) IsPrincipleEdge() bool { + return e.A.GetMainPort() == e && e.B.GetMainPort() == e +} + +/** ------------------------------------------------------------------------- */ + +type Node interface { + // Returns the principle port that the node is attached to. + GetMainPort() Edge + + // Returns all auxiliary ports that the node has. These ports are guaranteed + // to be ordered clockwise, as they would appear graphically. + GetAuxPorts() []Edge + + // Returns the label of the node. May be blank. + GetLabel() string +} + +/** ------------------------------------------------------------------------- */ + +type EraserNode struct { + Main Edge +} + +func (n EraserNode) GetLabel() string { return "Ⓧ" } +func (n EraserNode) GetMainPort() Edge { return n.Main } +func (n EraserNode) GetAuxPorts() []Edge { return []Edge{} } + +/** ------------------------------------------------------------------------- */ + +type ReplicatorNode struct { + Main Edge + Level uint + Aux []Edge + Deltas []int +} + +func (n ReplicatorNode) GetLabel() string { return "" } +func (n ReplicatorNode) GetMainPort() Edge { return n.Main } +func (n ReplicatorNode) GetAuxPorts() []Edge { return n.Aux } + +// Returns the level of the replicator node. +func (n ReplicatorNode) GetLevel() uint { return n.Level } + +/** ------------------------------------------------------------------------- */ + +type FanNode struct { + Label string + Main Edge + Left, Right Edge +} + +func (n FanNode) GetLabel() string { return n.Label } +func (n FanNode) GetMainPort() Edge { return n.Main } +func (n FanNode) GetAuxPorts() []Edge { return []Edge{n.Left, n.Right} } + +/** ------------------------------------------------------------------------- */ + +type TerminalNode struct { + Label string + Main Edge +} + +func (n TerminalNode) GetLabel() string { return n.Label } +func (n TerminalNode) GetMainPort() Edge { return n.Main } +func (n TerminalNode) GetAuxPorts() []Edge { return []Edge{} } + +/** ------------------------------------------------------------------------- */