graph

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: Apache-2.0 Imports: 4 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 interface {
	// An edge implements Node because it has an Identifier and attributes
	Node
	// From returns the root node of the edge
	From() Node
	// To returns the target node of the edge
	To() Node
}

Edge is a relationship between two nodes

func BasicEdge added in v0.6.0

func BasicEdge(id ID, attributes Map, from, to Node) Edge

type Edges

type Edges map[string]map[string]Edge

Edges is a map of edges. Edges are not concurrency safe.

func (Edges) AddEdge added in v0.5.1

func (e Edges) AddEdge(edge Edge)

AddEdge adds the edge to the map

func (Edges) DelEdge added in v0.5.1

func (e Edges) DelEdge(id ID)

DelEdge deletes the edge

func (Edges) Filter added in v0.5.2

func (e Edges) Filter(fn func(e Edge) bool) []Edge

Filter executes the function over every edge. If the function returns true, the edges will be added to the returned array of edges.

func (Edges) FilterType added in v0.5.2

func (e Edges) FilterType(typ string, fn func(e Edge) bool) []Edge

FilterType executes the function over every edge of the given type. If the function returns true, the edges will be added to the returned array of edges.

func (Edges) GetEdge added in v0.5.1

func (e Edges) GetEdge(id ID) (Edge, bool)

GetEdge gets an edge by id

func (Edges) HasEdge added in v0.5.1

func (e Edges) HasEdge(id ID) bool

HasEdge returns true if the edge exists

func (Edges) Len added in v0.5.1

func (e Edges) Len(typ string) int

Len returns the number of edges of the given type

func (Edges) Range added in v0.5.1

func (e Edges) Range(fn func(e Edge) bool)

Range executes the function over every edge. If the function returns false, the iteration stops.

func (Edges) RangeType added in v0.5.1

func (e Edges) RangeType(typ string, fn func(e Edge) bool)

RangeType executes the function over a list of edges with the given type. If the function returns false, the iteration stops.

func (Edges) Types added in v0.5.1

func (e Edges) Types() []string

type Graph

type Graph interface {
	// AddNode adds a single node to the graph
	AddNode(n Node)
	// AddNodes adds multiple nodes to the graph
	AddNodes(nodes ...Node)
	// GetNode gets a node from the graph if it exists
	GetNode(id ID) (Node, bool)
	// DelNode deletes the nodes and it's edges
	DelNode(id ID)
	// HasNode returns true if the node exists in the graph
	HasNode(id ID) bool
	// NodeTypes returns an array of Node types that exist in the graph
	NodeTypes() []string
	// RangeNodeTypes ranges over every node of the given type until the given function returns false
	RangeNodeTypes(typ string, fn func(n Node) bool)
	// RangeNodes ranges over every node until the given function returns false
	RangeNodes(fn func(n Node) bool)
	// AddEdge adds an edge to the graph between the two nodes. It returns an error if one of the nodes does not exist.
	AddEdge(e Edge) error
	// AddEdges adds all of the edges to the graph
	AddEdges(e Edges) error
	// GetEdge gets the edge by id if it exists
	GetEdge(id ID) (Edge, bool)
	// HasEdge returns true if the edge exists in the graph
	HasEdge(id ID) bool
	// DelEdge deletes the edge
	DelEdge(id ID)
	// DelEdges deletes all the edges at once
	DelEdges(e Edges) error
	// RangeEdges ranges over every edge until the given function returns false
	RangeEdges(fn func(e Edge) bool)
	// RangeEdgeTypes ranges over every edge of the given type until the given function returns false
	RangeEdgeTypes(typ string, fn func(e Edge) bool)
	// EdgesFrom returns all of the edges the point from the given node identifier
	EdgesFrom(id ID) (Edges, bool)
	// EdgesTo returns all of the edges the point to the given node identifier
	EdgesTo(id ID) (Edges, bool)
	// EdgeTypes returns all of the edge types in the Graph
	EdgeTypes() []string
	// Close removes all entries from the cache
	Close()
}

Graph is a concurrency safe directed Graph datastructure

func NewGraph

func NewGraph() Graph

type ID added in v0.5.1

type ID interface {
	// ID returns a string id
	ID() string
	// Type returns the string type
	Type() string
	// String returns a concatenation of id and type
	String() string
}

func BasicID added in v0.6.0

func BasicID(typ string, id string) ID

if id is empty, a random id will be assigned

type Map

type Map map[interface{}]interface{}

Map is a functional map for storing arbitrary data. It is not concurrency safe

func (Map) Copy

func (m Map) Copy() Map

Copy creates a replica of the Map

func (Map) Del

func (m Map) Del(k interface{})

Del deletes the entry from the map by key

func (Map) Exists

func (m Map) Exists(key interface{}) bool

Exists returns true if the key exists in the map

func (Map) Filter

func (m Map) Filter(filter func(k, v interface{}) bool) Map

Filter returns a map of the values that return true from the filter function

func (Map) Get

func (m Map) Get(k interface{}) (interface{}, bool)

Get gets an entry from the map by key

func (Map) Intersection

func (m Map) Intersection(other Map) Map

Intersection returns the values that exist in both maps ref: https://en.wikipedia.org/wiki/Intersection_(set_theory)#:~:text=In%20mathematics%2C%20the%20intersection%20of,that%20also%20belong%20to%20A).

func (Map) Range

func (m Map) Range(iterator func(k, v interface{}) bool)

Range iterates over the map with the function. If the function returns false, the iteration exits.

func (Map) Set

func (m Map) Set(k, v interface{})

Set set an entry in the map

func (Map) Union

func (m Map) Union(other Map) Map

Union returns the all values in both maps ref: https://en.wikipedia.org/wiki/Union_(set_theory)

type Node

type Node interface {
	ID
	// Attributes returns arbitrary data found in the node(if it exists)
	Attributes() Map
}

Node is a single element in the Graph. It may be connected to other Nodes via Edges

func BasicNode added in v0.6.0

func BasicNode(id ID, attributes Map) Node

Jump to

Keyboard shortcuts

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