-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
model: Serialize dependency graph edges in some explicit order #8696
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,7 +179,7 @@ class DependencyGraphBuilder<D>( | |
) | ||
} | ||
|
||
private fun Collection<DependencyGraphEdge>.removeCycles(): List<DependencyGraphEdge> { | ||
private fun Set<DependencyGraphEdge>.removeCycles(): Set<DependencyGraphEdge> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the spirit of "be lenient when consuming, be strict when producing", should the receiver stay a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe in general it makes sense, in this case I decided against it so that one does not have to even think about what happens when input contains duplicates, because the API is private (small scope), and because there is no use besides the Sets one. |
||
val edges = toMutableSet() | ||
val edgesToKeep = breakCycles(edges) | ||
val edgesToRemove = edges - edgesToKeep | ||
|
@@ -188,7 +188,7 @@ class DependencyGraphBuilder<D>( | |
logger.warn { "Removing edge '${it.from} -> ${it.to}' to break a cycle." } | ||
} | ||
|
||
return filter { it in edgesToKeep } | ||
return filterTo(mutableSetOf()) { it in edgesToKeep } | ||
} | ||
|
||
private fun checkReferences() { | ||
|
@@ -436,9 +436,9 @@ class DependencyGraphBuilder<D>( | |
*/ | ||
private fun Collection<DependencyReference>.toGraph( | ||
indexMapping: IntArray | ||
): Pair<List<DependencyGraphNode>, List<DependencyGraphEdge>> { | ||
): Pair<List<DependencyGraphNode>, Set<DependencyGraphEdge>> { | ||
val nodes = mutableSetOf<DependencyGraphNode>() | ||
val edges = mutableListOf<DependencyGraphEdge>() | ||
val edges = mutableSetOf<DependencyGraphEdge>() | ||
val nodeIndices = mutableMapOf<NodeKey, Int>() | ||
|
||
fun getOrAddNodeIndex(ref: DependencyReference): Int = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment in line 102 should now also say "set" instead of "list". Also, the commit message should probably also mention that order is not important either (even if a set usually maintains insertion order).