graph

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DGraph

type DGraph struct {
	Nodes  []*Node
	Edges  EdgeList
	Layers []*Layer
}

func (*DGraph) ConnectedComponents added in v0.10.0

func (g *DGraph) ConnectedComponents() []*DGraph

func (*DGraph) GetEdges

func (g *DGraph) GetEdges() []*Edge

func (*DGraph) GetNodes

func (g *DGraph) GetNodes() []*Node

func (*DGraph) Populate

func (g *DGraph) Populate(*DGraph)

func (*DGraph) Sinks

func (g *DGraph) Sinks() iter.Seq[*Node]

Sinks returns a list of nodes with no outgoing edges

func (*DGraph) Sources

func (g *DGraph) Sources() iter.Seq[*Node]

Sources returns a sequence of nodes with no incoming edges

func (*DGraph) VirtualNodes added in v0.10.0

func (g *DGraph) VirtualNodes() iter.Seq[*Node]

type Edge

type Edge struct {
	// contains filtered or unexported fields
}

func NewEdge

func NewEdge(from, to *Node, weight int) *Edge

func (*Edge) ConnectedNode

func (e *Edge) ConnectedNode(n *Node) *Node

func (*Edge) Crosses

func (e *Edge) Crosses(f *Edge) bool

func (*Edge) IsFlat

func (e *Edge) IsFlat() bool

func (*Edge) Reverse

func (e *Edge) Reverse()

func (*Edge) SelfLoops

func (e *Edge) SelfLoops() bool

func (*Edge) String

func (e *Edge) String() string

func (*Edge) Type

func (e *Edge) Type() EdgeType

Type returns the edge's EdgeType

type EdgeIntMap

type EdgeIntMap = hashmap[*Edge, int]

type EdgeList

type EdgeList []*Edge

func (*EdgeList) Add

func (list *EdgeList) Add(e *Edge)

func (*EdgeList) Remove

func (list *EdgeList) Remove(e *Edge)

type EdgeSet

type EdgeSet = hashmap[*Edge, bool]

type EdgeSlice added in v0.10.0

type EdgeSlice [][]string

EdgeSlice is a graph Source.

func (EdgeSlice) Populate added in v0.10.0

func (edges EdgeSlice) Populate(g *DGraph)

type EdgeType added in v0.9.0

type EdgeType uint8

EdgeType encodes information about the nodes adjacent to an edge,

const (
	// EdgeTypeConcrete indicates a type 0 edge whose adjacent nodes are both non-virtual.
	EdgeTypeConcrete EdgeType = iota
	// EdgeTypeHybrid indicates a type 1 edge whose adjacent nodes are one virtual and one non-virtual.
	EdgeTypeHybrid
	// EdgeTypeVirtual indicates a type 2 edge whose adjacent nodes are both virtual.
	EdgeTypeVirtual
)

type Layer

type Layer struct {
	Nodes []*Node
	Index int
	Size
}

func (*Layer) Head added in v0.9.0

func (layer *Layer) Head() *Node

Head returns the first node in this layer, i.e. the node with index 0

func (*Layer) Len

func (layer *Layer) Len() int

func (*Layer) String

func (layer *Layer) String() string

func (*Layer) Tail

func (layer *Layer) Tail() *Node

Tail returns the last node in this layer, i.e. the node with the greatest index

type Node

type Node struct {
	ID        string
	In, Out   EdgeList
	Layer     int
	LayerPos  int
	IsVirtual bool

	// Size stores the dimensions of the node and its computed (x,y) coordinates.
	// The point (x,y) is the top-left corner of the node, and (0,0) is the top-left corner of the drawing plane.
	Size
	// contains filtered or unexported fields
}

func (*Node) Deg

func (n *Node) Deg() int

Deg returns the total number of incoming and outgoing edges

func (*Node) Indeg

func (n *Node) Indeg() int

Indeg returns the number of incoming edges

func (*Node) Outdeg

func (n *Node) Outdeg() int

Outdeg returns the number of outgoing edges

func (*Node) SVG added in v0.9.0

func (n *Node) SVG() string

func (*Node) String

func (n *Node) String() string

func (*Node) VisitEdges

func (n *Node) VisitEdges(visit func(*Edge))

type NodeFloatMap

type NodeFloatMap = hashmap[*Node, float64]

type NodeIntMap

type NodeIntMap = hashmap[*Node, int]

type NodeList

type NodeList []*Node

type NodeMap

type NodeMap = hashmap[*Node, *Node]

type NodeSet

type NodeSet = hashmap[*Node, bool]

type OptionNsBalance

type OptionNsBalance uint8

OptionNsBalance controls which balancing strategy to use in the network simplex layerer.

const (
	// OptionNsBalanceV represents vertical balancing in network simplex solver. Default value used in phase 2.
	OptionNsBalanceV OptionNsBalance = iota + 1
	// OptionNsBalanceH represents horizontal balancing in network simplex solver. Used in phase 4 NetworkSimplex positioner.
	OptionNsBalanceH
)

type Params

type Params struct {

	// Sets the same width and height to all non-virtual nodes
	NodeFixedSizeFunc func(n *Node)

	// Sets a width and height to individual non-virtual nodes
	NodeSizeFunc func(n *Node)

	// Controls whether the next maximum outflow node in the greedy cycle breaker is picked at random.
	// When this option is true, the greedy cycle breaker behaves non-deterministically.
	GreedyCycleBreakerRandomNodeChoice bool

	// Factor used in to determine the maximum number of iterations.
	NetworkSimplexThoroughness uint
	// If positive, factor by which thoroughness is multiplied to determine the maximum number of iterations.
	// Otherwise, ignored.
	NetworkSimplexMaxIterFactor int
	// Controls which balancing strategy to use in the network simplex layering by moving nodes to less crowded layers.
	NetworkSimplexBalance OptionNsBalance

	// Size of virtual nodes (NxN). Defaults to zero, i.e. virtual nodes are treated as points.
	VirtualNodeFixedSize float64

	// Maximum number of iterations of the WMedian orderer.
	WMedianMaxIter uint

	// Spacing between layers (above and below).
	LayerSpacing float64
	// Spacing between nodes (left and right).
	NodeSpacing float64
	// Weight factor for edges in the network simplex positioner.
	NetworkSimplexAuxiliaryGraphWeightFactor int
	// Allows choosing one of the four B&K layouts. The accepted values are: 0: bottom-right, 1: bottom-left, 2: top-right, 3: top-left.
	// The directions refer to the direction in which the algorithm sweeps layers and nodes. Different directions
	// result in different aligmnent priorities, and therefore in different positioning.
	// In case the inequality 0 <= v < 4 doesn't hold, the default balanced layout is used instead.
	BrandesKoepfLayout int
}

Params holds parameters and options that are used by the layout algorithms and don't strictly belong to the graph itself

type Size

type Size struct {
	X, Y, W, H float64
}

type Source added in v0.10.0

type Source interface {
	Populate(*DGraph)
}

Source represent the source of graph data. It hides the implementation details of the internal DGraph struct and allows only this module to provide implementations.

Jump to

Keyboard shortcuts

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