Package graph

Dependencies

  • eudaimonia/uuid

Types

Graph

graph/graph.go
type Graph struct {
        // Has unexported fields.
}

Node

graph/graph.go
type Node struct {
        Id         uuid.UUID      `json:"id"`
        Labels     []string       `json:"labels,omitempty"`
        Properties map[string]any `json:"properties,omitempty"`
}

Edge

graph/graph.go
type Edge struct {
        Id         uuid.UUID      `json:"id"`
        Type       string         `json:"type,omitempty"`
        From       uuid.UUID      `json:"from"`
        To         uuid.UUID      `json:"to"`
        Properties map[string]any `json:"properties,omitempty"`
}

Functions

NewGraph

graph/graph.go
func NewGraph() *Graph

Creates a new graph.

graph.NewNode

graph/graph.go
func (g *Graph) NewNode() *Node

Creates a new node.

graph.ContainsNode

graph/graph.go
func (g *Graph) ContainsNode(n *Node) bool

Parameters:

  • v: Checks if g contains the vertex v.

Returns:

  • true if v is in g.

  • false if v is not in g.

Example:

g := graph.NewGraph()
n := g.NewNode()
fmt.Println(g.Contains(n)) // true

graph.GetNodes

graph/graph.go
func (g *Graph) GetNodes() []*Node

Returns all nodes within the graph g.

graph.InsertDirectedEdge

graph/graph.go
func (g *Graph) InsertDirectedEdge(src, dst *Node) (*Edge, error)

Returns:

  • nil if the operation was successful.

  • error:

    • If either src or dst does not exist within g.

    • If the edge already exists in g.

graph.ContainsEdge

graph/graph.go
func (g *graph) ContainsEdge(e *Edge) bool

Parameters:

  • e: Checks if g contains the edge e.

Returns:

  • true if e is in g.

  • false if e is not in g.

Example:

g := graph.NewGraph()
v := g.NewNode()
w := g.NewNode()
e := g.InsertDirectedEdge(v, w)
fmt.Println(g.ContainsEdge(e)) // true

graph.GetPath

graph/graph.go
=== func (g *Graph) GetPath(src, dst *Node) ([]*Node, error)

Returns the path from the source node to the destination node.

Parameters:

  • src: The source node of the path.

  • dst: The destination node of the path.

Returns:

Returns an array of *Node, including src and dst or an error if src or dst are not in g or there is no path connecting them.

graph.UnmarshalJSON

graph/graph.go
func (g *Graph) UnmarshalJSON(data []byte) error

graph.MarshalJSON

graph/graph.go
func (g *Graph) MarshalJSON() ([]byte, error)