Exemple #1
0
func findCommon(taller, shorter *types.RefByHeight, height uint64) (tallRefs, comRefs types.RefSlice) {
	d.Chk.True(tallestHeight(taller) == height)
	d.Chk.True(tallestHeight(shorter) == height)
	comIndices := []int{}
	// Walk through shorter and taller in tandem from the back (where the tallest Refs are). Refs from taller that go into a work queue are popped off directly, but doing so to shorter would mess up shortIdx. So, instead just keep track of the indices of common refs and drop them from shorter at the end.
	for shortIdx := shorter.Len() - 1; !taller.Empty() && tallestHeight(taller) == height; {
		tallPeek := taller.PeekEnd()
		shortPeek := shorter.PeekAt(shortIdx)
		if types.HeightOrder(tallPeek, shortPeek) {
			tallRefs = append(tallRefs, taller.PopBack())
			continue
		}
		if shortPeek.Equals(tallPeek) {
			comIndices = append(comIndices, shortIdx)
			comRefs = append(comRefs, taller.PopBack())
		}
		shortIdx--
	}
	shorter.DropIndices(comIndices)
	return
}
Exemple #2
0
func tallestHeight(h *types.RefByHeight) uint64 {
	return h.PeekEnd().Height()
}