ranges

package
v1.58.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2022 License: MIT Imports: 1 Imported by: 7

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FoundRange

type FoundRange struct {
	R       Range
	Present bool
}

FoundRange is returned from FindAll

It contains a Range and a boolean as to whether the range was Present or not.

type Range

type Range struct {
	Pos  int64
	Size int64
}

Range describes a single byte range

func (*Range) Clip

func (r *Range) Clip(offset int64)

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

func (r Range) End() int64

End returns the end of the Range

func (Range) Intersection

func (r Range) Intersection(b Range) (intersection Range)

Intersection returns the common Range for two Range~s

If there is no intersection then the Range returned will have IsEmpty() true

func (Range) IsEmpty

func (r Range) IsEmpty() bool

IsEmpty true if the range has no size

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

func (rs Ranges) Equal(bs Ranges) bool

Equal returns true if rs == bs

func (Ranges) Find

func (rs Ranges) Find(r Range) (curr, next Range, present bool)

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

func (rs Ranges) FindMissing(r Range) (rout Range)

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

func (rs *Ranges) Insert(r Range)

Insert the new Range into a sorted and coalesced slice of Ranges. The result will be sorted and coalesced.

func (Ranges) Intersection

func (rs Ranges) Intersection(r Range) (newRs Ranges)

Intersection works out which ranges out of rs are entirely contained within r and returns a new Ranges

func (Ranges) Present

func (rs Ranges) Present(r Range) (present bool)

Present returns whether r can be satisfied by rs

func (Ranges) Size

func (rs Ranges) Size() (size int64)

Size returns the total size of all the segments

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL