File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ "sync"
6+ )
7+
8+ type SafeGraph struct {
9+ container Graph
10+ mutex sync.Mutex
11+ }
12+
13+ func (graph * SafeGraph ) changeRoutePrice (firstCity , secondCity string , newPrice int ) {
14+ graph .mutex .Lock ()
15+ graph .container .changePrice (firstCity , secondCity , newPrice )
16+ graph .mutex .Unlock ()
17+ }
18+
19+ func (graph * SafeGraph ) addRoute (firstCity , secondCity string , price int ) {
20+ graph .mutex .Lock ()
21+ graph .container .addEdge (firstCity , secondCity , price )
22+ graph .mutex .Unlock ()
23+ }
24+
25+ func (graph * SafeGraph ) deleteRoute (firstCity , secondCity string ) {
26+ graph .mutex .Lock ()
27+ graph .container .deleteEdge (firstCity , secondCity )
28+ graph .mutex .Unlock ()
29+ }
30+
31+ func (graph * SafeGraph ) addCity (city string ) {
32+ graph .mutex .Lock ()
33+ graph .container .addVertex (city )
34+ graph .mutex .Unlock ()
35+ }
36+
37+ func (graph * SafeGraph ) deleteCity (city string ) {
38+ graph .mutex .Lock ()
39+ graph .container .deleteVertex (city )
40+ graph .mutex .Unlock ()
41+ }
42+
43+ func (graph * SafeGraph ) getPathCost (firstCity , secondCity string ) {
44+ graph .mutex .Lock ()
45+ exists , cost := graph .container .getPathCost (firstCity , secondCity )
46+ graph .mutex .Unlock ()
47+
48+ if exists {
49+ fmt .Printf ("\" %s\" -> \" %s\" route cost is %d\n " , firstCity , secondCity , cost )
50+ } else {
51+ fmt .Printf ("There is no route between \" %s\" and \" %s\" \n " , firstCity , secondCity )
52+ }
53+ }
54+
55+ func (graph * SafeGraph ) printGraphviz (name string ) {
56+ graph .mutex .Lock ()
57+ println (graph .container .getGraphvizInfo (name ))
58+ graph .mutex .Unlock ()
59+ }
You can’t perform that action at this time.
0 commit comments