graph

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: BSD-2-Clause Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Graph

type Graph[Schema any] struct {
	// contains filtered or unexported fields
}

func NewGraph

func NewGraph[Schema any](schemas []Schema, dependency [][]int) Graph[Schema]

func (Graph[Schema]) Get

func (g Graph[Schema]) Get(index int) Schema

Get returns the schema at the given index.

func (Graph[Schema]) Len

func (g Graph[Schema]) Len() int

Len returns the number of schemas in the graph.

func (Graph[Schema]) References

func (g Graph[Schema]) References(index int) []int

References returns the indexes of the schemas that the schema at index depends on.

func (Graph[Schema]) TopologicalSort

func (g Graph[Schema]) TopologicalSort() (orderedIndexes []int, cyclic bool)

TopologicalSort performs a topological sort on the graph. Returns (nil, true) if a cycle is detected in the graph. Otherwise, returns (orderedIndexes, false), where orderedIndexes is a slice of schema indexes sorted such that the index u comes after the index v for all dependencies (u, v), each of which is the relationship that the schema at the index v depends on the schema at the index u. Related description: https://en.wikipedia.org/wiki/Topological_sorting#Kahn's_algorithm

Jump to

Keyboard shortcuts

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