forked from TrueCloudLab/frostfs-node
[#972] pilorama: Remove removeDuplicatesInPlace()
Also, check that slices.CompareFunc() indeed passes all the tests before removal. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
e39a714c25
commit
45fd4e4ff1
2 changed files with 2 additions and 83 deletions
|
@ -2,6 +2,7 @@ package pilorama
|
|||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"slices"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -50,7 +51,7 @@ func (b *batch) run() {
|
|||
sort.Slice(b.operations, func(i, j int) bool {
|
||||
return b.operations[i].Time < b.operations[j].Time
|
||||
})
|
||||
b.operations = removeDuplicatesInPlace(b.operations)
|
||||
b.operations = slices.CompactFunc(b.operations, func(x, y *Move) bool { return x.Time == y.Time })
|
||||
|
||||
// Our main use-case is addition of new items. In this case,
|
||||
// we do not need to perform undo()/redo(), just do().
|
||||
|
@ -115,15 +116,3 @@ func (b *batch) run() {
|
|||
b.results[i] <- err
|
||||
}
|
||||
}
|
||||
|
||||
func removeDuplicatesInPlace(a []*Move) []*Move {
|
||||
equalCount := 0
|
||||
for i := 1; i < len(a); i++ {
|
||||
if a[i].Time == a[i-1].Time {
|
||||
equalCount++
|
||||
} else {
|
||||
a[i-equalCount] = a[i]
|
||||
}
|
||||
}
|
||||
return a[:len(a)-equalCount]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue