minigraph

package
v0.0.0-...-75e3e40 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2018 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TYPE_NODE = iota
	TYPE_ENDPOINT
	TYPE_NETWORK
)
View Source
const (
	UNCONNECTED = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

type Edge struct {
	N int
	D map[string]string
}

An endpoint network. Edges contain a reference to a connected network, or UNCONNECTED.

func (*Edge) Match

func (e *Edge) Match(k, v string) bool

type Endpoint

type Endpoint struct {
	NID   int
	Edges []*Edge
	D     map[string]string
}

A network endpoint (regular endpoint, router, etc.). Endpoints contain a map for specifying arbitrary information (tags, disk images, etc.).

func (*Endpoint) Connected

func (e *Endpoint) Connected(n int) bool

Connected returns true if the endpoint is connected to the node referenced by the given node ID.

func (*Endpoint) Data

func (e *Endpoint) Data() map[string]string

func (*Endpoint) HasEdge

func (e *Endpoint) HasEdge(edge *Edge) bool

HasEdge returns true when the specified edge is in the endpoint.

func (*Endpoint) ID

func (e *Endpoint) ID() int

Return the ID of the endpoint.

func (*Endpoint) Match

func (e *Endpoint) Match(k, v string) bool

func (*Endpoint) Neighbors

func (e *Endpoint) Neighbors() []int

Return IDs of connected neighbors

func (*Endpoint) NewEdge

func (e *Endpoint) NewEdge() *Edge

func (*Endpoint) String

func (e *Endpoint) String() string

func (*Endpoint) Type

func (e *Endpoint) Type() int

Return the type. Used as a fast alternative to reflection when using the Node interface.

type Graph

type Graph struct {
	Nodes map[int]Node
	// contains filtered or unexported fields
}

func New

func New() *Graph

func Read

func Read(f io.Reader) (*Graph, error)

read graph contents from an io.Reader. If an io.EOF occurs without reading any data, assume an empty reader and return a new graph.

func (*Graph) Connect

func (g *Graph) Connect(e, n Node, edge *Edge) error

connect an endpoint to a network on a given edge. A node may only have a single connection to a given network. The edge must belong to e.

func (*Graph) Delete

func (g *Graph) Delete(n Node) error

Delete a node from the graph and remove all references to it in other nodes.

func (*Graph) Disconnect

func (g *Graph) Disconnect(n1, n2 Node) error

disconnect a node from a network.

func (*Graph) FindEndpoints

func (g *Graph) FindEndpoints(k string, v string) []*Endpoint

func (*Graph) FindNetworks

func (g *Graph) FindNetworks(k string, v string) []*Network

func (*Graph) FindNodes

func (g *Graph) FindNodes(k string, v string) []Node

return a list of nodes that contain the string v in the key k

func (*Graph) GetEndpoints

func (g *Graph) GetEndpoints() []*Endpoint

func (*Graph) GetNetworks

func (g *Graph) GetNetworks() []*Network

func (*Graph) GetNodes

func (g *Graph) GetNodes() []Node

func (*Graph) HasNode

func (g *Graph) HasNode(n Node) bool

HasNode returns true if a given node is in the graph

func (*Graph) Insert

func (g *Graph) Insert(n Node) (Node, error)

func (*Graph) NewEndpoint

func (g *Graph) NewEndpoint() *Endpoint

func (*Graph) NewNetwork

func (g *Graph) NewNetwork() *Network

func (*Graph) Update

func (g *Graph) Update(n Node) (Node, error)

func (*Graph) Write

func (g *Graph) Write(f io.Writer) error

type Network

type Network struct {
	NID       int
	Endpoints []int
	D         map[string]string
}

func (*Network) Connected

func (n *Network) Connected(e int) bool

Connected returns true if the network is connected to the node referenced by the given node ID.

func (*Network) Data

func (n *Network) Data() map[string]string

func (*Network) ID

func (n *Network) ID() int

Return the ID of the network

func (*Network) Match

func (n *Network) Match(k, v string) bool

func (*Network) Neighbors

func (n *Network) Neighbors() []int

Return IDs of connected neighbors

func (*Network) String

func (n *Network) String() string

func (*Network) Type

func (n *Network) Type() int

Return the type. Used as a fast alternative to reflection when using the Node interface.

type Node

type Node interface {
	ID() int
	Type() int
	Connected(int) bool
	Neighbors() []int
	Match(string, string) bool

	Data() map[string]string
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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