memory

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

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

Edge implements graph.WeightedEdge

func NewEdge

func NewEdge(from, to *Node, opts ...graph.Option) (*Edge, error)

NewEdge creates new Edge and returns it. If no DOTID is given, DOTID returns UID. If both WithUID and WithDOTID are provided DOTID overrides the UID value.

func (Edge) Attributes

func (e Edge) Attributes() []encoding.Attribute

Attributes implements store.DOTAttrs

func (Edge) Attrs added in v0.0.3

func (e Edge) Attrs() attrs.Attrs

Attrs returns edge attributes

func (Edge) DOTID

func (e Edge) DOTID() string

DOTID returns the edge's DOT ID.

func (*Edge) From

func (e *Edge) From() gngraph.Node

From returns the from node of the first non-nil edge, or nil.

func (Edge) FromNode

func (e Edge) FromNode(ctx context.Context) (graph.Node, error)

FromNode returns the from node of the first non-nil edge, or nil.

func (*Edge) ReversedEdge

func (e *Edge) ReversedEdge() gngraph.Edge

ReversedEdge returns a new edge with end points of the pair swapped.

func (*Edge) SetDOTID

func (e *Edge) SetDOTID(id string)

SetDOTID sets the edge's DOT ID.

func (*Edge) To

func (e *Edge) To() gngraph.Node

To returns the to node of the first non-nil edge, or nil.

func (Edge) ToNode

func (e Edge) ToNode(ctx context.Context) (graph.Node, error)

ToNode returns the to node of the first non-nil edge, or nil.

func (Edge) UID added in v0.0.3

func (e Edge) UID() uuid.UID

UID returns Edge UID

func (Edge) Weight

func (e Edge) Weight() float64

Weight returns edge weight

type Graph

Graph is in-memory graph.

type Node

type Node struct {
	space.Entity
	// contains filtered or unexported fields
}

Node is a graph node.

func NewNode

func NewNode(id int64, e space.Entity, opts ...graph.Option) (*Node, error)

NewNode creates new Node and returns it. NOTE: if WithAttrs is passed it, its values ovverride Object.Attrs

func (Node) Attributes

func (n Node) Attributes() []encoding.Attribute

Attributes implements attrs.DOT.

func (Node) Attrs

func (n Node) Attrs() attrs.Attrs

Attrs returns node attributes.

func (Node) DOTID

func (n Node) DOTID() string

DOTID returns GraphViz DOT ID.

func (Node) ID

func (n Node) ID() int64

ID returns node ID.

func (*Node) SetDOTID

func (n *Node) SetDOTID(id string)

SetDOTID sets GraphViz DOT ID. It sets both dotid and name attributes to id.

type WUG

type WUG struct {
	*simple.WeightedUndirectedGraph
	// contains filtered or unexported fields
}

WUG is weighted undirected graph.

func NewWUG

func NewWUG(opts ...graph.Option) (*WUG, error)

NewWUG creates a new weighted undirected graph and returns it. If DOTID is not provided via options, it's set to graph UID>

func (*WUG) AddNode

func (g *WUG) AddNode(ctx context.Context, n graph.Node) error

AddNode adds node to the graph.

func (*WUG) DOT

func (g *WUG) DOT() (string, error)

DOT returns the GrapViz dot representation of netscrape.

func (*WUG) DOTAttributers

func (g *WUG) DOTAttributers() (graph, node, edge encoding.Attributer)

DOTAttributers implements encoding.Attributer.

func (WUG) DOTID

func (g WUG) DOTID() string

DOTID returns the store DOT ID.

func (*WUG) Edge

func (g *WUG) Edge(ctx context.Context, uid, vid uuid.UID) (graph.Edge, error)

Edge returns edge between the two nodes

func (*WUG) Edges

func (g *WUG) Edges(ctx context.Context) ([]graph.Edge, error)

Edges returns all the edges (lines) from u to v.

func (g *WUG) Link(ctx context.Context, from, to uuid.UID, opts ...graph.Option) (graph.Edge, error)

Link creates a new edge between from and to and returns it or it returns the existing edge. It returns error if either of the nodes does not exist in the graph.

func (*WUG) NewNode

func (g *WUG) NewNode(ctx context.Context, ent space.Entity, opts ...graph.Option) (graph.Node, error)

NewNode creates a new graph node and returns it. NOTE: this is a convenience method which creates the new *memory.Node such that it makes sure its ID does not already exist in the graph relieving you from the necessity to make sure your new Node.ID() returns unique ID in the underlying graph.

func (*WUG) Node

func (g *WUG) Node(ctx context.Context, uid uuid.UID) (graph.Node, error)

Node returns the node with the given ID if it exists in the graph, and error if it could not be retrieved.

func (*WUG) Nodes

func (g *WUG) Nodes(ctx context.Context) ([]graph.Node, error)

Nodes returns all the nodes in the graph.

func (WUG) Query

func (g WUG) Query(ctx context.Context, q query.Query) ([]graph.Object, error)

Query queries the in-memory graph and returns the matched results.

func (g *WUG) RemoveLink(ctx context.Context, from, to uuid.UID) error

RemoveLink removes link between two nodes.

func (*WUG) RemoveNode

func (g *WUG) RemoveNode(ctx context.Context, uid uuid.UID) error

RemoveNode removes the node with the given id from graph.

func (*WUG) SubGraph

func (g *WUG) SubGraph(ctx context.Context, uid uuid.UID, depth int, opts ...graph.Option) (graph.Graph, error)

SubGraph returns the subgraph of the node with the given uid up to the given depth.

func (WUG) UID added in v0.0.3

func (g WUG) UID() uuid.UID

UID returns graph UID

Jump to

Keyboard shortcuts

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