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) }