graph

package
v0.0.0-...-d6e2918 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 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 Graph

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

Graph is a graph of connected Nodes

func New

func New(nodeNeighbors [][]Node) *Graph

New creates a new Graph

nodeNeighbors is a list of neighbors where the index is the node id and the value is that node's neighbors

func (*Graph) FindLevels

func (g *Graph) FindLevels(source Node) []int

FindLevels returns the hop count of each node in the graph

func (*Graph) FindPath

func (g *Graph) FindPath(path *[]Node, maxPathLength int, source, dest Node, priorityFn PriorityFunc)

FindPath finds the shortest path from source to dest

When there are multiple shortest paths, FindPath may return any one of those paths.
The first element of the returned path is always source, and the last element is always dest.
path - is a pointer to a slice that FindPath will set to the found path
When no path is found, path will be set to zero length

func (*Graph) GobDecode

func (g *Graph) GobDecode(p []byte) error

GobDecode implements gob.GobDecoder

func (*Graph) GobEncode

func (g *Graph) GobEncode() ([]byte, error)

GobEncode implements gob.GobEncoder

func (*Graph) NodeNeighbors

func (g *Graph) NodeNeighbors(n Node) []Node

NodeNeighbors returns n's immediate neighbors

type Node

type Node uint32

Node is a graph node

type PriorityFunc

type PriorityFunc func(node Node) int64

PriorityFunc returns a node's priority when choosing between nodes. This is not cost.

The shortest path still wins no matter the priority. Higher number is higher priority. 2 gets
chosen before 1.

Jump to

Keyboard shortcuts

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