-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedge.go
More file actions
37 lines (29 loc) · 746 Bytes
/
edge.go
File metadata and controls
37 lines (29 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package dagg
import (
"fmt"
)
// Edge represents an edge in the graph, with a source and target vertex.
type Edge[T Hashable] interface {
Source() T
Target() T
Hashable
}
// BasicEdge returns an Edge implementation that simply tracks the source
// and target given as-is.
func BasicEdge[T Hashable](source, target T) Edge[T] {
return &basicEdge[T]{Src: source, Trgt: target}
}
// basicEdge is a basic implementation of Edge that has the source and
// target vertex.
type basicEdge[T Hashable] struct {
Src, Trgt T
}
func (e *basicEdge[T]) Hashcode() string {
return fmt.Sprintf("%s-%s", e.Src.Hashcode(), e.Trgt.Hashcode())
}
func (e *basicEdge[T]) Source() T {
return e.Src
}
func (e *basicEdge[T]) Target() T {
return e.Trgt
}