You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Dijkstra Algorithm/README.md
+40-40Lines changed: 40 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -139,28 +139,28 @@ It is pretty simple
139
139
```swift
140
140
openclassVertex {
141
141
142
-
//Every vertex should be unique, that's why we set up identifier
142
+
//Every vertex should be unique, that's why we set up identifier
143
143
openvar identifier: String
144
144
145
-
//For dijkstra every vertex in the graph should be connected with at least one other vertex. But there can be some use cases,
146
-
//when you firstly initialize all vertices without neighbors. And then on next interation set up thei neighbors. So, initially neighbors is an empty array.
147
-
//Array contains tuples (Vertex, Double). Vertex is a neighbor and Double is as edge weight to that neighbor.
145
+
//For dijkstra every vertex in the graph should be connected with at least one other vertex. But there can be some use cases,
146
+
//when you firstly initialize all vertices without neighbors. And then on next interation set up thei neighbors. So, initially neighbors is an empty array.
147
+
//Array contains tuples (Vertex, Double). Vertex is a neighbor and Double is as edge weight to that neighbor.
148
148
openvar neighbors: [(Vertex, Double)] = []
149
149
150
-
//As it was mentioned in algorithm description, default path length from start for all vertices should be as much as possible.
151
-
//It is var, because we will update it during algorithm execution.
150
+
//As it was mentioned in algorithm description, default path length from start for all vertices should be as much as possible.
151
+
//It is var, because we will update it during algorithm execution.
152
152
openvar pathLengthFromStart =Double.infinity
153
-
154
-
//This array containt vertices, which we need to go through to reach this vertex from starting one
155
-
//As with path length from start, we will change this array during algorithm execution.
153
+
154
+
//This array containt vertices, which we need to go through to reach this vertex from starting one
155
+
//As with path length from start, we will change this array during algorithm execution.
156
156
openvar pathVerticesFromStart: [Vertex] = []
157
157
158
158
publicinit(identifier: String) {
159
159
self.identifier= identifier
160
160
}
161
161
162
-
//This function let us use the same array of vertices again and again to calculate paths with different starting vertex.
163
-
//When we will need to set new starting vertex andd recalculate paths, then we will simply clear graph vertices' cashes.
162
+
//This function let us use the same array of vertices again and again to calculate paths with different starting vertex.
163
+
//When we will need to set new starting vertex andd recalculate paths, then we will simply clear graph vertices' cashes.
164
164
openfuncclearCache() {
165
165
pathLengthFromStart =Double.infinity
166
166
pathVerticesFromStart = []
@@ -187,79 +187,79 @@ We've created a base for our algorithm. Now let's create a house :)
187
187
Dijkstra's realization is really straightforward.
188
188
```swift
189
189
publicclassDijkstra {
190
-
//This is a storage for vertices in the graph.
191
-
//Assuming, that our vertices are unique, we can use Set instead of array. This approach will bring some benefits later.
190
+
//This is a storage for vertices in the graph.
191
+
//Assuming, that our vertices are unique, we can use Set instead of array. This approach will bring some benefits later.
192
192
privatevar totalVertices: Set<Vertex>
193
193
194
194
publicinit(vertices: Set<Vertex>) {
195
195
totalVertices = vertices
196
196
}
197
197
198
-
//Remember clearCache function in the Vertex class implementation?
199
-
//This is just a wrapper that cleans cache for all stored vertices.
198
+
//Remember clearCache function in the Vertex class implementation?
199
+
//This is just a wrapper that cleans cache for all stored vertices.
0 commit comments