Documentation ¶
Overview ¶
Package groph is a simple graph database that can be loaded / stored from / to JSON and YAML files.
Refer to package parser to instructions about how to load a file as a graph.
Index ¶
- func PrintV(v *Vertex)
- type AnyData
- type Data
- type Edge
- type Edges
- func (es Edges) Each(f func(*Edge))
- func (es Edges) Filter(f func(*Edge) bool) (res Edges)
- func (es Edges) Fold(init interface{}, f func(a interface{}, b *Edge) interface{}) (cur interface{})
- func (es Edges) FromVertices() Vertices
- func (es Edges) Map(f func(*Edge) *Edge) (res Edges)
- func (es Edges) MapT(f func(*Edge) Data) (res *Results)
- func (es Edges) MapV(f func(*Edge) *Vertex) (res Vertices)
- func (es Edges) PointsToVertices() Vertices
- func (es Edges) Size() int
- type Graph
- func (g *Graph) AddConnection(s, t *Vertex, e *Edge)
- func (g *Graph) All(f func(*Vertex))
- func (g *Graph) BreadthFirst(id interface{}, f func(*Vertex))
- func (g *Graph) Filter(f func(*Vertex) bool) (vs Vertices)
- func (g *Graph) Find(id interface{}) (*Vertex, error)
- func (g *Graph) In(v *Vertex) []*Edge
- func (g *Graph) InWhereEdge(f func(*Edge) bool) (res []*Edge)
- func (g *Graph) InWhereVertex(f func(*Vertex) bool) (res []*Edge)
- func (g *Graph) NewEdge(d Data, weight float64) *Edge
- func (g *Graph) NewVertex(d Data) *Vertex
- func (g *Graph) NewVertexWithUpdate(d Data) *Vertex
- func (g *Graph) Out(v *Vertex) Edges
- func (g *Graph) OutWhereEdge(filterFunc func(*Edge) bool) (edges Edges)
- func (g *Graph) OutWhereVertex(f func(*Vertex) bool) (edges Edges)
- func (g *Graph) RootVertex() (v *Vertex, err error)
- func (g *Graph) SaveToDisk(filePath string) error
- func (g *Graph) SetRootVertex(r *Vertex)
- func (g *Graph) ShortestPath(id interface{}) (reversed Vertices, totalCost float64, err error)
- func (g *Graph) ShortestPathWithVertex(t *Vertex) (reversed []*Vertex, totalCost float64, err error)
- func (g *Graph) Traverse(f func(*Vertex))
- type Queue
- type Results
- type Vertex
- type Vertices
- func (vs Vertices) Each(f func(v *Vertex))
- func (vs Vertices) Filter(f func(v *Vertex) bool) (res Vertices)
- func (vs Vertices) FlatMap(f func(v *Vertex) Vertices) (res Vertices)
- func (vs Vertices) Fold(init interface{}, f func(a interface{}, b *Vertex) interface{}) (cur interface{})
- func (vs Vertices) InEdges() Edges
- func (vs Vertices) Map(f func(v *Vertex) *Vertex) (res Vertices)
- func (vs Vertices) MapE(f func(v *Vertex) *Edge) (res Edges)
- func (vs Vertices) MapT(f func(v *Vertex) Data) (res *Results)
- func (vs Vertices) OutEdges() Edges
- func (vs Vertices) Size() int
- type VerticesSlice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AnyData ¶
type AnyData struct { Data interface{} `json:"data, omitempty"` ID interface{} `json:"id, omitempty"` }
AnyData is a generic type to hold data within a vertex or an edge. One of its uses in the library is to parse unknown incoming data from a JSON or YAML file
type Data ¶
type Data interface { GetData() interface{} SetData(interface{}) GetID() interface{} SetID(interface{}) }
type Edge ¶
type Edges ¶
type Edges []*Edge
func (Edges) FromVertices ¶
func (Edges) PointsToVertices ¶
type Graph ¶
Graph is the main type to do queries and stores a vertex to be used as the starting point of any query. At the same time it maintains a map of known vertices
func (*Graph) AddConnection ¶
AddConnection connects two existing vertices with the provided edge
func (*Graph) BreadthFirst ¶
func (*Graph) InWhereEdge ¶
InWhereEdge traverses the entire graph and returns all inner edges that passes the filter function
func (*Graph) InWhereVertex ¶
InWhereVertex returns all inner edges that matches the filter function
func (*Graph) NewVertex ¶
NewVertex returns an initialized vertex with the provided data if it doesn't exists already or a pointer to the already existing one. Any contents incoming in 'd' are lost if the Vertex is found. If you want to update use 'NewVertexWithUpdate' instead.
func (*Graph) NewVertexWithUpdate ¶
NewVertexWithUpdate returns an initialized vertex with the provided data if it doesn't exists already or a pointer to the already existing one with the contents updated with the incoming data
func (*Graph) OutWhereEdge ¶
OutWhereEdge returns edges that matches specified filter
func (*Graph) OutWhereVertex ¶
OutWhereVertex returns edges that passes the provided filter
func (*Graph) RootVertex ¶
func (*Graph) SetRootVertex ¶
SetRootVertex changes the current root vertex. This is useful to initiate some specific searches from a particular vertex
func (*Graph) ShortestPath ¶
func (*Graph) ShortestPathWithVertex ¶
type Results ¶
type Results struct {
// contains filtered or unexported fields
}
func NewResults ¶
func NewResults() *Results
func (*Results) AddIfNotExists ¶
type Vertex ¶
type Vertex struct { Data `json:"data, omitempty"` // contains filtered or unexported fields }
type VerticesSlice ¶
type VerticesSlice []Vertices
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
Package parser provides function to read JSON and YAML files and convert them to a graph value.
|
Package parser provides function to read JSON and YAML files and convert them to a graph value. |