Documentation ¶
Overview ¶
Package util provides useful utilities for working with graphs.
Index ¶
- func Clipped(err error) int
- func CpWeights(dst groph.WGraph, src groph.RGraph) (dstout groph.WGraph, err error)
- func CpXWeights(dst groph.WGraph, src groph.RGraph, xf func(in interface{}) interface{}) (dstout groph.WGraph, err error)
- func FirstEdge(ofIdx int, akku, w interface{}) (sum interface{}, stop bool)
- func MergeEqual(w1, w2 interface{}) (interface{}, error)
- func MergeWeights(g groph.RGraph, merge func(w1, w2 interface{}) (merged interface{}, err error)) func(u, v groph.VIdx) (interface{}, error)
- func MustCp(g groph.WGraph, err error) groph.WGraph
- func ParseI32(s string) (interface{}, error)
- func ReadGraph(into groph.WGraph, rd io.Reader, wParse WeightParse) error
- func ReorderPath(slice interface{}, path []groph.VIdx)
- func WeightOr(g groph.RGraph, u, v groph.VIdx, or interface{}) interface{}
- func WriteSparse(wr io.Writer, g groph.RGraph) error
- type ClipError
- type MergeError
- type PointsNDist
- func (g *PointsNDist) Check() (*PointsNDist, error)
- func (g *PointsNDist) Must() *PointsNDist
- func (g *PointsNDist) Order() groph.VIdx
- func (g *PointsNDist) Vertex(idx groph.VIdx) interface{}
- func (g *PointsNDist) Weight(u, v groph.VIdx) interface{}
- func (g *PointsNDist) WeightU(u, v groph.VIdx) interface{}
- type RSubgraph
- type RUadapter
- type RUnion
- type SrcDstError
- type WSubgraph
- type WeightParse
- type WeightsSlice
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clipped ¶ added in v0.4.0
Clipped returns the clipping if err is a ClipError. Otherwise it returns 0.
func CpWeights ¶
CpWeights copies the edge weights from one graph to another. Vertices are identified by their index, i.e. the user has to take care of the vertex order. If the number of vertices in the graph differs the smaller graph determines how many edge weights are copied.
func CpXWeights ¶
func CpXWeights( dst groph.WGraph, src groph.RGraph, xf func(in interface{}) interface{}, ) (dstout groph.WGraph, err error)
CpXWeights “transfers” the edge weights from src Graph to dst Graph with the same vertex restrictions as CpWeights. CpXWeights applies the transformation function xf() to each edge weight.
Panic of xf will be recovered and returned as error.
func MergeEqual ¶
func MergeEqual(w1, w2 interface{}) (interface{}, error)
func MergeWeights ¶
func ReorderPath ¶ added in v0.5.0
TODO can this be done in place?
Example ¶
data := []string{"a", "b", "c", "d", "e"} path := []groph.VIdx{1, 3, 0, 4, 2} ReorderPath(data, path) fmt.Println(data)
Output: [b d a e c]
func WeightOr ¶ added in v0.4.0
WeightOr returns parameter 'or' when the edge (u,v) is not in graph g. Otherwise the weight of edge (u,v) is returned.
func WriteSparse ¶ added in v0.4.0
Example ¶
g := sliceofmaps.NewDInt32(4, nil) g.SetEdge(0, 1, 1) g.SetEdge(1, 2, 2) g.SetEdge(2, 3, 3) g.SetEdge(3, 0, 0) g.SetEdge(0, 2, -1) WriteSparse(os.Stdout, g)
Output: groph directed edges order=4 0 1 1 0 2 -1 1 2 2 2 3 3 3 0 0
Types ¶
type ClipError ¶ added in v0.4.0
type ClipError int
ClipError is returned when the order of src and dst in Cp*Weights does not match. If err is < 0 there were -err vertices ignored from src. If err > 0 then err vertices in dst were not covered.
type MergeError ¶
type MergeError struct {
// contains filtered or unexported fields
}
func (MergeError) Error ¶
func (e MergeError) Error() string
func (MergeError) Unwrap ¶
func (e MergeError) Unwrap() error
type PointsNDist ¶ added in v0.4.0
type PointsNDist struct {
// contains filtered or unexported fields
}
PointsNDist implements a metric RUndirected graph based on a slice of vertices of some type V and a symmetric function f(u V, v V) → W that computes the weight of type W for any edge (u, v).
From this use e.g. CpWeights or CpXWeights to initialize an other WGraph.
func NewPointsNDist ¶ added in v0.4.0
func NewPointsNDist(vertexSlice interface{}, measure interface{}) *PointsNDist
func (*PointsNDist) Check ¶ added in v0.4.0
func (g *PointsNDist) Check() (*PointsNDist, error)
Check does type checking on g. It always returns g. Only if everything is OK the returned error is nil.
func (*PointsNDist) Must ¶ added in v0.4.0
func (g *PointsNDist) Must() *PointsNDist
Verify call Check on g and panics if Check returns an error.
func (*PointsNDist) Order ¶ added in v0.4.0
func (g *PointsNDist) Order() groph.VIdx
func (*PointsNDist) Vertex ¶ added in v0.4.0
func (g *PointsNDist) Vertex(idx groph.VIdx) interface{}
func (*PointsNDist) Weight ¶ added in v0.4.0
func (g *PointsNDist) Weight(u, v groph.VIdx) interface{}
func (*PointsNDist) WeightU ¶ added in v0.4.0
func (g *PointsNDist) WeightU(u, v groph.VIdx) interface{}
type RUadapter ¶
type RUadapter struct { G groph.RGraph Merge func(u, v groph.VIdx) (merged interface{}, err error) Err error }
Example ¶
package main import ( "fmt" "git.fractalqb.de/fractalqb/groph/adjmatrix" "git.fractalqb.de/fractalqb/groph" ) var _ groph.RUndirected = (*RUadapter)(nil) func main() { ws := NewWeightsSlice([]int32{1, 2, 3, 4}) u := adjmatrix.NewUInt32(ws.Order(), adjmatrix.I32Del, nil) _, err := CpWeights(u, ws) fmt.Println("copy error:", err) rua := RUadapter{G: ws, Merge: MergeWeights(ws, MergeEqual)} _, err = CpWeights(u, &rua) fmt.Println("copy error:", err) fmt.Println("rua error:", rua.Err) }
Output: copy error: cannot copy from directed to undirected graph copy error: source: edges 1, 0: not equal: '3' / '2' rua error: edges 1, 0: not equal: '3' / '2'
type RUnion ¶ added in v0.5.0
type SrcDstError ¶ added in v0.4.0
SrcDstError is returned when an error occurred in the src or dst graph during Cp*Weights.
func (SrcDstError) Error ¶ added in v0.4.0
func (err SrcDstError) Error() string
type WeightParse ¶ added in v0.4.0
type WeightsSlice ¶ added in v0.4.0
type WeightsSlice struct {
// contains filtered or unexported fields
}
func NewWeightsSlice ¶ added in v0.4.0
func NewWeightsSlice(edgeSlice interface{}) *WeightsSlice
func (*WeightsSlice) Check ¶ added in v0.4.0
func (g *WeightsSlice) Check() (*WeightsSlice, error)
func (*WeightsSlice) Must ¶ added in v0.4.0
func (g *WeightsSlice) Must() *WeightsSlice
func (*WeightsSlice) Order ¶ added in v0.4.0
func (g *WeightsSlice) Order() groph.VIdx
func (*WeightsSlice) Weight ¶ added in v0.4.0
func (g *WeightsSlice) Weight(u, v groph.VIdx) interface{}