Move Subgraph into heartwood package as EventSubgraph.

This commit is contained in:
Jay
2026-03-03 16:22:02 -05:00
parent d87ec421db
commit c4cc7115b3
4 changed files with 58 additions and 64 deletions

View File

@@ -161,54 +161,6 @@ func (r *Relationship) Serialize() *SerializedRel {
return &srel
}
// ========================================
// Simple Subgraph
// ========================================
// Subgraph represents a simple collection of nodes and relationships.
type Subgraph struct {
// The nodes in the subgraph.
nodes []*Node
// The relationships in the subgraph.
rels []*Relationship
}
// NewSubgraph creates an empty subgraph.
func NewSubgraph() *Subgraph {
return &Subgraph{
nodes: []*Node{},
rels: []*Relationship{},
}
}
// AddNode adds a node to the subgraph
func (s *Subgraph) AddNode(node *Node) {
s.nodes = append(s.nodes, node)
}
// AddRel adds a relationship to the subgraph.
func (s *Subgraph) AddRel(rel *Relationship) {
s.rels = append(s.rels, rel)
}
func (s *Subgraph) Nodes() []*Node {
return s.nodes
}
func (s *Subgraph) Rels() []*Relationship {
return s.rels
}
func (s *Subgraph) NodesByLabel(label string) []*Node {
nodes := []*Node{}
for _, node := range s.nodes {
if node.Labels.Contains(label) {
nodes = append(nodes, node)
}
}
return nodes
}
// ========================================
// Structured Subgraph
// ========================================