Skip to content

Commit 5d8deae

Browse files
committed
adding num edges
1 parent 0045cc1 commit 5d8deae

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

bin/main

0 Bytes
Binary file not shown.

graph.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ type Node Coordinate
1212

1313
// Graph Basic graph complete with concurrency safe lock
1414
type Graph struct {
15-
nodes Nodes
16-
edges Edges
17-
lock sync.RWMutex
15+
nodes Nodes
16+
edges Edges
17+
numEdges int64
18+
lock sync.RWMutex
1819
}
1920

2021
// Nodes map vals to pointers
@@ -36,6 +37,7 @@ func (graph *Graph) Init() {
3637
graph.lock.Lock()
3738
graph.nodes = make(Nodes)
3839
graph.edges = make(Edges)
40+
graph.numEdges = 0
3941
graph.lock.Unlock()
4042
}
4143

@@ -63,6 +65,7 @@ func (graph *Graph) AddEdge(n1, n2 *Node) {
6365
graph.edges[n1] = make(SetOfNodes)
6466
}
6567
graph.edges[n1][n2] = exists
68+
graph.numEdges++
6669
graph.lock.Unlock()
6770
}
6871

parse-geojson.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func createGraph(geojson GeoJSON) Graph {
5656
prev = node
5757
}
5858
}
59-
fmt.Println("geojson Graph created with", len(graph.nodes), "nodes")
59+
fmt.Println("geojson Graph created with", len(graph.nodes), "nodes and ", graph.numEdges, "edges")
6060
return graph
6161
}
6262

travel-api.go

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func homeLink(w http.ResponseWriter, r *http.Request) {
9393
var graph Graph
9494

9595
// var filename = "./data/greater-london-latest.geojson"
96+
9697
// var filename = "./data/central.geojson"
9798
var filename = "./data/cleaned.geojson"
9899

0 commit comments

Comments
 (0)