File tree 2 files changed +4
-23
lines changed
2 files changed +4
-23
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package quorum
17
17
import (
18
18
"fmt"
19
19
"math"
20
+ "slices"
20
21
"sort"
21
22
"strings"
22
23
)
@@ -112,15 +113,6 @@ func (c MajorityConfig) Slice() []uint64 {
112
113
return sl
113
114
}
114
115
115
- func insertionSort (sl []uint64 ) {
116
- a , b := 0 , len (sl )
117
- for i := a + 1 ; i < b ; i ++ {
118
- for j := i ; j > a && sl [j ] < sl [j - 1 ]; j -- {
119
- sl [j ], sl [j - 1 ] = sl [j - 1 ], sl [j ]
120
- }
121
- }
122
- }
123
-
124
116
// CommittedIndex computes the committed index from those supplied via the
125
117
// provided AckedIndexer (for the active config).
126
118
func (c MajorityConfig ) CommittedIndex (l AckedIndexer ) Index {
@@ -159,10 +151,7 @@ func (c MajorityConfig) CommittedIndex(l AckedIndexer) Index {
159
151
}
160
152
}
161
153
}
162
-
163
- // Sort by index. Use a bespoke algorithm (copied from the stdlib's sort
164
- // package) to keep srt on the stack.
165
- insertionSort (srt )
154
+ slices .Sort (srt )
166
155
167
156
// The smallest index into the array for which the value is acked by a
168
157
// quorum. In other words, from the end of the slice, move n/2+1 to the
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ package tracker
16
16
17
17
import (
18
18
"fmt"
19
+ "slices"
19
20
"sort"
20
21
"strings"
21
22
@@ -180,15 +181,6 @@ func (p *ProgressTracker) Committed() uint64 {
180
181
return uint64 (p .Voters .CommittedIndex (matchAckIndexer (p .Progress )))
181
182
}
182
183
183
- func insertionSort (sl []uint64 ) {
184
- a , b := 0 , len (sl )
185
- for i := a + 1 ; i < b ; i ++ {
186
- for j := i ; j > a && sl [j ] < sl [j - 1 ]; j -- {
187
- sl [j ], sl [j - 1 ] = sl [j - 1 ], sl [j ]
188
- }
189
- }
190
- }
191
-
192
184
// Visit invokes the supplied closure for all tracked progresses in stable order.
193
185
func (p * ProgressTracker ) Visit (f func (id uint64 , pr * Progress )) {
194
186
n := len (p .Progress )
@@ -206,7 +198,7 @@ func (p *ProgressTracker) Visit(f func(id uint64, pr *Progress)) {
206
198
n --
207
199
ids [n ] = id
208
200
}
209
- insertionSort (ids )
201
+ slices . Sort (ids )
210
202
for _ , id := range ids {
211
203
f (id , p .Progress [id ])
212
204
}
You can’t perform that action at this time.
0 commit comments