@@ -7,15 +7,13 @@ package spanset
77
88import "slices"
99
10- // mergeSpans sorts the given spans and merges ones with overlapping
11- // spans and equal access timestamps. The implementation is a copy of
12- // roachpb.MergeSpans.
10+ // mergeSpans sorts the given spans and merges ones with overlapping spans and
11+ // equal access timestamps. The implementation is a modified roachpb.MergeSpans.
1312//
14- // Returns true iff all of the spans are distinct.
1513// The input spans are not safe for re-use.
16- func mergeSpans (latches []Span ) ( []Span , bool ) {
14+ func mergeSpans (latches []Span ) []Span {
1715 if len (latches ) == 0 {
18- return latches , true
16+ return latches
1917 }
2018
2119 // Sort first on the start key and second on the end key. Note that we're
@@ -31,7 +29,6 @@ func mergeSpans(latches []Span) ([]Span, bool) {
3129 // because "r" grows by at most 1 element on each iteration, staying abreast
3230 // or behind the iteration over "latches".
3331 r := latches [:1 ]
34- distinct := true
3532
3633 for _ , cur := range latches [1 :] {
3734 prev := & r [len (r )- 1 ]
@@ -44,7 +41,6 @@ func mergeSpans(latches []Span) ([]Span, bool) {
4441 if cur .Timestamp != prev .Timestamp {
4542 r = append (r , cur )
4643 }
47- distinct = false
4844 }
4945 continue
5046 }
@@ -56,7 +52,6 @@ func mergeSpans(latches []Span) ([]Span, bool) {
5652 } else {
5753 prev .EndKey = cur .EndKey
5854 }
59- distinct = false
6055 } else {
6156 // [a, nil] merge [b, c]
6257 r = append (r , cur )
@@ -73,15 +68,11 @@ func mergeSpans(latches []Span) ([]Span, bool) {
7368 } else {
7469 prev .EndKey = cur .EndKey
7570 }
76- if c > 0 {
77- distinct = false
78- }
7971 } else {
8072 // [a, c] merge [b, c]
8173 if cur .Timestamp != prev .Timestamp {
8274 r = append (r , cur )
8375 }
84- distinct = false
8576 }
8677 } else if c == 0 {
8778 // [a, b] merge [b, nil]
@@ -94,11 +85,10 @@ func mergeSpans(latches []Span) ([]Span, bool) {
9485 if cur .Timestamp != prev .Timestamp {
9586 r = append (r , cur )
9687 }
97- distinct = false
9888 }
9989 continue
10090 }
10191 r = append (r , cur )
10292 }
103- return r , distinct
93+ return r
10494}
0 commit comments