sqlitegraph

package module
v0.0.0-...-7a8e9ca Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2018 License: GPL-3.0 Imports: 7 Imported by: 0

README

go-sqlite-graph

Build Status GoDoc Go Report Card codecov

Save graphs and trees to a sqlite database

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

type Edge struct {
	ID   int
	From int
	To   int
	Text string
}

Edge is the data structure to connect nodes inside the graph.

func NewEdge

func NewEdge(id, from, to int) *Edge

NewEdge creates and returns a new edge from a given start and end node id

func (*Edge) Equals

func (e *Edge) Equals(e2 *Edge) bool

type Graph

type Graph struct {
	Root  *Node
	Nodes []*Node
	Edges []*Edge
}

Graph holds the data of the graph with all it's Nodes and edges.

func NewGraph

func NewGraph() *Graph

NewGraph creates a new graph containig only the root Node

func (*Graph) AddEdge

func (g *Graph) AddEdge(e *Edge) error

AddEdge adds a Node to the graph

func (*Graph) AddNode

func (g *Graph) AddNode(n *Node) error

AddNode adds a Node to the graph

func (*Graph) ChildsOf

func (g *Graph) ChildsOf(n int) []int

ChildsOf finds the childs of a node

func (*Graph) DeleteEdge

func (g *Graph) DeleteEdge(id int) error

DeleteEdge deletes an edge from the graph if it is present

func (*Graph) DeleteNode

func (g *Graph) DeleteNode(id int) error

DeleteNode deletes an Node from the graph if it is present

func (*Graph) Empty

func (g *Graph) Empty() bool

Empty returns true if the root Node is the only Node in the graph, false otherwise

func (Graph) Equal

func (g Graph) Equal(g2 *Graph) bool

Check if two graphs are the same

func (*Graph) FindEdgeByID

func (g *Graph) FindEdgeByID(ID int) (*Edge, error)

FindEdgeByID finds a Edge in the graph by it's ID

func (*Graph) FindEdgesFromTo

func (g *Graph) FindEdgesFromTo(IDFrom, IDTo int) []*Edge

FindEdgesFromTo finds an endge in the graph by it's start and end

func (*Graph) FindNodeByID

func (g *Graph) FindNodeByID(ID int) (*Node, error)

FindNodeByID finds a node in the graph by it's ID

func (*Graph) FindSubGraph

func (g *Graph) FindSubGraph(startIDs, endIDs []int) (*Graph, error)

FindSubGraph returns a subset of the graph (a subgraph) with the shortest way from the start nodes to the end nodes if possible. If no possible connection is found, an error is returned

func (*Graph) Load

func (g *Graph) Load(path string) error

Load loads a graph from a sqlite database specified by the path

func (*Graph) ParentsOf

func (g *Graph) ParentsOf(n int) []int

ParentsOf finds the parents of a node

func (*Graph) PrintGraphviz

func (g *Graph) PrintGraphviz() error

PrintGraphviz generates a graph in the dot language to be visualized using graphviz

func (*Graph) Save

func (g *Graph) Save(path string) error

Save saves the graph to a sqlite database specified by the path

func (Graph) ToString

func (g Graph) ToString() string

type Node

type Node struct {
	ID   int
	Text string
}

Node is the basic data structure of the graph.

func NewNode

func NewNode(id int) *Node

NewNode creates a new Node with a given id

func (*Node) Equals

func (n *Node) Equals(n2 *Node) bool

Jump to

Keyboard shortcuts

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