Documentation ¶
Overview ¶
Copyright 2021 Cloud Privacy Labs, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2021 Cloud Privacy Labs, LLC ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2021 Cloud Privacy Labs, LLC ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- func CheckIsomorphism(g1, g2 *Graph, nodeEquivalenceFunc func(n1, n2 *Node) bool, ...) bool
- func CollectAllPaths(graph *Graph, fromNode *Node, firstLeg EdgeIterator, ...)
- func ComparePropertyValue(a, b interface{}) int
- func CopyGraph(source, target *Graph, clonePropertyFunc func(string, interface{}) interface{}) map[*Node]*Node
- func CopyGraphf(source *Graph, copyNodeFunc func(*Node, map[*Node]*Node) *Node, ...) map[*Node]*Node
- func CopySubgraph(sourceNode *Node, target *Graph, ...)
- func DefaultDOTEdgeRender(fromNode, toNode string, edge *Edge, w io.Writer) error
- func DefaultDOTNodeRender(ID string, node *Node, w io.Writer) error
- func ForEachNode(g *Graph, predicate func(*Node) bool) bool
- func GetEdgeFilterFunc(labels StringSet, properties map[string]interface{}) func(*Edge) bool
- func GetNodeFilterFunc(labels StringSet, properties map[string]interface{}) func(*Node) bool
- type Cursor
- func (c *Cursor) Backward() EdgeIterator
- func (c *Cursor) BackwardWith(label string) EdgeIterator
- func (c *Cursor) Edges(dir EdgeDir) EdgeIterator
- func (c *Cursor) EdgesWith(dir EdgeDir, label string) EdgeIterator
- func (c *Cursor) Forward() EdgeIterator
- func (c *Cursor) ForwardWith(label string) EdgeIterator
- func (c *Cursor) GetPath() *Path
- func (c *Cursor) NextNodes() NodeIterator
- func (c *Cursor) NextNodesWith(label string) NodeIterator
- func (c *Cursor) Nodes(dir EdgeDir) NodeIterator
- func (c *Cursor) NodesWith(dir EdgeDir, label string) NodeIterator
- func (c *Cursor) PopFromPath() *Cursor
- func (c *Cursor) PrevNodes() NodeIterator
- func (c *Cursor) PrevNodesWith(label string) NodeIterator
- func (c *Cursor) PushToPath(edge *Edge) *Cursor
- func (c *Cursor) Set(node *Node) *Cursor
- func (c *Cursor) StartPath() *Cursor
- type DOTRenderer
- func (d DOTRenderer) Render(g *Graph, graphName string, out io.Writer) error
- func (d DOTRenderer) RenderEdge(fromID, toID string, edge *Edge, w io.Writer) (bool, error)
- func (d DOTRenderer) RenderNode(ID string, node *Node, w io.Writer) (bool, error)
- func (d DOTRenderer) RenderNodesEdges(g *Graph, out io.Writer) error
- type DefaultMatchAccumulator
- type Edge
- func (p *Edge) ForEachProperty(f func(string, interface{}) bool) bool
- func (edge *Edge) GetFrom() *Node
- func (edge *Edge) GetGraph() *Graph
- func (edge *Edge) GetID() int
- func (edge *Edge) GetLabel() string
- func (p *Edge) GetProperty(key string) (interface{}, bool)
- func (edge *Edge) GetTo() *Node
- func (edge *Edge) MarshalJSON() ([]byte, error)
- func (edge *Edge) Remove()
- func (edge *Edge) RemoveProperty(key string)
- func (edge *Edge) SetLabel(label string)
- func (edge *Edge) SetProperty(key string, value interface{})
- func (edge *Edge) String() string
- type EdgeDir
- type EdgeIterator
- type EdgeSet
- type ErrEdgeVariableExpected
- type ErrInvalidGraph
- type ErrNodeVariableExpected
- type Graph
- func (g *Graph) AddEdgePropertyIndex(propertyName string, ix IndexType)
- func (g *Graph) AddNodePropertyIndex(propertyName string, ix IndexType)
- func (g *Graph) FindEdges(labels StringSet, properties map[string]interface{}) EdgeIterator
- func (g *Graph) FindNodes(allLabels StringSet, properties map[string]interface{}) NodeIterator
- func (g *Graph) GetEdges() EdgeIterator
- func (g *Graph) GetEdgesWithAnyLabel(set StringSet) EdgeIterator
- func (g *Graph) GetEdgesWithProperty(property string) EdgeIterator
- func (g *Graph) GetNodes() NodeIterator
- func (g *Graph) GetNodesWithAllLabels(labels StringSet) NodeIterator
- func (g *Graph) GetNodesWithProperty(property string) NodeIterator
- func (g *Graph) NewEdge(from, to *Node, label string, props map[string]interface{}) *Edge
- func (g *Graph) NewNode(labels []string, props map[string]interface{}) *Node
- func (g *Graph) NumEdges() int
- func (g *Graph) NumNodes() int
- type IndexType
- type Interner
- type Iterator
- type JSON
- type MapInterner
- type MatchAccumulator
- type MatchContext
- type MatchPlan
- type Node
- func CopyNode(sourceNode *Node, target *Graph, ...) *Node
- func NextNodesWith(source *Node, label string) []*Node
- func NodeSlice(in NodeIterator) []*Node
- func PrevNodesWith(source *Node, label string) []*Node
- func Sinks(graph *Graph) []*Node
- func SourceNodes(in EdgeIterator) []*Node
- func Sources(graph *Graph) []*Node
- func TargetNodes(in EdgeIterator) []*Node
- func (node *Node) Detach()
- func (node *Node) DetachAndRemove()
- func (p *Node) ForEachProperty(f func(string, interface{}) bool) bool
- func (node *Node) GetEdges(dir EdgeDir) EdgeIterator
- func (node *Node) GetEdgesWithAnyLabel(dir EdgeDir, labels StringSet) EdgeIterator
- func (node *Node) GetEdgesWithLabel(dir EdgeDir, label string) EdgeIterator
- func (node *Node) GetGraph() *Graph
- func (node *Node) GetID() int
- func (node *Node) GetLabels() StringSet
- func (p *Node) GetProperty(key string) (interface{}, bool)
- func (node *Node) HasLabel(s string) bool
- func (node *Node) MarshalJSON() ([]byte, error)
- func (node *Node) RemoveProperty(key string)
- func (node *Node) SetLabels(labels StringSet)
- func (node *Node) SetProperty(key string, value interface{})
- func (node *Node) String() string
- type NodeIterator
- type NodeMap
- type NodeSet
- type Path
- func (p *Path) Append(edge ...*Edge) *Path
- func (p *Path) Clear() *Path
- func (p *Path) Clone() *Path
- func (p *Path) First() *Node
- func (p *Path) GetEdge(n int) *Edge
- func (p *Path) GetNode(n int) *Node
- func (p *Path) IsEmpty() bool
- func (p *Path) Last() *Node
- func (p *Path) NumEdges() int
- func (p *Path) NumNodes() int
- func (p *Path) Prepend(edge ...*Edge) *Path
- func (p *Path) RemoveFirst() *Path
- func (p *Path) RemoveLast() *Path
- func (p *Path) SetOnlyNode(node *Node) *Path
- type Pattern
- func (pattern Pattern) FindNodes(graph *Graph, symbols map[string]*PatternSymbol) ([]*Node, error)
- func (pattern Pattern) FindPaths(graph *Graph, symbols map[string]*PatternSymbol) (DefaultMatchAccumulator, error)
- func (pattern Pattern) GetPlan(graph *Graph, symbols map[string]*PatternSymbol) (MatchPlan, error)
- func (pattern Pattern) GetSymbolNames() StringSet
- func (pattern Pattern) Run(graph *Graph, symbols map[string]*PatternSymbol, result MatchAccumulator) error
- type PatternItem
- type PatternSymbol
- type StringSet
- func (set *StringSet) Add(s ...string) *StringSet
- func (set *StringSet) AddSet(s StringSet) *StringSet
- func (set StringSet) Clone() StringSet
- func (set StringSet) Has(s string) bool
- func (set StringSet) HasAll(s ...string) bool
- func (set StringSet) HasAllSet(s StringSet) bool
- func (set StringSet) HasAny(s ...string) bool
- func (set StringSet) HasAnySet(s StringSet) bool
- func (set StringSet) IsEqual(s StringSet) bool
- func (set StringSet) Len() int
- func (set StringSet) MarshalJSON() ([]byte, error)
- func (set *StringSet) Remove(s ...string) *StringSet
- func (set StringSet) Slice() []string
- func (set StringSet) SortedSlice() []string
- func (set StringSet) String() string
- func (set *StringSet) UnmarshalJSON(in []byte) error
- type WithNativeValue
- type WithProperties
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckIsomorphism ¶
func CheckIsomorphism(g1, g2 *Graph, nodeEquivalenceFunc func(n1, n2 *Node) bool, edgeEquivalenceFunc func(e1, e2 *Edge) bool) bool
CheckIsomoprhism checks to see if graphs given are equal as defined by the edge equivalence and node equivalence functions. The nodeEquivalenceFunction will be called for all pairs of nodes. The edgeEquivalenceFunction will be called for edges connecting equivalent nodes.
func CollectAllPaths ¶
func CollectAllPaths(graph *Graph, fromNode *Node, firstLeg EdgeIterator, edgeFilter func(*Edge) bool, dir EdgeDir, min, max int, accumulator func([]*Edge, *Node) bool)
CollectAllPaths iterates the variable length paths that have the edges in firstLeg. For each edge, it calls the edgeFilter function. If the edge is accepted, it recursively descends and calls accumulator.AddPath for each discovered path until AddPath returns false
func ComparePropertyValue ¶
func ComparePropertyValue(a, b interface{}) int
ComparePropertyValue compares a and b. They must be comparable. Supported types are
int string []int []string []interface
The []interface must have one of the supported types as its elements
If one of the values implement GetNativeValue() method, then it is called to get the underlying value
func CopyGraph ¶
func CopyGraph(source, target *Graph, clonePropertyFunc func(string, interface{}) interface{}) map[*Node]*Node
CopyGraph copies source graph into target, using clonePropertyFunc to clone properties
func CopyGraphf ¶
func CopyGraphf(source *Graph, copyNodeFunc func(*Node, map[*Node]*Node) *Node, copyEdgeFunc func(*Edge, map[*Node]*Node) *Edge) map[*Node]*Node
CopyGraphf copies source graph into target, using the copeNodeFunc func to clone nodes. copyNodeFunc may return nil to prevent copying a node
func CopySubgraph ¶
func CopySubgraph(sourceNode *Node, target *Graph, clonePropertyFunc func(string, interface{}) interface{}, nodeMap map[*Node]*Node)
CopySubgraph copies all nodes that are accessible from sourceNode to the target graph
func DefaultDOTEdgeRender ¶
DefaultDOTEdgeRender renders the edge with a label if there is one, or without a label if there is not a label.
func DefaultDOTNodeRender ¶
DefaultDOTNodeRender renders the node with the given ID. If the node has a label, it uses that label, otherwise node is not labeled.
func ForEachNode ¶
ForEachNode iterates through all the nodes of g until predicate returns false or all nodes are processed.
func GetEdgeFilterFunc ¶
GetEdgeFilterFunc returns a function that can be used to select edges that have at least one of the specified labels, with correct property values
Types ¶
type Cursor ¶ added in v1.0.9
type Cursor struct {
// contains filtered or unexported fields
}
Cursor is a convenience class to move around a graph
func (*Cursor) Backward ¶ added in v1.0.9
func (c *Cursor) Backward() EdgeIterator
Backward returns an edge iterator for incoming edges of the current node. If the current node is invalid, returns an empty iterator
func (*Cursor) BackwardWith ¶ added in v1.0.9
func (c *Cursor) BackwardWith(label string) EdgeIterator
BackwardWith returns an edge iterator for incoming edges of the current node with the given label. If the current node is invalid, returns an empty iterator
func (*Cursor) Edges ¶ added in v1.0.9
func (c *Cursor) Edges(dir EdgeDir) EdgeIterator
Edges returns an iterator of edges of the current node. If the current node is invalid, returns an empty iterator
func (*Cursor) EdgesWith ¶ added in v1.0.9
func (c *Cursor) EdgesWith(dir EdgeDir, label string) EdgeIterator
EdgesWith returns an iterator of edges of the current node with the given label. If the current node is invalid, returns an empty iterator
func (*Cursor) Forward ¶ added in v1.0.9
func (c *Cursor) Forward() EdgeIterator
Forward returns an edge iterator for outgoing edges of the current node. If the current node is invalid, returns an empty iterator
func (*Cursor) ForwardWith ¶ added in v1.0.9
func (c *Cursor) ForwardWith(label string) EdgeIterator
ForwardWith returns an edge iterator for outgoing edges of the current node with the given label. If the current node is invalid, returns an empty iterator
func (*Cursor) GetPath ¶ added in v1.0.9
GetPath returns the recorded path. This is the internal copy of the path, so caller must clone if it changes are necessary
func (*Cursor) NextNodes ¶ added in v1.0.9
func (c *Cursor) NextNodes() NodeIterator
NextNodes returns a node iterator that can be reached at one step from the current node. If current node is invalid, returns an empty iterator.
func (*Cursor) NextNodesWith ¶ added in v1.0.9
func (c *Cursor) NextNodesWith(label string) NodeIterator
NextNodesWith returns a node iterator that can be reached at one step from the current node with the given label. If current node is invalid, returns an empty iterator.
func (*Cursor) Nodes ¶ added in v1.0.9
func (c *Cursor) Nodes(dir EdgeDir) NodeIterator
Nodes returns an iterator over the nodes that are reachable by a single edge from the current node. If the current node is not valid, returns an empty iterator
func (*Cursor) NodesWith ¶ added in v1.0.9
func (c *Cursor) NodesWith(dir EdgeDir, label string) NodeIterator
NodesWith returns an iterator over the nodes that are reachable by a single edge with the given label from the current node. If the current node is not valid, returns an empty iterator
func (*Cursor) PopFromPath ¶ added in v1.0.9
PopFromPath removes the last edge from the path. This also moves the cursor to the previous node
func (*Cursor) PrevNodes ¶ added in v1.0.9
func (c *Cursor) PrevNodes() NodeIterator
PrevNodes returns a node iterator that can be reached at one step backwards from the current node. If current node is invalid, returns an empty iterator.
func (*Cursor) PrevNodesWith ¶ added in v1.0.9
func (c *Cursor) PrevNodesWith(label string) NodeIterator
PrevNodesWith returns a node iterator that can be reached at one step backwards from the current node with the given label. If current node is invalid, returns an empty iterator.
func (*Cursor) PushToPath ¶ added in v1.0.9
PushToPath pushes the edge onto the path. The path must be started, and the pushed edge must be connected to the current node. This also advances the cursor to the target node.
type DOTRenderer ¶
type DOTRenderer struct { // NodeRenderer renders a node. If the node is to be excluded, returns false. NodeRenderer func(string, *Node, io.Writer) (bool, error) // EdgeRenderer renders an edge. The from and to nodes are rendered // if this is called. If the edge is to be excluded, returns false EdgeRenderer func(fromID string, toID string, edge *Edge, w io.Writer) (bool, error) }
DOTRenderer renders a graph in Graphviz dot format
func (DOTRenderer) RenderEdge ¶
RenderEdge renders an edge. If edge renderer is not set, call the default rendeded
func (DOTRenderer) RenderNode ¶
RenderNode renders a node. If node renderer is not set, calls the default renderer
func (DOTRenderer) RenderNodesEdges ¶
func (d DOTRenderer) RenderNodesEdges(g *Graph, out io.Writer) error
type DefaultMatchAccumulator ¶
type DefaultMatchAccumulator struct { // Each element of the paths is either a Node or []Edge Paths []interface{} Symbols []map[string]interface{} }
func (*DefaultMatchAccumulator) GetHeadNodes ¶
func (acc *DefaultMatchAccumulator) GetHeadNodes() []*Node
Returns the unique nodes in the accumulator that start a path
func (*DefaultMatchAccumulator) GetTailNodes ¶
func (acc *DefaultMatchAccumulator) GetTailNodes() []*Node
Returns the unique nodes in the accumulator that ends a path
func (*DefaultMatchAccumulator) StoreResult ¶
func (acc *DefaultMatchAccumulator) StoreResult(_ *MatchContext, path interface{}, symbols map[string]interface{})
type Edge ¶
type Edge struct {
// contains filtered or unexported fields
}
An Edge connects two nodes of a graph
func CopyEdge ¶
func CopyEdge(edge *Edge, target *Graph, clonePropertyFunc func(string, interface{}) interface{}, nodeMap map[*Node]*Node) *Edge
CopyEdge copies the edge into graph
func EdgeSlice ¶
func EdgeSlice(in EdgeIterator) []*Edge
EdgeSlice reads all the remaining items of an edge iterator and returns them in a slice
func EdgesBetweenNodes ¶ added in v1.0.13
EdgesBetweenNodes finds all the edges that go from 'from' to 'to'
func (*Edge) ForEachProperty ¶
ForEachProperty calls f for each property in p until f returns false. Returns false if f returned false. p can be nil
func (*Edge) GetID ¶
GetID returns the unique identifier for the edge. The identifier is unique in this graph, and meaningless once the edge is disconnected.
func (*Edge) GetProperty ¶
GetProperty returns the value for the key, and whether or not key exists. p can be nil
func (*Edge) MarshalJSON ¶ added in v1.0.8
func (*Edge) RemoveProperty ¶
RemoveProperty removes an edge property
func (*Edge) SetProperty ¶
SetProperty sets an edge property
type EdgeIterator ¶
EdgeIterator iterates the edges of an underlying list
type EdgeSet ¶
type EdgeSet struct {
// contains filtered or unexported fields
}
EdgeSet keeps an unordered set of edges
func NewEdgeSet ¶
func NewEdgeSet() *EdgeSet
func (EdgeSet) Iterator ¶
func (set EdgeSet) Iterator() EdgeIterator
type ErrEdgeVariableExpected ¶
type ErrEdgeVariableExpected string
func (ErrEdgeVariableExpected) Error ¶
func (e ErrEdgeVariableExpected) Error() string
type ErrInvalidGraph ¶
type ErrInvalidGraph struct {
Msg string
}
func (ErrInvalidGraph) Error ¶
func (e ErrInvalidGraph) Error() string
type ErrNodeVariableExpected ¶
type ErrNodeVariableExpected string
func (ErrNodeVariableExpected) Error ¶
func (e ErrNodeVariableExpected) Error() string
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
A Graph is a labeled property graph containing nodes, and directed edges combining those nodes.
Every node of the graph contains a set of labels, and a map of properties. Each node provides access to the edges adjacent to it. Every edge contains a from and to node, a label, and a map of properties.
Nodes and edges are "owned" by a graph object. Given a node or edge, you can always get its graph using `node.GetGraph()` or `edge.GetGraph()` method. You cannot use an edge to connect nodes of different graphs.
Zero value for a Graph is not usable. Use `NewGraph` to construct a new graph.
func NewGraph ¶
func NewGraph() *Graph
NewGraph constructs and returns a new graph. The new graph has no nodes or edges.
func (*Graph) AddEdgePropertyIndex ¶
AddEdgePropertyIndex adds an index for the given edge property
func (*Graph) AddNodePropertyIndex ¶
AddNodePropertyIndex adds an index for the given node property
func (*Graph) FindEdges ¶
func (g *Graph) FindEdges(labels StringSet, properties map[string]interface{}) EdgeIterator
FindEdges returns an iterator that will iterate through all the edges whose label is in the given labels and have all the properties. If labels is nil or empty, it does not look at the labels. If properties is nil or empty, it does not look at the properties
func (*Graph) FindNodes ¶
func (g *Graph) FindNodes(allLabels StringSet, properties map[string]interface{}) NodeIterator
FindNodes returns an iterator that will iterate through all the nodes that have all of the given labels and properties. If allLabels is nil or empty, it does not look at the labels. If properties is nil or empty, it does not look at the properties
func (*Graph) GetEdges ¶
func (g *Graph) GetEdges() EdgeIterator
GetEdges returns an edge iterator that goes through all the edges of the graph. The behavior of the returned iterator is undefined if during iteration edges are updated, new edges are added, or existing edges are deleted.
func (*Graph) GetEdgesWithAnyLabel ¶
func (g *Graph) GetEdgesWithAnyLabel(set StringSet) EdgeIterator
GetEdgesWithAnyLabel returns an iterator that goes through the edges of the graph that are labeled with one of the labels in the given set. The behavior of the returned iterator is undefined if during iteration edges are updated, new edges are added, or existing edges are deleted.
func (*Graph) GetEdgesWithProperty ¶
func (g *Graph) GetEdgesWithProperty(property string) EdgeIterator
GetEdgesWithProperty returns an iterator for the edges that has the property. If there is an index for the property, and iterator over that index is returned. Otherwise, an iterator that goes through all edges while filtering them is returned. The behavior of the returned iterator is undefined if during iteration edges are updated, new edges are added, or existing edges are deleted.
func (*Graph) GetNodes ¶
func (g *Graph) GetNodes() NodeIterator
GetNodes returns a node iterator that goes through all the nodes of the graph. The behavior of the returned iterator is undefined if during iteration nodes are updated, new nodes are added, or existing nodes are deleted.
func (*Graph) GetNodesWithAllLabels ¶
func (g *Graph) GetNodesWithAllLabels(labels StringSet) NodeIterator
GetNodesWithAllLabels returns an iterator that goes through the nodes that have all the nodes given in the set. The nodes may have more nodes than given in the set. The behavior of the returned iterator is undefined if during iteration nodes are updated, new nodes are added, or existing nodes are deleted.
func (*Graph) GetNodesWithProperty ¶
func (g *Graph) GetNodesWithProperty(property string) NodeIterator
GetNodesWithProperty returns an iterator for the nodes that has the property. If there is an index for the node property, and iterator over that index is returned. Otherwise, an iterator that goes through all nodes while filtering them is returned. The behavior of the returned iterator is undefined if during iteration nodes are updated, new nodes are added, or existing nodes are deleted.
func (*Graph) NewEdge ¶
NewEdge creates a new edge between the two nodes of the graph. Both nodes must be nodes of this graph, otherwise this call panics
type Interner ¶
type Interner interface { // Intern should return the interned copy of the string Intern(string) string }
Interner is a string interface, that can be as simple as a map[string]string, that is used to intern property keys
type Iterator ¶
type Iterator interface { // Next moves to the next item in the iterator, and returns true if // move was successful. If there are no next items remaining, returns false Next() bool // Value returns the current item in the iterator. This is undefined // before the first call to Next, and after Next returns false. Value() interface{} // MaxSize returns an estimation of maximum number of elements. If unknown, returns -1 MaxSize() int }
An Iterator iterates the items of a collection
func MultiIterator ¶
MultiIterator returns an iterator that contatenates all the given iterators
type JSON ¶
type JSON struct { Interner Interner // If false, dring marshaling edges are embedded in the source // nodes. If true, edges are marshaled separately as a JSON array. MarshalEdgesSeparately bool // PropertyUnmarshaler unmarshals a property value. The return // values are the key, value, and possible error. If the returned // key is empty, the property is not unmarshaled. If this is nil, // default json unmarshaler is used for property value. PropertyUnmarshaler func(key string, value json.RawMessage) (string, interface{}, error) // PropertyMarshaler marshals a property value. The return values // are the key, the marshaled value, and possible error. If the // returned key is empty, the property is not marshaled. If this is // nil, the default json marshaler is used for property value. PropertyMarshaler func(key string, value interface{}) (string, json.RawMessage, error) }
JSON marshals/unmarshals a graph to/from JSON.
The JSON unmarshaling uses a string Interner if it is set. This allows reusing the strings for repeated keys. Setting this interner to an implementation will reduce memory footprint of the graph. If letf uninitialized, the unmarshaler still uses an interner, but this interner will not be shared between different graphs unmarshaled using this unmarshaler.
If PropertyMarshaler/PropertyUnmarshaler is set, these functions are called to marshal/unmarshal individual properties. These function can return an empty string for the key to skip the property.
If MarshalEdgesSeparately is set, graph edges are marshaled under the "edges" key. If this is false, the graph edges are included under the source node.
The JSON representation of nodes use a numeric node index. These indexes are used to refer to nodes in edges.
With MarshalEdgesSeparately=false:
{ "nodes": [ { "n": 0, "labels": ["lbl1","lbl2"], "properties": { "key": "value" }, "edges": [ { "to": 1, "label": "edgeLabel" } ] }, { "n": 1, "labels": ["lbl1"] } ] }
With MarshalEdgesSeparately=true:
{ "nodes": [ { "n": 0, "labels": ["lbl1","lbl2"], "properties": { "key": "value" } }, { "n": 1, "labels": ["lbl1"] } ], "edges": [ { "from": 0, "to": 1, "label": "edgeLabel" } ] }
type MapInterner ¶
MapInterner is a basic interner that uses a map[string]string to intern strings
func (MapInterner) Intern ¶
func (i MapInterner) Intern(s string) string
Intern keeps the interned copy of s in the map
type MatchAccumulator ¶
type MatchAccumulator interface { // path is either a Node or []Edge, the matching path symbols // contains the current values for each symbol. The values of the // map is either Node or []Edge StoreResult(ctx *MatchContext, path interface{}, symbols map[string]interface{}) }
type MatchContext ¶
type MatchContext struct { Graph *Graph // These are symbols that are used as constraints in the matching process. Symbols map[string]*PatternSymbol // localSymbols are symbols defined in the pattern. LocalSymbols map[string]*PatternSymbol // contains filtered or unexported fields }
type MatchPlan ¶
type MatchPlan struct {
// contains filtered or unexported fields
}
func (MatchPlan) CaptureSymbolValues ¶
CaptureSymbolValues captures the current symbol values as nodes or []Edges
func (MatchPlan) GetCurrentPath ¶
func (plan MatchPlan) GetCurrentPath() interface{}
GetCurrentPath returns the current path recoded in the stages of the pattern. The result is either a single node, or a path
func (MatchPlan) Run ¶
func (plan MatchPlan) Run(graph *Graph, symbols map[string]*PatternSymbol, result MatchAccumulator) error
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
A Node represents a graph node.
func CopyNode ¶
func CopyNode(sourceNode *Node, target *Graph, clonePropertyFunc func(string, interface{}) interface{}) *Node
CopyNode copies the sourceNode into target graph
func NextNodesWith ¶
NextNodesWith returns the nodes reachable from source with the given label at one step
func NodeSlice ¶
func NodeSlice(in NodeIterator) []*Node
NodeSlice reads all the remaining items of a node iterator and returns them in a slice
func PrevNodesWith ¶
PrevNodesWith returns the nodes reachable from source with the given label at one step
func SourceNodes ¶
func SourceNodes(in EdgeIterator) []*Node
SourceNodes returns the source nodes of all edges
func TargetNodes ¶
func TargetNodes(in EdgeIterator) []*Node
TargetNodes returns the target nodes of all edges
func (*Node) DetachAndRemove ¶
func (node *Node) DetachAndRemove()
Remove all connected edges, and remove the node
func (*Node) ForEachProperty ¶
ForEachProperty calls f for each property in p until f returns false. Returns false if f returned false. p can be nil
func (*Node) GetEdges ¶
func (node *Node) GetEdges(dir EdgeDir) EdgeIterator
Returns an edge iterator for incoming or outgoing edges
func (*Node) GetEdgesWithAnyLabel ¶
func (node *Node) GetEdgesWithAnyLabel(dir EdgeDir, labels StringSet) EdgeIterator
Returns an edge iterator for incoming or outgoingn edges that has the given labels
func (*Node) GetEdgesWithLabel ¶
func (node *Node) GetEdgesWithLabel(dir EdgeDir, label string) EdgeIterator
Returns an edge iterator for incoming or outgoing edges with the given label
func (*Node) GetID ¶
GetID returns the unique node ID. The ID is meaningless if the node is removed from the graph
func (*Node) GetProperty ¶
GetProperty returns the value for the key, and whether or not key exists. p can be nil
func (*Node) MarshalJSON ¶ added in v1.0.8
func (*Node) RemoveProperty ¶
RemoveProperty removes a node property
func (*Node) SetProperty ¶
SetProperty sets a node property
type NodeIterator ¶
NodeIterator iterates nodes of an underlying list
func SinksItr ¶ added in v1.0.12
func SinksItr(graph *Graph) NodeIterator
Sinks finds all the sink nodes in the graph
func SourcesItr ¶
func SourcesItr(graph *Graph) NodeIterator
Sources finds all the source nodes in the graph
type NodeMap ¶
type NodeMap struct {
// contains filtered or unexported fields
}
An NodeMap stores nodes indexed by node labels
func NewNodeMap ¶
func NewNodeMap() *NodeMap
func (NodeMap) Iterator ¶
func (nm NodeMap) Iterator() NodeIterator
func (NodeMap) IteratorAllLabels ¶
func (nm NodeMap) IteratorAllLabels(labels StringSet) NodeIterator
type NodeSet ¶
type NodeSet struct {
// contains filtered or unexported fields
}
func NewNodeSet ¶
func NewNodeSet() *NodeSet
func (NodeSet) Iterator ¶
func (set NodeSet) Iterator() NodeIterator
type Path ¶ added in v1.0.9
type Path struct {
// contains filtered or unexported fields
}
A Path can be a node, or node-edge-node...-edge-node sequence.
func PathFromNode ¶ added in v1.0.9
PathFromNode creates a path containing a single node
func (*Path) Append ¶ added in v1.0.9
Append an edge to the end of the path. The edge must be outgoing from the last node of the path
func (*Path) Prepend ¶ added in v1.0.9
Prepend an edge to tbe beginning of the path. The edge must be incoming to the first node of the path
func (*Path) RemoveFirst ¶ added in v1.0.9
RemoveFirst removes the first edge from the graph. If the path has only a node, path becomes empty
func (*Path) RemoveLast ¶ added in v1.0.9
RemoveLast removes the last edge from the path. If the path has one edge, the path becomes a single node containing the source. If the path has only a node, path becomes empty
func (*Path) SetOnlyNode ¶ added in v1.0.9
SetOnlyNode sets the path to a single node
type Pattern ¶
type Pattern []PatternItem
Pattern contains pattern items, with even numbered elements corresponding to nodes, and odd numbered elements corresponding to edges
func (Pattern) FindNodes ¶
FindNodes runs the pattern with the given symbols, and returns all the head nodes found
func (Pattern) FindPaths ¶
func (pattern Pattern) FindPaths(graph *Graph, symbols map[string]*PatternSymbol) (DefaultMatchAccumulator, error)
func (Pattern) GetSymbolNames ¶
func (Pattern) Run ¶
func (pattern Pattern) Run(graph *Graph, symbols map[string]*PatternSymbol, result MatchAccumulator) error
type PatternItem ¶
type PatternItem struct { Labels StringSet Properties map[string]interface{} // Min=-1 and Max=-1 for variable length Min int Max int // ToLeft is true if this is a relationship of the form <- ToLeft bool // Undirected is true if this is a relationship of the form -- Undirected bool // Name of the variable associated with this processing node. If the // name is defined, it is used to constrain values. If not, it is // used to store values Name string }
A PatternItem can be a node or an edge element of a pattern
type PatternSymbol ¶
A PatternSymbol contains either nodes, or edges.
func (*PatternSymbol) Add ¶
func (p *PatternSymbol) Add(item interface{}) bool
func (*PatternSymbol) AddNode ¶
func (p *PatternSymbol) AddNode(item *Node)
func (*PatternSymbol) AddPath ¶
func (p *PatternSymbol) AddPath(path []*Edge)
func (*PatternSymbol) EdgeSlice ¶
func (p *PatternSymbol) EdgeSlice() []*Edge
func (*PatternSymbol) NodeSlice ¶
func (p *PatternSymbol) NodeSlice() []*Node
type StringSet ¶
type StringSet struct {
M map[string]struct{}
}
func NewStringSet ¶
func (StringSet) MarshalJSON ¶
func (StringSet) SortedSlice ¶
func (*StringSet) UnmarshalJSON ¶
type WithNativeValue ¶ added in v1.0.4
type WithNativeValue interface {
GetNativeValue() interface{}
}
WithNativeValue is used to return a native value for property values. If the property value implements this interface, the underlying native value for indexing and comparison is obtained from this interface.