graph

package
v0.0.0-...-a09f9a9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal[T comparable](a, b Graph[T]) bool

Equal returns true if graph a and graph b meet the following rules, otherwise, it returns false:

  • a.IsDirected() == b.IsDirected()
  • a.AllowsSelfLoops() == b.AllowsSelfLoops()
  • a.Nodes() and b.Nodes() are equal according to set.Equal
  • a.Edges() and b.Edges() are equal according to set.Equal

This method should be used over ==, the behaviour of which is undefined.

Equal itself follows these rules:

  • Reflexive: for any potentially-nil graph a, Equal(a, a) returns true.
  • Symmetric: for any potentially-nil graphs a and b, Equal(a, b) and Equal(b, a) have the same results.
  • Transitive: for any potentially-nil graphs a, b and c, if Equal(a, b) and Equal(b, c), then Equal(a, c) is true.
  • Consistent: for any potentially-nil graphs a and b, multiple calls to Equal(a, b) consistently returns true or consistently returns false, as long as the graphs do not change.

Types

type Builder

type Builder[N comparable] struct {
	// contains filtered or unexported fields
}

func Directed

func Directed[N comparable]() Builder[N]

func Undirected

func Undirected[N comparable]() Builder[N]

func (Builder[N]) AllowsSelfLoops

func (b Builder[N]) AllowsSelfLoops(allowsSelfLoops bool) Builder[N]

func (Builder[N]) Build

func (b Builder[N]) Build() MutableGraph[N]

type EndpointPair

type EndpointPair[N comparable] struct {
	// contains filtered or unexported fields
}

func EndpointPairOf

func EndpointPairOf[N comparable](source N, target N) EndpointPair[N]

func (EndpointPair[N]) AdjacentNode

func (e EndpointPair[N]) AdjacentNode(node N) N

func (EndpointPair[N]) Source

func (e EndpointPair[N]) Source() N

func (EndpointPair[N]) String

func (e EndpointPair[N]) String() string

func (EndpointPair[N]) Target

func (e EndpointPair[N]) Target() N

type Graph

type Graph[N comparable] interface {
	Nodes() set.Set[N]
	Edges() set.Set[EndpointPair[N]]
	IsDirected() bool
	AllowsSelfLoops() bool
	AdjacentNodes(node N) set.Set[N]
	Predecessors(node N) set.Set[N]
	Successors(node N) set.Set[N]
	IncidentEdges(node N) set.Set[EndpointPair[N]]
	Degree(node N) int
	InDegree(node N) int
	OutDegree(node N) int
	HasEdgeConnecting(source N, target N) bool
	HasEdgeConnectingEndpoints(endpointPair EndpointPair[N]) bool
	String() string
}

type MutableGraph

type MutableGraph[N comparable] interface {
	Graph[N]

	AddNode(node N) bool
	PutEdge(source N, target N) bool
	RemoveNode(node N) bool
	RemoveEdge(source N, target N) bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL