1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 08:25:19 +03:00

Merge pull request #102 from github/charge-a-constant-cost-to-patches

Charge a constant cost to patches
This commit is contained in:
Josh Vera 2015-10-14 16:47:47 -04:00
commit d49986c671
3 changed files with 203 additions and 241 deletions

View File

@ -16,17 +16,6 @@ public enum Patch<A>: CustomDebugStringConvertible, CustomDocConvertible {
}
/// The cost of a patch to the diff.
public var cost: Int {
switch self {
case .Replace:
return 2
default:
return 1
}
}
public var inverse: Patch {
switch self {
case let .Replace(a, b):

View File

@ -9,7 +9,7 @@ public func SES<A>(a: [Fix<A>], _ b: [Fix<A>], equals: (A, A) -> Bool, recur: (F
if b.isEmpty { return a.map { Diff.Pure(Patch.Delete($0)) } }
func cost(diff: Diff) -> Int {
return diff.map { $0.cost }.iterate { syntax in
return diff.map(const(1)).iterate { syntax in
switch syntax {
case .Leaf:
return 0
@ -82,4 +82,5 @@ public func SES<A>(a: [Fix<A>], _ b: [Fix<A>], equals: (A, A) -> Bool, recur: (F
import Memo
import Prelude
import Stream

View File

@ -1,5 +1,5 @@
[
[{
[{
"delete": [{
"source": "Algorithm",
"categories": [
@ -26,17 +26,6 @@
]
], {
"insert": [{
"source": "ByIndex",
"categories": [
]
},
[
]
]
}, {
"source": "mark",
"categories": [
@ -50,85 +39,6 @@
},
[
]
]
]
], {
"insert": [{
"source": "FreeAlgorithm",
"categories": [
]
},
[
[{
"source": "Pure",
"categories": [
]
},
[
]
],
[{
"source": "Roll",
"categories": [
]
},
[
]
],
[{
"source": "analysis(ifPure:ifRoll:)",
"categories": [
]
},
[
]
], {
"source": "mark",
"categories": [
]
},
[{
"source": "map(_:)",
"categories": [
]
},
[
]
], {
"source": "mark",
"categories": [
]
},
[{
"source": "flatMap(_:)",
"categories": [
]
},
[
]
],
[{
"source": "evaluate(_:recur:)",
"categories": [
]
},
[
]
]
]
@ -142,14 +52,49 @@
]
},
"after": [{
"source": "FreeAlgorithm",
"source": "Algorithm",
"categories": [
]
},
[
[{
"source": "evaluate(_:)",
"source": "Recursive",
"categories": [
]
},
[
]
],
[{
"source": "ByKey",
"categories": [
]
},
[
]
],
[{
"source": "ByIndex",
"categories": [
]
},
[
]
], {
"source": "mark",
"categories": [
]
},
[{
"source": "map(_:)",
"categories": [
]
@ -190,8 +135,8 @@
]
]
]
}, {
"delete": [{
},
[{
"source": "FreeAlgorithm",
"categories": [
@ -259,19 +204,28 @@
]
],
[{
"replace": {
"before": {
"source": "evaluate(_:)",
"categories": [
]
},
"after": {
"source": "evaluate(_:recur:)",
"categories": [
]
}
}
},
[
]
]
]
]
}, {
"delete": [{
],
[{
"source": "FreeAlgorithm",
"categories": [
@ -279,18 +233,27 @@
},
[
[{
"replace": {
"before": {
"source": "evaluate()",
"categories": [
]
},
"after": {
"source": "evaluate(_:)",
"categories": [
]
}
}
},
[
]
]
]
]
},
],
[{
"source": "FreeConvertible",
"categories": [
@ -338,8 +301,8 @@
]
}
]
],
[{
], {
"insert": [{
"source": "FreeAlgorithm",
"categories": [
@ -355,8 +318,8 @@
[
]
], {
"insert": [{
],
[{
"source": "evaluate(_:)",
"categories": [
@ -366,10 +329,10 @@
]
]
}
]
], {
"insert": [{
]
},
[{
"source": "FreeAlgorithm",
"categories": [
@ -377,10 +340,20 @@
},
[
[{
"replace": {
"before": {
"source": "init(_:_:)",
"categories": [
]
},
"after": {
"source": "evaluate()",
"categories": [
]
}
}
},
[
@ -388,5 +361,4 @@
]
]
]
}
]