Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit f61f2da

Browse files
author
Wojciech Jabłoński
committed
simplified decisionType instances
Signed-off-by: Wojciech Jabłoński <wj359634@students.mimuw.edu.pl>
1 parent b08b00f commit f61f2da

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

uast/diff/diff.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ type decisionType interface {
1010
cost() int
1111
}
1212

13-
type basicDecision struct {
14-
privateCost int
15-
}
16-
17-
func (b basicDecision) cost() int { return b.privateCost }
18-
1913
// match decision types together with their params
20-
type sameDecision struct{ basicDecision }
21-
type replaceDecision struct{ basicDecision }
22-
type matchDecision struct{ basicDecision }
14+
type sameDecision struct{ privateCost int }
15+
type replaceDecision struct{ privateCost int }
16+
type matchDecision struct{ privateCost int }
2317
type permuteDecision struct {
24-
basicDecision
18+
privateCost int
2519
permutation []int
2620
}
2721

22+
func (d sameDecision) cost() int { return d.privateCost }
23+
func (d replaceDecision) cost() int { return d.privateCost }
24+
func (d matchDecision) cost() int { return d.privateCost }
25+
func (d permuteDecision) cost() int { return d.privateCost }
26+
2827
// min is a convinience method for choosing the cheapest decision
2928
func min(self, candidate decisionType) decisionType {
3029
if self.cost() > candidate.cost() {
@@ -76,7 +75,7 @@ func (ds *cacheStorage) decideAction(src, dst nodes.Node) decisionType {
7675
cost := ds.nodeSize(dst) + 1
7776

7877
var bestDecision decisionType
79-
bestDecision = replaceDecision{basicDecision{cost}}
78+
bestDecision = replaceDecision{cost}
8079

8180
if nodes.KindOf(src) != nodes.KindOf(dst) {
8281
ds.decisions[label] = bestDecision
@@ -91,10 +90,10 @@ func (ds *cacheStorage) decideAction(src, dst nodes.Node) decisionType {
9190
dst := dst.(nodes.Value)
9291
cost = 0
9392
if src == dst {
94-
bestDecision = min(bestDecision, sameDecision{basicDecision{cost}})
93+
bestDecision = min(bestDecision, sameDecision{cost})
9594
} else {
9695
cost = 1
97-
bestDecision = min(bestDecision, replaceDecision{basicDecision{cost}})
96+
bestDecision = min(bestDecision, replaceDecision{cost})
9897
}
9998

10099
case nodes.Object:
@@ -112,9 +111,9 @@ func (ds *cacheStorage) decideAction(src, dst nodes.Node) decisionType {
112111
}
113112

114113
if cost == 0 {
115-
bestDecision = min(bestDecision, sameDecision{basicDecision{cost}})
114+
bestDecision = min(bestDecision, sameDecision{cost})
116115
} else {
117-
bestDecision = min(bestDecision, matchDecision{basicDecision{cost}})
116+
bestDecision = min(bestDecision, matchDecision{cost})
118117
}
119118

120119
case nodes.Array:
@@ -126,7 +125,7 @@ func (ds *cacheStorage) decideAction(src, dst nodes.Node) decisionType {
126125
sum += ds.decideAction(src[i], dst[i]).cost()
127126
}
128127
if sum == 0 {
129-
bestDecision = min(bestDecision, sameDecision{basicDecision{cost}})
128+
bestDecision = min(bestDecision, sameDecision{cost})
130129
break
131130
}
132131
} else {
@@ -162,11 +161,11 @@ func (ds *cacheStorage) decideAction(src, dst nodes.Node) decisionType {
162161

163162
cost += res.Cost
164163

165-
bestDecision = min(bestDecision, permuteDecision{basicDecision{cost}, res.InRow})
164+
bestDecision = min(bestDecision, permuteDecision{cost, res.InRow})
166165

167166
case nil:
168167
cost = 0
169-
bestDecision = min(bestDecision, sameDecision{basicDecision{cost}})
168+
bestDecision = min(bestDecision, sameDecision{cost})
170169

171170
default:
172171
panic(fmt.Errorf("unknown node type %T", src))

0 commit comments

Comments
 (0)