graph

package
v1.4.4-alpha1202-loadi... Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildGraphWithDFS

func BuildGraphWithDFS[K comparable, T comparable](
	ctx context.Context,
	startNode T,
	getNodeKey func(T) (K, error),
	getNeighbors func(T) []*Neighbor[T],
	handleEdge func(from K, to K, edgeType string, extraMsg map[string]any),
) error

func GraphPath

func GraphPath[T comparable](
	node T,
	next func(T) []T,
) [][]T

index by T type , and return path with T type

func GraphPathEx

func GraphPathEx[K comparable, T, U any](
	ctx context.Context,
	node T,
	next func(T) []T,
	getKey func(T) K,
	getValue func(T) U,
	target ...T,
) [][]U

func GraphPathWithKey

func GraphPathWithKey[K comparable, T any](
	node T,
	next func(T) []T,
	getKey func(T) K,
) [][]T

index by K type, and return path with T type

func GraphPathWithTarget

func GraphPathWithTarget[T comparable](
	ctx context.Context,
	node T,
	target T,
	next func(T) []T,
) [][]T

func GraphPathWithValue

func GraphPathWithValue[T comparable, U any](
	node T,
	next func(T) []T,
	getValue func(T) U,
) [][]U

index by T type, and return path with U type

Types

type DFSGraphBuilder

type DFSGraphBuilder[K, T comparable] struct {
	// contains filtered or unexported fields
}

DFSGraphBuilder is a utility struct to construct a graph using Depth-First Search (DFS) traversal.

func NewDFSGraphBuilder

func NewDFSGraphBuilder[K comparable, T comparable](
	ctx context.Context,
	getNodeKey func(T) (K, error),
	getNeighbors func(T) []*Neighbor[T],
	handleEdge func(from K, to K, edgeType string, extraMsg map[string]any),
) *DFSGraphBuilder[K, T]

func (*DFSGraphBuilder[K, T]) BuildGraph

func (g *DFSGraphBuilder[K, T]) BuildGraph(startNode T) error

BuildGraph Depth-First Search driven graph construction method

func (*DFSGraphBuilder[K, T]) GetVisited

func (g *DFSGraphBuilder[K, T]) GetVisited(node T) (key K, ok bool)

type DeepFirstPath

type DeepFirstPath[K comparable, T, U any] struct {
	// contains filtered or unexported fields
}

deep first search for nodeID and its children to [][]id, id is string, if node.Prev have more than one, add a new line

type Neighbor

type Neighbor[T any] struct {
	// The neighboring node
	Node T
	// The type of edge connecting the current node to the neighbor
	EdgeType string
	ExtraMsg map[string]any
}

Neighbor Structure combining neighboring nodes with their edge types

func NewNeighbor

func NewNeighbor[T any](node T, edgeType string) *Neighbor[T]

func (*Neighbor[T]) AddExtraMsg

func (n *Neighbor[T]) AddExtraMsg(k string, v any)

Jump to

Keyboard shortcuts

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