+
+ return merged
+}
+
+// Coarsen takes each merge of other, a view of the same messages, and then
+// merges in one batch until the size is at most low. Each line of the result is
+// the coarser of the two lines that start at its first message. Dyadic ranges
+// either nest or do not overlap, so the result covers the messages without a
+// gap.
+func (v *View) Coarsen(other *View, tree nodeReader) {
+ lines := make([]nodeKey, 0, len(v.lines))
+ mine, theirs := 0, 0
+ for start := 0; start < v.end; {
+ line := v.lines[mine]
+ if other.lines[theirs].level > line.level {
+ line = other.lines[theirs]
+ }
+
+ lines = append(lines, line)
+ start = nodeEnd(line.level, line.index)
+ for mine < len(v.lines) && v.lines[mine].index<<v.lines[mine].level < start {
+ mine++
+ }
+
+ for theirs < len(other.lines) && other.lines[theirs].index<<other.lines[theirs].level < start {
+ theirs++
+ }
+ }
+
+ v.lines = lines
+ v.merging = true
+ v.fit(tree)