Documentation
¶
Overview ¶
Package graph provides core data structures and interfaces for the gograph database. It includes Node, Relationship, and Property types along with utilities for indexing and adjacency list management.
Package graph provides core data structures and interfaces for the gograph database.
Package graph provides core data structures and interfaces for the gograph database.
Package graph provides core data structures and interfaces for the gograph database.
Package graph provides core data structures and interfaces for the gograph database.
Package graph provides core data structures and interfaces for the gograph database.
Package graph provides core data structures and interfaces for the gograph database.
Package graph provides core data structures and interfaces for the gograph database.
Index ¶
- func EncodePropertyValue(v PropertyValue) string
- func GenerateID(prefix string) string
- func SetIDCounter(counter uint64)
- type AdjacencyList
- func (adj *AdjacencyList) AddRelationship(m Mutator, rel *Relationship) error
- func (adj *AdjacencyList) GetAllRelated(nodeID string) ([]string, error)
- func (adj *AdjacencyList) GetRelatedNodes(nodeID, relType string, direction Direction) ([]string, error)
- func (adj *AdjacencyList) RemoveRelationship(m Mutator, rel *Relationship) error
- type Direction
- type Index
- func (idx *Index) BuildLabelIndex(m Mutator, node *Node) error
- func (idx *Index) BuildPropertyIndex(m Mutator, node *Node) error
- func (idx *Index) LookupByLabel(label string) ([]string, error)
- func (idx *Index) LookupByProperty(label, propName, propValue string) ([]string, error)
- func (idx *Index) RemoveLabelIndex(m Mutator, node *Node) error
- func (idx *Index) RemovePropertyIndex(m Mutator, node *Node) error
- type Mutator
- type Node
- type PropertyType
- type PropertyValue
- type Relationship
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodePropertyValue ¶
func EncodePropertyValue(v PropertyValue) string
EncodePropertyValue encodes a PropertyValue to a string for indexing.
func GenerateID ¶
GenerateID generates a unique ID with the given prefix. It uses an atomic counter to ensure uniqueness across concurrent operations.
func SetIDCounter ¶
func SetIDCounter(counter uint64)
SetIDCounter sets the ID counter to a specific value. This is primarily useful for testing purposes.
Types ¶
type AdjacencyList ¶
type AdjacencyList struct {
// contains filtered or unexported fields
}
AdjacencyList manages the adjacency relationships between nodes. It provides methods to build and query relationships between graph nodes.
func NewAdjacencyList ¶
func NewAdjacencyList(store *storage.DB) *AdjacencyList
NewAdjacencyList creates a new AdjacencyList instance.
func (*AdjacencyList) AddRelationship ¶
func (adj *AdjacencyList) AddRelationship(m Mutator, rel *Relationship) error
AddRelationship creates adjacency entries for a relationship within a mutation context.
func (*AdjacencyList) GetAllRelated ¶
func (adj *AdjacencyList) GetAllRelated(nodeID string) ([]string, error)
GetAllRelated returns all Relationship IDs related to the given node, regardless of type. This is critical for efficient `Detach Delete`.
func (*AdjacencyList) GetRelatedNodes ¶
func (adj *AdjacencyList) GetRelatedNodes(nodeID, relType string, direction Direction) ([]string, error)
GetRelatedNodes returns the IDs of nodes related to the given node with the specified relationship type and direction.
func (*AdjacencyList) RemoveRelationship ¶
func (adj *AdjacencyList) RemoveRelationship(m Mutator, rel *Relationship) error
RemoveRelationship removes adjacency entries for a relationship within a mutation context.
type Direction ¶
type Direction string
Direction represents the direction of a relationship in a graph.
func ParseDirection ¶
ParseDirection parses a direction string and returns the corresponding Direction. Supported formats: "outgoing", "->", "out" for outgoing; "incoming", "<-", "in" for incoming; "both", "-" for both.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index manages label and property indexes for efficient node lookups.
func (*Index) BuildLabelIndex ¶
BuildLabelIndex creates index entries for all labels on a node.
func (*Index) BuildPropertyIndex ¶
BuildPropertyIndex creates index entries for all properties on a node.
func (*Index) LookupByLabel ¶
LookupByLabel returns all node IDs that have the given label.
func (*Index) LookupByProperty ¶
LookupByProperty returns all node IDs that have the given label and property value.
func (*Index) RemoveLabelIndex ¶
RemoveLabelIndex removes index entries for all labels on a node.
type Node ¶
type Node struct {
ID string
Labels []string
Properties map[string]PropertyValue
}
Node represents a graph node with an ID, labels, and properties.
func (*Node) GetProperty ¶
func (n *Node) GetProperty(key string) (PropertyValue, bool)
GetProperty returns the property value and true if it exists, or zero value and false.
func (*Node) RemoveLabel ¶
RemoveLabel removes a label from the node.
func (*Node) RemoveProperty ¶
RemoveProperty removes a property from the node.
func (*Node) SetProperty ¶
func (n *Node) SetProperty(key string, value PropertyValue)
SetProperty sets a property value on the node.
type PropertyType ¶
type PropertyType string
PropertyType represents the type of a property value.
const ( PropertyTypeString PropertyType = "string" PropertyTypeInt PropertyType = "int" PropertyTypeFloat PropertyType = "float" PropertyTypeBool PropertyType = "bool" )
type PropertyValue ¶
PropertyValue represents a typed property value that can hold string, int, float, or bool.
func NewBoolProperty ¶
func NewBoolProperty(v bool) PropertyValue
NewBoolProperty creates a PropertyValue holding a bool.
func NewFloatProperty ¶
func NewFloatProperty(v float64) PropertyValue
NewFloatProperty creates a PropertyValue holding a float64.
func NewIntProperty ¶
func NewIntProperty(v int64) PropertyValue
NewIntProperty creates a PropertyValue holding an int64.
func NewStringProperty ¶
func NewStringProperty(v string) PropertyValue
NewStringProperty creates a PropertyValue holding a string.
func ToPropertyValue ¶
func ToPropertyValue(v interface{}) PropertyValue
ToPropertyValue converts a Go value to a PropertyValue.
func (PropertyValue) BoolValue ¶
func (p PropertyValue) BoolValue() bool
BoolValue returns the bool value, or false if not a bool type.
func (PropertyValue) FloatValue ¶
func (p PropertyValue) FloatValue() float64
FloatValue returns the float value, or 0 if not a float type.
func (PropertyValue) IntValue ¶
func (p PropertyValue) IntValue() int64
IntValue returns the int value, or 0 if not an int type.
func (PropertyValue) StringValue ¶
func (p PropertyValue) StringValue() string
StringValue returns the string value, or empty string if not a string type.
func (PropertyValue) Type ¶
func (p PropertyValue) Type() PropertyType
Type returns the type of the property value.
type Relationship ¶
type Relationship struct {
ID string
StartNodeID string
EndNodeID string
Type string
Properties map[string]PropertyValue
}
Relationship represents a directed relationship between two nodes in a graph.
func NewRelationship ¶
func NewRelationship(startNodeID, endNodeID, relType string, properties map[string]interface{}) *Relationship
NewRelationship creates a new Relationship with the given parameters.
func (*Relationship) GetProperty ¶
func (r *Relationship) GetProperty(key string) (PropertyValue, bool)
GetProperty returns the property value and true if it exists, or zero value and false.
func (*Relationship) RemoveProperty ¶
func (r *Relationship) RemoveProperty(key string)
RemoveProperty removes a property from the relationship.
func (*Relationship) SetProperty ¶
func (r *Relationship) SetProperty(key string, value PropertyValue)
SetProperty sets a property value on the relationship.