2024-02-08 03:48:59 -06:00
|
|
|
// Copyright (c) The OpenTofu Authors
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
2023-05-02 10:33:06 -05:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-01-23 17:01:58 -06:00
|
|
|
package dag
|
|
|
|
|
|
|
|
// Edge represents an edge in the graph, with a source and target vertex.
|
|
|
|
type Edge interface {
|
|
|
|
Source() Vertex
|
|
|
|
Target() Vertex
|
2015-01-30 14:56:03 -06:00
|
|
|
|
2015-02-13 16:12:23 -06:00
|
|
|
Hashable
|
2015-01-23 17:01:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// BasicEdge returns an Edge implementation that simply tracks the source
|
|
|
|
// and target given as-is.
|
|
|
|
func BasicEdge(source, target Vertex) Edge {
|
|
|
|
return &basicEdge{S: source, T: target}
|
|
|
|
}
|
|
|
|
|
|
|
|
// basicEdge is a basic implementation of Edge that has the source and
|
|
|
|
// target vertex.
|
|
|
|
type basicEdge struct {
|
|
|
|
S, T Vertex
|
|
|
|
}
|
|
|
|
|
2015-01-30 14:56:03 -06:00
|
|
|
func (e *basicEdge) Hashcode() interface{} {
|
2022-01-05 05:28:47 -06:00
|
|
|
return [...]interface{}{e.S, e.T}
|
2015-01-30 14:56:03 -06:00
|
|
|
}
|
|
|
|
|
2015-01-23 17:01:58 -06:00
|
|
|
func (e *basicEdge) Source() Vertex {
|
|
|
|
return e.S
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *basicEdge) Target() Vertex {
|
|
|
|
return e.T
|
|
|
|
}
|