Documentation
¶
Index ¶
- type Data
- func (d *Data) AddNode(nd *Node) bool
- func (d *Data) Clone() *Data
- func (d *Data) Connect(src, dst *Node, weight float32)
- func (d *Data) DeleteEdge(src, dst *Node)
- func (d *Data) DeleteNode(nd *Node)
- func (d *Data) GetEdgeWeight(src, dst *Node) float32
- func (d *Data) GetEdges() []Edge
- func (d *Data) GetNodeByID(id string) *Node
- func (d *Data) GetNodeSize() int
- func (d *Data) Init()
- func (d *Data) String() string
- func (d *Data) TopologicalDag() (Nodes, bool)
- func (d *Data) UpdateEdgeWeight(src, dst *Node, weight float32)
- type Edge
- type Node
- type Nodes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct { sync.Mutex // NodeMap is a hash-map for all Nodes in the graph. NodeMap map[*Node]bool // contains filtered or unexported fields }
Data contains graph data, represented in adjacency list and slice. Make sure to use Pointer when we need to update the struct with receiver. (https://golang.org/doc/faq#methods_on_values_or_pointers)
func (*Data) AddNode ¶
AddNode adds a Node to a graph Data. It returns true if the Node is added the graph Data.
func (*Data) Clone ¶
Clone clones(deep copy) the graph Data. (changing the cloned Data would not affect the original Data.) It traverses every single node with depth-first-search.
func (*Data) Connect ¶
Connect adds an edge from src(source) to dst(destination) Node, to a graph Data. This doese not connect from dst to src.
func (*Data) DeleteEdge ¶
DeleteEdge deletes an Edge from src to dst from the graph Data. This does not delete Nodes.
func (*Data) DeleteNode ¶
DeleteNode deletes a Node from the graph Data. This deletes all the related edges too.
func (*Data) GetEdgeWeight ¶
GetEdgeWeight returns the weight value of an edge from src to dst Node.
func (*Data) GetNodeByID ¶
GetNodeByID finds a Node by ID.
func (*Data) GetNodeSize ¶
GetNodeSize returns the size of Node of the graph Data.
func (*Data) TopologicalDag ¶
TopologicalDag does topological sort(ordering) with DFS. It returns true if the Graph is a DAG. (no cycle, have a topological sort) It returns false if the Graph is not a DAG. (cycle, have no topological sort) (http://en.wikipedia.org/wiki/Topological_sorting)
1 L ← Empty list that will contain the sorted nodes 2 while there are unmarked nodes do 3 select an unmarked node n 4 visit(n) 5 6 function visit(node n) 7 if n has a temporary mark then stop (not a DAG) 8 if n is not marked (i.e. has not been visited yet) then 9 mark n temporarily 10 for each node m with an edge from n to m do 11 visit(m) 12 mark n permanently 13 add n to head of L
func (*Data) UpdateEdgeWeight ¶
UpdateEdgeWeight overwrites the edge weight from src to dst Node.
type Node ¶
type Node struct { // ID of Node is assumed to be unique among Nodes. ID string // Color is used for graph traversal. Color string sync.Mutex // WeightTo maps its Node to outgoing Nodes with its edge weight (outgoing edges from its Node). WeightTo map[*Node]float32 // WeightFrom maps its Node to incoming Nodes with its edge weight (incoming edges to its Node). WeightFrom map[*Node]float32 }
Node is a Node(node) in Graph.