graph

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: MIT Imports: 7 Imported by: 0

README

graph

Build Status Go Report Card GoDoc

Documentation

Index

Constants

View Source
const (

	// BFS is the constant for Breadth First Search
	BFS = iota

	// DFS is the constant for Depth First Search
	DFS = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DirectedEdge

type DirectedEdge interface {
	Edge
	Directional() bool
}

DirectedEdge is the interface that defines a directional edge in the graph

type DirectedWeightedEdge

type DirectedWeightedEdge interface {
	DirectedEdge
	Weight() float64
}

DirectedWeightedEdge is the interface that defines a directional weighted edge in the graph

type Edge

type Edge interface {
	Parent() *Node
	Child() *Node
	Value() interface{}
}

Edge is the interface that defines an edge in the graph

type Graphy

type Graphy struct {
	Directional bool
	Weighted    bool
	// contains filtered or unexported fields
}

Graphy is the graphy struct for building and searching the graph

func (*Graphy) AddEdge

func (g *Graphy) AddEdge(parent, child *Node, value interface{}, weight float64) (err error)

AddEdge adds a new edge to the graph between two nodes

func (*Graphy) AddNode

func (g *Graphy) AddNode(node *Node) (err error)

func (*Graphy) Bipartite

func (g *Graphy) Bipartite() (isBipartite bool)

Bipartite determines if the graph is bipartite

func (*Graphy) DAG

func (g *Graphy) DAG() (isDAG bool)

DAG determines if the graph that's build is a Directed Acyclic Graph

func (*Graphy) Export

func (g *Graphy) Export(ctx context.Context) string

func (*Graphy) Mutual

func (g *Graphy) Mutual(n1 Node, n2 Node) (mutual bool)

Mutual accepts two nodes of the graph and determines if they're mutually reachable

func (*Graphy) Node

func (g *Graphy) Node(value interface{}) (node *Node, err error)

Node adds a new node to the graph if it doesn't already exist and returns the node if the node already exists then it returns the node object from the map

func (*Graphy) Nodes

func (g *Graphy) Nodes(ctx context.Context) <-chan *Node

Nodes returns a full set of the nodes in the graph with their associated edges

func (*Graphy) RemoveEdge

func (g *Graphy) RemoveEdge(parent *Node, child *Node) (err error)

RemoveEdge removes an edge from the graph

func (*Graphy) RemoveNode

func (g *Graphy) RemoveNode(value interface{}) (err error)

RemoveNode removes a node from the graph and removes all edges that reference that node

func (*Graphy) Size

func (g *Graphy) Size() int

Size returns the current size of the graph

func (*Graphy) String

func (g *Graphy) String(ctx context.Context) string

func (*Graphy) Strong

func (g *Graphy) Strong() (isStrong bool)

Strong determines if the graph has strong connectivity

func (*Graphy) UpdateEdge

func (g *Graphy) UpdateEdge(parent *Node, child *Node, value interface{}, weight int) (err error)

UpdateEdge updates the information in an edge for the graph

type Heap

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

func (*Heap) ChangeCost

func (h *Heap) ChangeCost(value interface{}, parent *Node, cost float64)

func (*Heap) Delete

func (h *Heap) Delete(i int) (err error)

func (*Heap) DeleteElem

func (h *Heap) DeleteElem(value interface{}) (err error)

func (*Heap) Down

func (h *Heap) Down(i int)

func (*Heap) ExtractMin

func (h *Heap) ExtractMin() (min *Node, err error)

func (*Heap) Find

func (h *Heap) Find(value interface{}) (index int, err error)

func (*Heap) Insert

func (h *Heap) Insert(n *Node) (err error)

func (*Heap) Min

func (h *Heap) Min() (index int, err error)

func (*Heap) Print

func (h *Heap) Print()

func (*Heap) Size

func (h *Heap) Size() int

func (*Heap) Swap

func (h *Heap) Swap(i, j int)

func (*Heap) Up

func (h *Heap) Up(i int)

type Node

type Node struct {
	Value  interface{}
	Parent *Node
	Cost   float64
	// contains filtered or unexported fields
}

Node is the interface representation of a node in the graph

func (*Node) AddEdge

func (n *Node) AddEdge(relation *Node, edge Edge) (err error)

AddEdge adds an edge from this node to the related node

func (*Node) AllReachable

func (n *Node) AllReachable(ctx context.Context, alg int) <-chan *Node

AllReachable returns all of the nodes that are accessible from this node the algorithm passed in is based off of the algorithms defined in the CONST files for search constants. Defaults to BFS.

func (*Node) DirectMutual

func (n *Node) DirectMutual(node Node) (mutual bool)

DirectMutual determines if a specific node is directly mutual to this node

func (*Node) Edges

func (n *Node) Edges(ctx context.Context) <-chan Edge

Edges returns a channel which streams the edges for this node

func (*Node) Export

func (n *Node) Export(ctx context.Context) string

func (*Node) Reachable

func (n *Node) Reachable(ctx context.Context, alg int, node *Node) (reachable bool)

Reachable determines if a node is reachable from this node

func (*Node) String

func (n *Node) String(ctx context.Context) string

type WeightedEdge

type WeightedEdge interface {
	Edge
	Weight() float64
}

WeightedEdge is the interface that defines an undirected weighted edge in the graph

Jump to

Keyboard shortcuts

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