graph

package
v0.0.0-...-ee3ee60 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Unlimited is used when returning a unlimited level subgraph.
	Unlimited = 0
)

Variables

This section is empty.

Functions

func NewProperties

func NewProperties(kv ...KV) map[string][]byte

NewProperties takes one or more key value pairs and returns a property map.

Types

type Edge

type Edge struct {
	UID        string            `json:"uid"`
	SourceUID  string            `json:"source_uid"`
	Label      string            `json:"label"`
	TargetUID  string            `json:"target_uid"`
	Properties map[string][]byte `json:"properties"`
}

Edge is a edge in the graph.

func NewEdge

func NewEdge(uid, sourceUID, label, targetUID string, kv ...KV) Edge

NewEdge returns a new edge instance.

type FilterType

type FilterType int

FilterType indicates what to apply the filtering on.

const (
	// LABEL is used for filtering by label.
	LABEL FilterType = iota
	// PROPERTY is used for filtering on properties.
	PROPERTY
)

type Graph

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

Graph is a graph store.

func New

func New() *Graph

New returns a new empty graph.

func NewFromJSON

func NewFromJSON(r io.Reader) (*Graph, error)

NewFromJSON takes a JSON formatted output and returns a new Graph.

func (*Graph) AddEdge

func (g *Graph) AddEdge(uid, sourceUID, label, targetUID string, kv ...KV) (Edge, error)

AddEdge adds a new edge to the graph.

func (*Graph) AddNode

func (g *Graph) AddNode(uid, label string, kv ...KV) (Node, error)

AddNode adds a new node to the graph.

func (*Graph) Edge

func (g *Graph) Edge(uid string) (Edge, error)

Edge returns the edge with the provided uid.

func (*Graph) EdgeCount

func (g *Graph) EdgeCount() int

EdgeCount returns the total number of edges in the graph.

func (*Graph) Edges

func (g *Graph) Edges() Iterator

Edges returns a edge iterator.

func (*Graph) EdgesBy

func (g *Graph) EdgesBy(source string, labels []string, target string, props map[string][]byte) Iterator

EdgesBy returns a edge iterator with filtered edges. If labels is an empty list, then any label will be used. If props is an empty map, no properties will be used for filtering.

func (*Graph) HasEdge

func (g *Graph) HasEdge(uid string) bool

HasEdge returns true if the graph has a edge with the provided uid.

func (*Graph) HasNode

func (g *Graph) HasNode(uid string) bool

HasNode returns true if the graph has a node with the provided uid.

func (*Graph) MarshalJSON

func (g *Graph) MarshalJSON() ([]byte, error)

MarshalJSON marchals the graph into a JSON format.

func (*Graph) Node

func (g *Graph) Node(uid string) (Node, error)

Node returns the node with the provided uid.

func (*Graph) NodeCount

func (g *Graph) NodeCount() int

NodeCount returns the total number of nodes in the graph.

func (*Graph) Nodes

func (g *Graph) Nodes() Iterator

Nodes returns a node iterator.

func (*Graph) NodesBy

func (g *Graph) NodesBy(labels []string, props map[string][]byte) Iterator

NodesBy returns a node iterator with filtered nodes. If labels is an empty list, then any label will be used. If props is an empty map, no properties will be used for filtering.

func (*Graph) Query

func (g *Graph) Query(query string) (*Graph, error)

Query takes a query string and returns a subgraph containing the query results.

func (*Graph) RemoveEdge

func (g *Graph) RemoveEdge(uid string) error

RemoveEdge removes the edge from the graph.

func (*Graph) RemoveNode

func (g *Graph) RemoveNode(uid string) error

RemoveNode removes the node from the graph.

func (*Graph) Stats

func (g *Graph) Stats() Stat

Stats returns some stats on the current graph instance.

func (*Graph) SubGraph

func (g *Graph) SubGraph(uid string, levels int) (*Graph, error)

SubGraph takes a starting node UID and returns a new subgraph with `n` levels deep. Levels `0` or `Unlimited` will return the subgraph with no level limit.

func (*Graph) UnmarshalJSON

func (g *Graph) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals JSON data into the graph.

func (*Graph) UpdateEdge

func (g *Graph) UpdateEdge(edge Edge) (Edge, error)

UpdateEdge updates the graph edge with the new edge.

func (*Graph) UpdateNode

func (g *Graph) UpdateNode(node Node) (Node, error)

UpdateNode updates the graph node with the new node.

type ItemType

type ItemType int

ItemType indicates the type of item.

const (
	// NODE is a node item type.
	NODE ItemType = iota
	// EDGE is a edge item type.
	EDGE
)

type Iterator

type Iterator interface {
	// Value returns the Item.
	Value() interface{}
	// Next progresses the iterator and return true if there are still items to iterate over.
	Next() bool
	// Size returns the total item count in the iterator
	Size() int
	// Channel returns the items in the iterator as a channel.
	Channel() <-chan interface{}
}

Iterator is an iterator interface for iterating over a set of items.

type KV

type KV struct {
	Key   string `json:"key"`
	Value []byte `json:"value"`
}

KV is a property key and value pair.

type Node

type Node struct {
	UID        string            `json:"uid"`
	Label      string            `json:"label"`
	Properties map[string][]byte `json:"properties"`
	// contains filtered or unexported fields
}

Node is a node in the graph.

func NewNode

func NewNode(uid, label string, kv ...KV) Node

NewNode returns a new node instance.

func (Node) Edges

func (n Node) Edges() []string

Edges returns all the in and outbound edges. ()-->(n)-->()

func (Node) InEdges

func (n Node) InEdges() []string

InEdges returns all the inbound edges. ()-->(n)

func (Node) OutEdges

func (n Node) OutEdges() []string

OutEdges returns all the outbound edges. (n)-->()

type Stat

type Stat struct {
	StartTime     time.Time
	NodeCount     int
	EdgeCount     int
	NumCPU        int
	NumGoroutings int
	MemStats      runtime.MemStats
}

Stat contains some information about the graph.

Directories

Path Synopsis
parser
cypher
Stripped down OpenCypher parser for quering the graph.
Stripped down OpenCypher parser for quering the graph.

Jump to

Keyboard shortcuts

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