Documentation ¶
Overview ¶
Package gm implements graph using adjacency list and map data structure.
Index ¶
- type EMAP
- type Edge
- type Graph
- func (g *Graph) AddEdge(e *Edge)
- func (g *Graph) AddVertex(v *Vertex)
- func (g *Graph) Connect(A, B *Vertex, weight float64)
- func (g *Graph) CreateAndAddToGraph(id string) *Vertex
- func (g *Graph) DeleteEdge(A, B *Vertex)
- func (g *Graph) DeleteVertex(A *Vertex)
- func (g Graph) GetEdgeWeight(src, dst *Vertex) float64
- func (g Graph) GetEdges() EMAP
- func (g Graph) GetEdgesSize() int
- func (g Graph) GetVertices() VMAP
- func (g Graph) GetVerticesSize() int
- func (g Graph) ImmediateDominate(A, B *Vertex) bool
- func (g *Graph) UpdateWeight(src, dst *Vertex, value float64)
- type VMAP
- type Vertex
- func (A *Vertex) AddInVertex(B *Vertex)
- func (A *Vertex) AddOutVertex(B *Vertex)
- func (i *Vertex) DeleteInVertex(v *Vertex)
- func (o *Vertex) DeleteOutVertex(v *Vertex)
- func (v Vertex) GetInVertices() VMAP
- func (v Vertex) GetInVerticesSize() int
- func (v Vertex) GetOutVertices() VMAP
- func (v Vertex) GetOutVerticesSize() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Graph ¶
Graph is a graph represented in adjacency list, but implemented in slice.
func ParseToGraph ¶
ParseToGraph parses string data to return a new graph.
func (*Graph) AddEdge ¶
AddEdge adds the edge e to the graph g's Edges. Only to be used when there is no duplicate edge.
func (*Graph) AddVertex ¶
AddVertex adds the vertex v to the graph g's Vertices. Only to be used when there is no duplicate vertex.
func (*Graph) CreateAndAddToGraph ¶
CreateAndAddToGrammar finds the vertex with the ID, or create it.
func (*Graph) DeleteEdge ¶
DeleteEdge deletes the edge from the vertex A to B. Note that this only delete one direction from A to B.
func (*Graph) DeleteVertex ¶
DeleteVertex removes the input vertex A from the graph g's Vertices.
func (Graph) GetEdgeWeight ¶
GetEdgeWeight returns the weight value. Our graph does not allow the duplicate edges. If there is a duplicate edges, the value is added to the existent weight.
func (Graph) GetEdgesSize ¶
GetEdgesSize returns the size of edge slice in a graph.
func (Graph) GetVerticesSize ¶
GetVerticesSize returns the size of vertex slice in a graph.
func (Graph) ImmediateDominate ¶
ImmediateDominate returns true if A immediately dominates B. That is, true if A can go to B with only one edge.
func (*Graph) UpdateWeight ¶
UpdateWeight updates the weight value between vertices.
type VMAP ¶
string is just to map the ID to the Vertex. Do not map "Vertex" to string since VMAP will be used as slice and the map does not allow duplicate keys.
type Vertex ¶
type Vertex struct { ID string Color string // slice of vertices that goes into this vertex // (vertices that precede this vertex in graph) InVertices VMAP // slice of vertices that go out of this vertex OutVertices VMAP // contains filtered or unexported fields }
Vertex is a vertex(node) in Graph.
func (*Vertex) AddInVertex ¶
AddInVertex adds the vertex B to the vertex A's InVertices. B goes into A.
func (*Vertex) AddOutVertex ¶
AddOutVertex adds the vertex B to the vertex A's OutVertices. A goes out to B.
func (*Vertex) DeleteInVertex ¶
DeleteInVertex removes the input vertex v from the vertex i's InVertices.
func (*Vertex) DeleteOutVertex ¶
DeleteOutVertex removes the input vertex v from the vertex o's OutVertices.
func (Vertex) GetInVertices ¶
GetInVertices returns a slice of adjacent vertices that goes to vertex v.
func (Vertex) GetInVerticesSize ¶
GetInVerticesSize returns the size of the vertex v's InVertices.
func (Vertex) GetOutVertices ¶
GetOutVertices returns a slice of adjacent vertices from vertex v.
func (Vertex) GetOutVerticesSize ¶
GetOutVerticesSize returns the size of the vertex v's OutVertices