Exemple #1
0
// If the lines immediately before those in the block move are identical,
// then grow the block move by one and repeat.
func GrowBackwards(p *dm.BlockMatch, aLines, bLines []dm.LinePos) {
	glog.Infof("GrowBackwards: dm.BlockMatch = %v", *p)

	aLimit, bLimit := aLines[0].Index, bLines[0].Index
	glog.Infof("GrowBackwards aLimit=%d, bLimit=%d", aLimit, bLimit)

	a := findLineWithIndex(aLines, p.AIndex)
	b := findLineWithIndex(bLines, p.BIndex)
	glog.Infof("GrowBackwards a=%d, b=%d", a, b)

	if aLines[a].Hash != bLines[b].Hash {
		glog.Fatalf("GrowBackwards: Lines %d and %d should have the same hash", a, b)
	}

	growBy := 0
	for a > aLimit && b > bLimit {
		a--
		b--
		if aLines[a].Hash != bLines[b].Hash {
			break
		}
		growBy++
	}

	glog.Infof("GrowBackwards growBy=%d", growBy)

	p.AIndex -= growBy
	p.BIndex -= growBy
	p.Length += growBy
}
Exemple #2
0
// If the lines immediately after those in the block move are identical,
// then grow the block move by one and repeat.
func GrowForwards(p *dm.BlockMatch, aLines, bLines []dm.LinePos) {
	glog.Infof("GrowForwards: dm.BlockMatch = %v", *p)

	aLimit := aLines[len(aLines)-1].Index
	bLimit := bLines[len(bLines)-1].Index
	glog.Infof("GrowForwards aLimit=%d, bLimit=%d", aLimit, bLimit)

	a := findLineWithIndex(aLines, p.AIndex+p.Length-1)
	b := findLineWithIndex(bLines, p.BIndex+p.Length-1)
	glog.Infof("GrowForwards a=%d, b=%d", a, b)

	if aLines[a].Hash != bLines[b].Hash {
		glog.Fatalf("GrowForwards: Lines %d and %d should have the same hash", a, b)
	}

	growBy := 0
	for a < aLimit && b < bLimit {
		a++
		b++
		if aLines[a].Hash != bLines[b].Hash {
			break
		}
		growBy++
	}

	glog.Infof("GrowForwards growBy=%d", growBy)

	p.Length += growBy
}