graph

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction int

Direction represents the direction of an edge traversal.

const (
	Out  Direction = iota // Outgoing edges
	In                    // Incoming edges
	Both                  // Both directions
)

type Edge

type Edge struct {
	ID         EdgeID
	Type       uint16
	From       NodeID
	To         NodeID
	Properties map[string]any
}

Edge represents an edge in the property graph.

type EdgeID

type EdgeID uint32

EdgeID is the unique identifier for an edge.

type Graph

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

Graph is the top-level in-memory property graph.

func New

func New(s *schema.Schema) *Graph

New creates a new empty graph. If schema is non-nil, mutations are validated against it.

func (*Graph) CreateEdge

func (g *Graph) CreateEdge(edgeType string, from, to NodeID, props map[string]any) (EdgeID, error)

CreateEdge creates a new edge between two nodes.

func (*Graph) CreateNode

func (g *Graph) CreateNode(label, key string, props map[string]any) (NodeID, error)

CreateNode creates a new node. If a node with the same key exists, it upserts (merges properties).

func (*Graph) DeleteEdge

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

DeleteEdge removes an edge.

func (*Graph) DeleteNode

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

DeleteNode removes a node and all its connected edges.

func (*Graph) EdgeCount

func (g *Graph) EdgeCount() int

EdgeCount returns the number of active edges.

func (*Graph) EdgeTypeName

func (g *Graph) EdgeTypeName(id uint16) string

EdgeTypeName returns the string name for an edge type ID.

func (*Graph) EdgesByType

func (g *Graph) EdgesByType(edgeType string) []EdgeID

EdgesByType returns all edge IDs with the given type.

func (*Graph) GetEdge

func (g *Graph) GetEdge(id EdgeID) *Edge

GetEdge returns an edge by ID, or nil if it doesn't exist.

func (*Graph) GetNode

func (g *Graph) GetNode(id NodeID) *Node

GetNode returns a node by ID, or nil if it doesn't exist.

func (*Graph) GetNodeByKey

func (g *Graph) GetNodeByKey(key string) (*Node, bool)

GetNodeByKey returns a node by its unique key.

func (*Graph) LabelName

func (g *Graph) LabelName(id uint16) string

LabelName returns the string name for a label ID.

func (*Graph) Neighbors

func (g *Graph) Neighbors(id NodeID, edgeType string, dir Direction) []NodeID

Neighbors returns node IDs connected to the given node via edges of the specified type and direction. If edgeType is empty, all edge types are matched.

func (*Graph) NodeCount

func (g *Graph) NodeCount() int

NodeCount returns the number of active nodes.

func (*Graph) NodesByLabel

func (g *Graph) NodesByLabel(label string) []NodeID

NodesByLabel returns all node IDs with the given label.

func (*Graph) Schema

func (g *Graph) Schema() *schema.Schema

Schema returns the graph's schema (may be nil).

func (*Graph) SetProperty

func (g *Graph) SetProperty(id NodeID, key string, value any) error

SetProperty sets a property on a node.

func (*Graph) ShortestPath

func (g *Graph) ShortestPath(from, to NodeID) []NodeID

ShortestPath finds the shortest path between two nodes using BFS. Returns the path as a slice of node IDs (including start and end), or nil if no path exists.

func (*Graph) Traverse

func (g *Graph) Traverse(start NodeID, edgeType string, dir Direction, minHops, maxHops int) []NodeID

Traverse performs a variable-length traversal from a start node. It follows edges of the given type (or all if empty) up to maxHops. Returns all unique node IDs reached (excluding the start node).

type Node

type Node struct {
	ID         NodeID
	Label      uint16
	Key        string
	Properties map[string]any
}

Node represents a node in the property graph.

type NodeID

type NodeID uint32

NodeID is the unique identifier for a node.

Jump to

Keyboard shortcuts

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