mirror of
https://github.com/github/semantic.git
synced 2024-11-29 11:02:26 +03:00
Add a function from categorization functions to comparable functions.
This commit is contained in:
parent
2d21447312
commit
f8cd049280
@ -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: +)
|
||||
|
Loading…
Reference in New Issue
Block a user