Documentation
¶
Overview ¶
Package gs implements graph using adjacency list and slice data structure.
Index ¶
- 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) FindVertexByID(id interface{}) *Vertex
- func (g Graph) GetEdgeWeight(src, dst *Vertex) float64
- func (g Graph) GetEdges() *slice.Sequence
- func (g Graph) GetEdgesSize() int
- func (g Graph) GetVertices() *slice.Sequence
- func (g Graph) GetVerticesSize() int
- func (g Graph) ImmediateDominate(A, B *Vertex) bool
- func (g *Graph) UpdateWeight(src, dst *Vertex, value float64)
- type Vertex
- func (i *Vertex) AddInVertex(v *Vertex)
- func (o *Vertex) AddOutVertex(v *Vertex)
- func (i *Vertex) DeleteInVertex(v *Vertex)
- func (o *Vertex) DeleteOutVertex(v *Vertex)
- func (v Vertex) GetInVertices() *slice.Sequence
- func (v Vertex) GetInVerticesSize() int
- func (v Vertex) GetOutVertices() *slice.Sequence
- 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) 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) FindVertexByID ¶
FindVertexByID returns the vertex with input ID , or return nil if it doesn't exist.
func (Graph) GetEdgeWeight ¶
GetEdgeWeight returns the slice of weight values of the edge from source to destination vertex. In case we need to allow duplicate edges, we can use slice.
func (Graph) GetEdgesSize ¶
GetEdgesSize returns the size of edge slice in a graph.
func (Graph) GetVertices ¶
GetVertices returns the vertex slice.
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 Vertex ¶
type Vertex struct { ID string Color string // slice of vertices that goes into this vertex // (vertices that precede this vertex in graph) InVertices *slice.Sequence // slice of vertices that go out of this vertex OutVertices *slice.Sequence // time stamp to record the distance // from source vertex StampD int64 // another timestamp to be used in other algorithms StampF int64 }
Vertex is a vertex(node) in Graph.
func (*Vertex) AddInVertex ¶
AddInVertex adds the vertex v to the vertex i's InVertices.
func (*Vertex) AddOutVertex ¶
AddOutVertex adds the vertex v to the vertex o's OutVertices.
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