``` goos: linux goarch: amd64 pkg: git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz │ old │ new │ │ sec/op │ sec/op vs base │ GetSubTree/latency-8 3.542m ± 12% 4.059m ± 20% +14.59% (p=0.005 n=10) GetSubTree/total_time-8 73.19m ± 9% 78.82m ± 4% +7.69% (p=0.043 n=10) geomean 16.10m 17.89m +11.09% │ old │ new │ │ B/op │ B/op vs base │ GetSubTree/latency-8 28.23Mi ± 0% 32.81Mi ± 0% +16.22% (p=0.000 n=10) GetSubTree/total_time-8 28.23Mi ± 0% 32.81Mi ± 0% +16.22% (p=0.000 n=10) geomean 28.23Mi 32.81Mi +16.22% │ old │ new │ │ allocs/op │ allocs/op vs base │ GetSubTree/latency-8 400.0k ± 0% 400.0k ± 0% +0.00% (p=0.000 n=10) GetSubTree/total_time-8 400.0k ± 0% 400.0k ± 0% +0.00% (p=0.000 n=10) geomean 400.0k 400.0k +0.00% ``` Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
47 lines
902 B
Go
47 lines
902 B
Go
package heap
|
|
|
|
import (
|
|
"bytes"
|
|
"sort"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
|
|
)
|
|
|
|
type OrderedSlice struct {
|
|
nodes []pilorama.NodeInfo
|
|
sorted bool
|
|
}
|
|
|
|
func NewOrderedSlice() *OrderedSlice {
|
|
return new(OrderedSlice)
|
|
}
|
|
|
|
func (s *OrderedSlice) Insert(infos ...pilorama.NodeInfo) {
|
|
s.sorted = false
|
|
s.nodes = append(s.nodes, infos...)
|
|
}
|
|
|
|
func (s *OrderedSlice) IsEmpty() bool {
|
|
return len(s.nodes) == 0
|
|
}
|
|
|
|
func (s *OrderedSlice) ExtractMin() pilorama.NodeInfo {
|
|
if !s.sorted {
|
|
sortByFilename(s.nodes)
|
|
s.sorted = true
|
|
}
|
|
|
|
node := s.nodes[0]
|
|
s.nodes = s.nodes[1:]
|
|
return node
|
|
}
|
|
|
|
func sortByFilename(nodes []pilorama.NodeInfo) {
|
|
if len(nodes) == 0 {
|
|
return
|
|
}
|
|
less := func(i, j int) bool {
|
|
return bytes.Compare(nodes[i].Meta.GetAttr(pilorama.AttributeFilename), nodes[j].Meta.GetAttr(pilorama.AttributeFilename)) < 0
|
|
}
|
|
sort.Slice(nodes, less)
|
|
}
|