Documentation ¶
Index ¶
- type AdjacencyMatrix
- func (am *AdjacencyMatrix[E, V]) AddEdge(fromNode, toNode V, weight E)
- func (am *AdjacencyMatrix[E, V]) AddNodes(dataList ...V)
- func (am *AdjacencyMatrix[E, V]) CheckEdge(fromNode, toNode V) (reachable bool, weight E)
- func (am *AdjacencyMatrix[E, V]) GetMatrix() (matrix [][]E)
- func (am *AdjacencyMatrix[E, V]) GetVertexList() (vertexList []V)
- func (am *AdjacencyMatrix[E, V]) MatrixString() string
- func (am *AdjacencyMatrix[E, V]) RemoveEdge(fromNode, toNode V)
- func (am *AdjacencyMatrix[E, V]) RemoveNode(data V)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdjacencyMatrix ¶
type AdjacencyMatrix[E, V any] struct { // contains filtered or unexported fields }
func NewAdjacencyMatrix ¶
func NewAdjacencyMatrix[E, V any]( zeroWeight *E, vertexEqualFunc vertexEqualFunc[V], edgeEqualFunc edgeEqualFunc[E]) (am *AdjacencyMatrix[E, V])
Example ¶
package main import ( "fmt" "gitee.com/cruvie/kk_go_kit/kk_graph/kk_adjacency_matrix" ) type user struct { status int name string } type userWeight struct { cost int } func main() { am := kk_adjacency_matrix.NewAdjacencyMatrix[userWeight, user](&userWeight{ cost: -1, }, func(a, b user) bool { return a.name == b.name }, func(a, b userWeight) bool { return a.cost == b.cost }) u1 := user{status: 1, name: "a"} u2 := user{status: 2, name: "b"} u3 := user{status: 3, name: "c"} am.AddNodes(u1, u2, u3) am.AddNodes(u1, u2, u3) am.AddEdge(u1, u2, userWeight{ cost: 22, }) am.AddEdge(u2, u3, userWeight{ cost: 15, }) reachable, weight := am.CheckEdge(u2, u3) fmt.Println(reachable, weight) fmt.Println(am.MatrixString()) }
Output: true {15} {0} {22} {-1} {0} {0} {15} {0} {0} {-1}
func (*AdjacencyMatrix[E, V]) AddEdge ¶
func (am *AdjacencyMatrix[E, V]) AddEdge(fromNode, toNode V, weight E)
func (*AdjacencyMatrix[E, V]) AddNodes ¶
func (am *AdjacencyMatrix[E, V]) AddNodes(dataList ...V)
func (*AdjacencyMatrix[E, V]) CheckEdge ¶
func (am *AdjacencyMatrix[E, V]) CheckEdge(fromNode, toNode V) (reachable bool, weight E)
func (*AdjacencyMatrix[E, V]) GetMatrix ¶
func (am *AdjacencyMatrix[E, V]) GetMatrix() (matrix [][]E)
func (*AdjacencyMatrix[E, V]) GetVertexList ¶
func (am *AdjacencyMatrix[E, V]) GetVertexList() (vertexList []V)
func (*AdjacencyMatrix[E, V]) MatrixString ¶
func (am *AdjacencyMatrix[E, V]) MatrixString() string
func (*AdjacencyMatrix[E, V]) RemoveEdge ¶
func (am *AdjacencyMatrix[E, V]) RemoveEdge(fromNode, toNode V)
func (*AdjacencyMatrix[E, V]) RemoveNode ¶
func (am *AdjacencyMatrix[E, V]) RemoveNode(data V)
Click to show internal directories.
Click to hide internal directories.