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: Code/Graph+Algorithms/Graph+EssentialEdges.swift
+1-1
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ public extension Graph
7
7
8
8
Note that this will not remove any edges that are part of cycles (i.e. part of strongly connected components), since only considers edges of the condensation graph can be "non-essential". This is because it's [algorithmically](https://en.wikipedia.org/wiki/Feedback_arc_set#Hardness) as well as conceptually hard to decide which edges in cycles are "non-essential". We recommend dealing with cycles independently of using this function.
A `GraphEdge` is `Identifiable` by its ``GraphEdge/id-swift.property``, which is a combination of ``GraphEdge/originID`` and ``GraphEdge/destinationID``.
A shorthand for the edge's full generic type name `GraphEdge<NodeID>`
20
20
*/
21
-
publictypealiasEdge=GraphEdge<NodeID>
21
+
publictypealiasEdge=GraphEdge<NodeID,Weight>
22
22
23
23
// MARK: - Identity
24
24
@@ -47,20 +47,20 @@ public struct GraphEdge<NodeID: Hashable>: Identifiable, Equatable
47
47
/// Create a ``GraphEdge``, for instance to pass it to a ``Graph`` initializer.
48
48
publicinit(from originID:NodeID,
49
49
to destinationID:NodeID,
50
-
count:Int=1)
50
+
weight:Weight=1)
51
51
{
52
52
self.originID = originID
53
53
self.destinationID = destinationID
54
54
55
-
self.count=count
55
+
self.weight=weight
56
56
}
57
57
58
58
/**
59
-
A kind of edge weight. Indicates how often the edge was "added" to its graph.
59
+
The edge weight.
60
60
61
-
The count to "add" can be specified when adding an edge to a graph, see ``Graph/addEdge(from:to:count:)``. By default, adding the edge the first time sets its count to 1, and every time it gets added again adds 1 to its `count`.
61
+
If you don't need edge weights and want to save memory, you could specify `UInt8` (a.k.a. Byte) as the edge weight type, so each edge would require just one Byte instead of for example four or 8 Bytes for other numeric types.
62
62
*/
63
-
publicinternal(set)varcount:Int
63
+
publicinternal(set)varweight:Weight
64
64
65
65
/**
66
66
The origin ``GraphNode/id`` at which the edge starts / from which it goes out
Copy file name to clipboardExpand all lines: README.md
+5-6
Original file line number
Diff line number
Diff line change
@@ -222,12 +222,11 @@ SwiftNodes is already being used in production, but [Codeface](https://codeface.
222
222
223
223
1. Round out and add algorithms (starting with the needs of Codeface):
224
224
1. Make existing algorithms compatible with cycles (two algorithms are still not). meaning: don't hang or crash, maybe throw an error!
225
-
2. Model edge weights so they *can* be considered in algorithms like Dijkstra. Do we really need a third type parameter for `Graph`? Or just use `Double` as universal weight type? Do we merge that with edge count or keep both distinct?
226
-
3. Update and complete documentation
227
-
4. Move to version 1.0.0 if possible
228
-
5. Add general purpose graph traversal algorithms (BFT, DFT, compatible with potentially cyclic graphs)
229
-
6. Add better ways of topological sorting
230
-
7. Approximate the [minimum feedback arc set](https://en.wikipedia.org/wiki/Feedback_arc_set), so Codeface can guess "faulty" or unintended dependencies, i.e. the fewest dependencies that need to be cut in order to break all cycles.
225
+
2. Update and complete documentation
226
+
3. Move to version 1.0.0 if possible
227
+
4. Add general purpose graph traversal algorithms (BFT, DFT, compatible with potentially cyclic graphs)
228
+
5. Add better ways of topological sorting
229
+
6. Approximate the [minimum feedback arc set](https://en.wikipedia.org/wiki/Feedback_arc_set), so Codeface can guess "faulty" or unintended dependencies, i.e. the fewest dependencies that need to be cut in order to break all cycles.
231
230
2. Possibly optimize performance – but only based on measurements and only if measurements show that the optimization yields significant acceleration. Optimizing the algorithms might be more effective than optimizing the data structure itself.
232
231
* What role does `@inlinable` play here?
233
232
* What role does [`lazy`](https://developer.apple.com/documentation/swift/sequence/lazy) play here?
0 commit comments