Skip to content

Commit 8817b06

Browse files
committed
manifest: use slices.SortFunc
Replace a lingering implementation of the sort.Interface with a use of slices.SortFunc.
1 parent 90c914a commit 8817b06

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

internal/manifest/l0_sublevels.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,19 +1182,15 @@ func (l *L0CompactionFiles) addFile(f *TableMetadata) {
11821182
l.maxIntervalIndex = max(l.maxIntervalIndex, f.maxIntervalIndex)
11831183
}
11841184

1185-
// Helper to order intervals being considered for compaction.
11861185
type intervalAndScore struct {
11871186
interval int
11881187
score int
11891188
}
1190-
type intervalSorterByDecreasingScore []intervalAndScore
11911189

1192-
func (is intervalSorterByDecreasingScore) Len() int { return len(is) }
1193-
func (is intervalSorterByDecreasingScore) Less(i, j int) bool {
1194-
return is[i].score > is[j].score
1195-
}
1196-
func (is intervalSorterByDecreasingScore) Swap(i, j int) {
1197-
is[i], is[j] = is[j], is[i]
1190+
func sortIntervalsByDecreasingScore(s []intervalAndScore) {
1191+
slices.SortFunc(s, func(a, b intervalAndScore) int {
1192+
return stdcmp.Compare(b.score, a.score)
1193+
})
11981194
}
11991195

12001196
// Compactions:
@@ -1401,7 +1397,7 @@ func (s *l0Sublevels) PickBaseCompaction(
14011397
scoredIntervals = append(scoredIntervals, intervalAndScore{interval: i, score: depth + sublevelCount})
14021398
}
14031399
}
1404-
sort.Sort(intervalSorterByDecreasingScore(scoredIntervals))
1400+
sortIntervalsByDecreasingScore(scoredIntervals)
14051401

14061402
// Optimization to avoid considering different intervals that
14071403
// are likely to choose the same seed file. Again this is just
@@ -1614,7 +1610,7 @@ func (s *l0Sublevels) PickIntraL0Compaction(
16141610
}
16151611
scoredIntervals[i] = intervalAndScore{interval: i, score: depth}
16161612
}
1617-
sort.Sort(intervalSorterByDecreasingScore(scoredIntervals))
1613+
sortIntervalsByDecreasingScore(scoredIntervals)
16181614

16191615
// Optimization to avoid considering different intervals that are likely to
16201616
// choose the same seed file. Again this is just to reduce wasted work.

0 commit comments

Comments
 (0)