graph

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TopologicalSort

func TopologicalSort(vertices []*vertex.Vertex) ([]*vertex.Vertex, error)

TopologicalSort topologically sort the graph and return slice of the sorted vertices

Types

type Graph

type Graph struct {
	// Map with vertices to have an easy access to it
	VerticesMap map[string]*vertex.Vertex
	// List of all Vertices
	Vertices []*vertex.Vertex

	Providers map[string]reflect.Value

	// internal type
	InitialProviders map[string]reflect.Value
}

Graph manages the set of services and their edges type of the VerticesMap: directed

func NewGraph

func NewGraph() *Graph

NewGraph initializes endure Graph According to the topological sorting, graph should be 1. DIRECTED 2. ACYCLIC

func (*Graph) AddGlobalProvider

func (g *Graph) AddGlobalProvider(providedID string, val reflect.Value)

AddGlobalProvider adds provider to the global map in the Graph structure

func (*Graph) AddInterfaceDep

func (g *Graph) AddInterfaceDep(vertex *vertex.Vertex, depID string, method Kind, isRef bool) error

AddInterfaceDep doing the following: 1. Get a vertexID (foo2.S2 for example) 2. Get a depID --> could be vertexID of vertex dep ID like foo2.DB 3. Need to find vertexID to provide dependency. Example foo2.DB is actually foo2.S2 vertex

func (*Graph) AddStructureDep

func (g *Graph) AddStructureDep(vertex *vertex.Vertex, depID string, method Kind, isRef bool) error

func (*Graph) AddVertex

func (g *Graph) AddVertex(vertexID string, vertexIface any)

AddVertex adds an vertex to the graph with its ID, value and meta information

func (*Graph) ClearState

func (g *Graph) ClearState()

func (*Graph) FindProviders

func (g *Graph) FindProviders(depID string) *vertex.Vertex

FindProviders finds provider deps for the vertex and returns dependent vertices

func (*Graph) GetVertex

func (g *Graph) GetVertex(id string) *vertex.Vertex

GetVertex returns vertex by its ID

func (*Graph) HasVertex

func (g *Graph) HasVertex(name string) bool

HasVertex returns true or false if the vertex exists in the vertices map in the graph

func (*Graph) Reset

func (g *Graph) Reset(vrtx *vertex.Vertex) []*vertex.Vertex

Reset resets vertices to initial state

type Kind

type Kind int

Kind used to identify the method which invokes AddDeps

const (
	// Init method
	Init Kind = iota
	// Collects method
	Collects
)

Jump to

Keyboard shortcuts

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