This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getShortestPath(startNode *Node, endNode *Node, g *ItemGraph) ([]string, int) { | |
| visited := make(map[string]bool) | |
| dist := make(map[string]int) | |
| prev := make(map[string]string) | |
| //pq := make(PriorityQueue, 1) | |
| //heap.Init(&pq) | |
| q := NodeQueue{} | |
| pq := q.NewQ() | |
| start := Vertex{ | |
| Node: startNode, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type ItemGraph struct { | |
| Nodes []*Node | |
| Edges map[Node][]*Edge | |
| Lock sync.RWMutex | |
| } | |
| // AddNode adds a node to the graph | |
| func (g *ItemGraph) AddNode(n *Node) { | |
| g.Lock.Lock() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package datastruct | |
| // Enqueue adds an Node to the end of the queue | |
| func (s *NodeQueue) Enqueue(t Vertex) { | |
| s.Lock.Lock() | |
| if len(s.Items) == 0 { | |
| s.Items = append(s.Items, t) | |
| s.Lock.Unlock() | |
| return | |
| } |