Skip to content

Instantly share code, notes, and snippets.

@eonil
Last active December 27, 2019 18:34
Show Gist options
  • Save eonil/353940f72d5bf930be74b40211540112 to your computer and use it in GitHub Desktop.
Save eonil/353940f72d5bf930be74b40211540112 to your computer and use it in GitHub Desktop.
Topological Sort in Swift
extension RelPath: Comparable {
/// Sorts by lexicographical topological order.
public static func < (_ a:RelPath, _ b:RelPath) -> Bool {
let c = Swift.min(a.count, b.count)
for i in 0..<c {
if a[i] < b[i] { return true }
if a[i] > b[i] { return false }
}
return a.count < b.count
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment