github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/pkg/graveler/committed/range.go (about) 1 package committed 2 3 import ( 4 "bytes" 5 6 "google.golang.org/protobuf/proto" 7 ) 8 9 // Range represents a range of sorted Keys 10 type Range struct { 11 ID ID 12 MinKey Key 13 MaxKey Key 14 EstimatedSize uint64 // EstimatedSize estimated Range size in bytes 15 Count int64 16 Tombstone bool 17 } 18 19 func (r Range) Copy() *Range { 20 return &Range{ 21 ID: r.ID, 22 MinKey: r.MinKey.Copy(), 23 MaxKey: r.MaxKey.Copy(), 24 EstimatedSize: r.EstimatedSize, 25 Count: r.Count, 26 Tombstone: r.Tombstone, 27 } 28 } 29 30 func (r Range) EqualBounds(o *Range) bool { 31 return bytes.Equal(r.MinKey, o.MinKey) && bytes.Equal(r.MaxKey, o.MaxKey) 32 } 33 34 func (r Range) BeforeRange(o *Range) bool { 35 return bytes.Compare(r.MaxKey, o.MinKey) < 0 36 } 37 38 func MarshalRange(r Range) ([]byte, error) { 39 return proto.Marshal(&RangeData{ 40 MinKey: r.MinKey, 41 MaxKey: r.MaxKey, 42 EstimatedSize: r.EstimatedSize, 43 Count: r.Count, 44 }) 45 } 46 47 func UnmarshalRange(b []byte) (Range, error) { 48 var p RangeData 49 err := proto.Unmarshal(b, &p) 50 if err != nil { 51 return Range{}, err 52 } 53 return Range{ 54 MinKey: p.MinKey, 55 MaxKey: p.MaxKey, 56 EstimatedSize: p.EstimatedSize, 57 Count: p.Count, 58 }, nil 59 }