Skip to content

Commit 9aedeff

Browse files
committed
internal/manifest: use slices.SortFunc
Use slices.SortFunc instead of implementing the sort.Interface in the implementation of L0 sublevels.
1 parent afc46e9 commit 9aedeff

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

internal/manifest/l0_sublevels.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -261,21 +261,10 @@ type L0Sublevels struct {
261261
addL0FilesCalled bool
262262
}
263263

264-
type sublevelSorter []*TableMetadata
265-
266-
// Len implements sort.Interface.
267-
func (sl sublevelSorter) Len() int {
268-
return len(sl)
269-
}
270-
271-
// Less implements sort.Interface.
272-
func (sl sublevelSorter) Less(i, j int) bool {
273-
return sl[i].minIntervalIndex < sl[j].minIntervalIndex
274-
}
275-
276-
// Swap implements sort.Interface.
277-
func (sl sublevelSorter) Swap(i, j int) {
278-
sl[i], sl[j] = sl[j], sl[i]
264+
func sortByMinIntervalIndex(files []*TableMetadata) {
265+
slices.SortFunc(files, func(a, b *TableMetadata) int {
266+
return stdcmp.Compare(a.minIntervalIndex, b.minIntervalIndex)
267+
})
279268
}
280269

281270
// NewL0Sublevels creates an L0Sublevels instance for a given set of L0 files.
@@ -331,7 +320,7 @@ func NewL0Sublevels(
331320
}
332321
// Sort each sublevel in increasing key order.
333322
for i := range s.levelFiles {
334-
sort.Sort(sublevelSorter(s.levelFiles[i]))
323+
sortByMinIntervalIndex(s.levelFiles[i])
335324
}
336325

337326
// Construct a parallel slice of sublevel B-Trees.
@@ -623,7 +612,7 @@ func (s *L0Sublevels) AddL0Files(
623612

624613
// Sort each updated sublevel in increasing key order.
625614
for _, sublevel := range updatedSublevels {
626-
sort.Sort(sublevelSorter(newVal.levelFiles[sublevel]))
615+
sortByMinIntervalIndex(newVal.levelFiles[sublevel])
627616
}
628617

629618
// Construct a parallel slice of sublevel B-Trees.

0 commit comments

Comments
 (0)