1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Diffs have a magnitude.

This commit is contained in:
Rob Rix 2015-09-16 12:23:24 -04:00
parent e823f84d4a
commit 0dfd3a5ecd

View File

@ -28,6 +28,17 @@ public enum Diff: CustomDebugStringConvertible, CustomDocConvertible, Equatable
}
}
public var magnitude: Int {
switch self {
case .Empty:
return 0
case .Patch:
return 1
case let .Copy(s):
return s.map { $0.magnitude }.reduce(0, combine: +)
}
}
public init(_ a: Fix, _ b: Fix) {
switch (a, b) {
case (.Empty, .Empty):