Last active
December 27, 2019 18:34
-
-
Save eonil/353940f72d5bf930be74b40211540112 to your computer and use it in GitHub Desktop.
Topological Sort in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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