-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathItemGraph.go
90 lines (72 loc) · 1.47 KB
/
ItemGraph.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"sync"
)
//Node : Base structure for graph node implementation.
type Node struct {
mCar *Car
id string
isSemaphor bool
semaphorState bool
hasCar bool
isFinal bool
visited bool
}
//ItemGraph : Node storage (graph).
type ItemGraph struct {
nodes []*Node
edges map[*Node][]*Node
lock sync.RWMutex
}
//AddNode : used to add a node to the graph.
func (g *ItemGraph) AddNode(n *Node) {
g.lock.Lock()
g.nodes = append(g.nodes, n)
g.lock.Unlock()
}
//AddEdge : addes an edge to the graph
func (g *ItemGraph) AddEdge(n1, n2 *Node) {
g.lock.Lock()
if g.edges == nil {
g.edges = make(map[*Node][]*Node)
}
g.edges[n1] = append(g.edges[n1], n2)
g.lock.Unlock()
}
func (n *Node) getCar() *Car {
return n.mCar
}
func (n *Node) setCar(mCar *Car) {
n.hasCar = true
n.mCar = mCar
}
func (n *Node) getID() string {
return n.id
}
func (n *Node) getIsSemaphor() bool {
return n.isSemaphor
}
func (n *Node) setIsSemaphor(isSemaphor bool) {
n.isSemaphor = isSemaphor
}
func (n *Node) getSemaphorState() bool {
return n.semaphorState
}
func (n *Node) setSemaphorState(semaphoreState bool) {
n.semaphorState = semaphoreState
}
func (n *Node) getHasCar() bool {
return n.hasCar
}
func (n *Node) setHasCar(hasCar bool) {
n.hasCar = hasCar
}
func (n *Node) getisFinal() bool {
return n.isFinal
}
func (n *Node) getVisited() bool {
return n.visited
}
func (n *Node) setVisited(visited bool) {
n.visited = visited
}