github.com/eliastor/durgaform@v0.0.0-20220816172711-d0ab2d17673e/internal/dag/edge.go (about)

     1  package dag
     2  
     3  // Edge represents an edge in the graph, with a source and target vertex.
     4  type Edge interface {
     5  	Source() Vertex
     6  	Target() Vertex
     7  
     8  	Hashable
     9  }
    10  
    11  // BasicEdge returns an Edge implementation that simply tracks the source
    12  // and target given as-is.
    13  func BasicEdge(source, target Vertex) Edge {
    14  	return &basicEdge{S: source, T: target}
    15  }
    16  
    17  // basicEdge is a basic implementation of Edge that has the source and
    18  // target vertex.
    19  type basicEdge struct {
    20  	S, T Vertex
    21  }
    22  
    23  func (e *basicEdge) Hashcode() interface{} {
    24  	return [...]interface{}{e.S, e.T}
    25  }
    26  
    27  func (e *basicEdge) Source() Vertex {
    28  	return e.S
    29  }
    30  
    31  func (e *basicEdge) Target() Vertex {
    32  	return e.T
    33  }