Documentation ¶
Overview ¶
Package ranges provides the Ranges type for keeping track of byte ranges which may or may not be present in an object.
Index ¶
- type FoundRange
- type Range
- type Ranges
- func (rs Ranges) Equal(bs Ranges) bool
- func (rs Ranges) Find(r Range) (curr, next Range, present bool)
- func (rs Ranges) FindAll(r Range) (frs []FoundRange)
- func (rs Ranges) FindMissing(r Range) (rout Range)
- func (rs *Ranges) Insert(r Range)
- func (rs Ranges) Intersection(r Range) (newRs Ranges)
- func (rs Ranges) Present(r Range) (present bool)
- func (rs Ranges) Size() (size int64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FoundRange ¶
FoundRange is returned from FindAll
It contains a Range and a boolean as to whether the range was Present or not.
type Range ¶
Range describes a single byte range
func (*Range) Clip ¶
Clip ensures r.End() <= offset by modifying r.Size if necessary
if r.Pos > offset then a Range{Pos:0, Size:0} will be returned.
func (Range) Intersection ¶
Intersection returns the common Range for two Range~s
If there is no intersection then the Range returned will have IsEmpty() true
type Ranges ¶
type Ranges []Range
Ranges describes a number of Range segments. These should only be added with the Ranges.Insert function. The Ranges are kept sorted and coalesced to the minimum size.
func (Ranges) Find ¶
Find searches for r in rs and returns the next present or absent Range. It returns:
curr which is the Range found next is the Range which should be presented to Find next present shows whether curr is present or absent
if !next.IsEmpty() then Find should be called again with r = next to retrieve the next Range.
Note that r.Pos == curr.Pos always
func (Ranges) FindAll ¶
func (rs Ranges) FindAll(r Range) (frs []FoundRange)
FindAll repeatedly calls Find searching for r in rs and returning present or absent ranges.
It returns a slice of FoundRange. Each element has a range and an indication of whether it was present or not.
func (Ranges) FindMissing ¶
FindMissing finds the initial part of r that is not in rs
If r is entirely present in rs then r an empty block will be returned.
If r is not present in rs then the block returned will have IsEmpty return true.
If r is partially present in rs then a new block will be returned which starts with the first part of rs that isn't present in r. The End() for this block will be the same as originally passed in.
For all returns rout.End() == r.End()
func (*Ranges) Insert ¶
Insert the new Range into a sorted and coalesced slice of Ranges. The result will be sorted and coalesced.
func (Ranges) Intersection ¶
Intersection works out which ranges out of rs are entirely contained within r and returns a new Ranges