Documentation
¶
Index ¶
- Variables
- type AdaptivePersister
- type Degree
- type Graph
- type IndexedGraph
- func (g *IndexedGraph) AddEdge(from, to, relationship string) error
- func (g *IndexedGraph) AddNode(nodeID string, nodeType string) error
- func (g *IndexedGraph) Clear() error
- func (g *IndexedGraph) CommonNeighbors(nodeA, nodeB string) ([]string, error)
- func (g *IndexedGraph) EdgeCount() int
- func (g *IndexedGraph) FindPath(from, to string, maxDepth int) ([]string, error)
- func (g *IndexedGraph) GetAllNodes() []string
- func (g *IndexedGraph) GetDegree(nodeID string) (Degree, error)
- func (g *IndexedGraph) GetIncomingEdges(nodeID string) (map[string]string, error)
- func (g *IndexedGraph) GetNeighbors(nodeID string) (map[string]string, error)
- func (g *IndexedGraph) GetNodeInfo(nodeID string) (*NodeInfo, error)
- func (g *IndexedGraph) GetNodesByType(entityType string) []string
- func (g *IndexedGraph) HasCycle() bool
- func (g *IndexedGraph) Load(filename string) error
- func (g *IndexedGraph) LoadIndex(filename string) error
- func (g *IndexedGraph) NodeCount() int
- func (g *IndexedGraph) NodeExists(nodeID string) bool
- func (g *IndexedGraph) PathExists(from, to string, maxDepth int) (bool, int, error)
- func (g *IndexedGraph) RemoveEdge(from, to string) error
- func (g *IndexedGraph) RemoveNode(nodeID string) error
- func (g *IndexedGraph) Save(filename string) error
- func (g *IndexedGraph) SaveIndex(filename string) error
- func (g *IndexedGraph) SetCycleDetection(mode string)
- func (g *IndexedGraph) UpdateFromEntity(entity string, id int, data map[string]interface{}) error
- type NodeInfo
Constants ¶
This section is empty.
Variables ¶
var ErrCycleDetected = errors.New("adding this edge would create a cycle")
ErrCycleDetected is returned when adding an edge would create a cycle
Functions ¶
This section is empty.
Types ¶
type AdaptivePersister ¶
type AdaptivePersister struct {
// contains filtered or unexported fields
}
AdaptivePersister handles graph persistence with adaptive timing. Under high write load, saves are batched to reduce I/O. Under low load, changes persist quickly.
func NewAdaptivePersister ¶
func NewAdaptivePersister(g Graph, filename string, logger zerolog.Logger) *AdaptivePersister
NewAdaptivePersister creates a new adaptive persister
func (*AdaptivePersister) MarkDirty ¶
func (p *AdaptivePersister) MarkDirty()
MarkDirty signals that the graph has been modified. Call this after UpdateFromEntity.
func (*AdaptivePersister) Start ¶
func (p *AdaptivePersister) Start()
Start begins the background persistence loop
func (*AdaptivePersister) Stats ¶
func (p *AdaptivePersister) Stats() map[string]interface{}
Stats returns current persister statistics
func (*AdaptivePersister) Stop ¶
func (p *AdaptivePersister) Stop()
Stop gracefully shuts down, ensuring final save
func (*AdaptivePersister) WriterEnter ¶
func (p *AdaptivePersister) WriterEnter()
WriterEnter increments active writer count. Call at the start of a write operation.
func (*AdaptivePersister) WriterExit ¶
func (p *AdaptivePersister) WriterExit()
WriterExit decrements active writer count. Call at the end of a write operation (defer recommended).
type Graph ¶
type Graph interface {
AddNode(nodeID string, nodeType string) error
RemoveNode(nodeID string) error
AddEdge(from, to, relationship string) error
RemoveEdge(from, to string) error
GetNeighbors(nodeID string) (map[string]string, error)
GetIncomingEdges(nodeID string) (map[string]string, error)
FindPath(from, to string, maxDepth int) ([]string, error)
HasCycle() bool
Save(filename string) error
Load(filename string) error
Clear() error
UpdateFromEntity(entity string, id int, data map[string]interface{}) error
}
Graph interface defines graph operations
type IndexedGraph ¶
type IndexedGraph struct {
// contains filtered or unexported fields
}
IndexedGraph implements an indexed graph with adjacency lists
func NewIndexedGraph ¶
func NewIndexedGraph() *IndexedGraph
NewIndexedGraph creates a new indexed graph
func NewIndexedGraphWithCycleDetection ¶
func NewIndexedGraphWithCycleDetection(mode string) *IndexedGraph
NewIndexedGraphWithCycleDetection creates a new indexed graph with cycle detection mode
func (*IndexedGraph) AddEdge ¶
func (g *IndexedGraph) AddEdge(from, to, relationship string) error
AddEdge adds a directed edge between nodes
func (*IndexedGraph) AddNode ¶
func (g *IndexedGraph) AddNode(nodeID string, nodeType string) error
AddNode adds a node to the graph
func (*IndexedGraph) CommonNeighbors ¶
func (g *IndexedGraph) CommonNeighbors(nodeA, nodeB string) ([]string, error)
CommonNeighbors finds nodes that are neighbors of both nodeA and nodeB
func (*IndexedGraph) EdgeCount ¶
func (g *IndexedGraph) EdgeCount() int
EdgeCount returns the number of edges in the graph
func (*IndexedGraph) FindPath ¶
func (g *IndexedGraph) FindPath(from, to string, maxDepth int) ([]string, error)
FindPath finds a path between two nodes using BFS
func (*IndexedGraph) GetAllNodes ¶
func (g *IndexedGraph) GetAllNodes() []string
GetAllNodes returns all node IDs in the graph
func (*IndexedGraph) GetDegree ¶
func (g *IndexedGraph) GetDegree(nodeID string) (Degree, error)
GetDegree returns the in-degree, out-degree, and total degree of a node
func (*IndexedGraph) GetIncomingEdges ¶
func (g *IndexedGraph) GetIncomingEdges(nodeID string) (map[string]string, error)
GetIncomingEdges returns all incoming edges to a node
func (*IndexedGraph) GetNeighbors ¶
func (g *IndexedGraph) GetNeighbors(nodeID string) (map[string]string, error)
GetNeighbors returns all outgoing neighbors of a node
func (*IndexedGraph) GetNodeInfo ¶
func (g *IndexedGraph) GetNodeInfo(nodeID string) (*NodeInfo, error)
func (*IndexedGraph) GetNodesByType ¶
func (g *IndexedGraph) GetNodesByType(entityType string) []string
GetNodesByType returns all nodes of a given entity type
func (*IndexedGraph) HasCycle ¶
func (g *IndexedGraph) HasCycle() bool
HasCycle checks if the graph has a cycle using DFS
func (*IndexedGraph) Load ¶
func (g *IndexedGraph) Load(filename string) error
Load loads the graph from a file in JSON format
func (*IndexedGraph) LoadIndex ¶
func (g *IndexedGraph) LoadIndex(filename string) error
LoadIndex loads the graph index from a file Deprecated: Use Load() which now loads all graph data including index
func (*IndexedGraph) NodeCount ¶
func (g *IndexedGraph) NodeCount() int
NodeCount returns the number of nodes in the graph
func (*IndexedGraph) NodeExists ¶
func (g *IndexedGraph) NodeExists(nodeID string) bool
NodeExists checks if a node exists in the graph
func (*IndexedGraph) PathExists ¶
PathExists checks if a path exists between two nodes within maxDepth
func (*IndexedGraph) RemoveEdge ¶
func (g *IndexedGraph) RemoveEdge(from, to string) error
RemoveEdge removes an edge between nodes
func (*IndexedGraph) RemoveNode ¶
func (g *IndexedGraph) RemoveNode(nodeID string) error
RemoveNode removes a node and all its edges
func (*IndexedGraph) Save ¶
func (g *IndexedGraph) Save(filename string) error
Save saves the graph to a file in JSON format
func (*IndexedGraph) SaveIndex ¶
func (g *IndexedGraph) SaveIndex(filename string) error
SaveIndex saves the graph index to a file Deprecated: Use Save() which now persists all graph data including index
func (*IndexedGraph) SetCycleDetection ¶
func (g *IndexedGraph) SetCycleDetection(mode string)
SetCycleDetection sets the cycle detection mode
func (*IndexedGraph) UpdateFromEntity ¶
func (g *IndexedGraph) UpdateFromEntity(entity string, id int, data map[string]interface{}) error
UpdateFromEntity updates the graph based on entity data
type NodeInfo ¶
type NodeInfo struct {
ID string `json:"id"`
Entity string `json:"entity"`
EntityID int `json:"entity_id"`
Outgoing map[string]string `json:"outgoing"` // neighbor -> relationship
Incoming map[string]string `json:"incoming"` // neighbor -> relationship
Degree Degree `json:"degree"`
}
GetNodeInfo returns comprehensive info about a node