1
1
mirror of https://github.com/github/semantic.git synced 2024-11-25 21:43:07 +03:00

Add a function from categorization functions to comparable functions.

This commit is contained in:
Rob Rix 2015-10-15 15:39:55 -04:00
parent 2d21447312
commit f8cd049280

View File

@ -16,6 +16,14 @@ public struct Interpreter<Term: TermType> {
self.cost = cost
}
/// Computes a term comparable function from a categorizing function.
public static func comparable<C>(categorize: Term -> Set<C>)(_ a: Term, _ b: Term) -> Bool {
let c0 = categorize(a)
let c1 = categorize(b)
return c0 == c1 || !categorize(a).intersect(categorize(b)).isEmpty
}
/// Computes a diff cost function from a patch cost function.
public static func cost(cost: Patch<Term> -> Int)(_ diff: Diff) -> Int {
return diff.map(cost).reduce(0, combine: +)