offsetrange

package
v2.22.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package offsetrange defines a restriction and restriction tracker for offset ranges. An offset range is just a range, with a start and end, that can begin at an offset, and is commonly used to represent byte ranges for files or indices for iterable containers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Restriction

type Restriction struct {
	Start, End int64 // Half-closed interval with boundaries [start, end).
}

type Tracker

type Tracker struct {
	Rest    Restriction
	Claimed int64 // Tracks the last claimed position.
	Stopped bool  // Tracks whether TryClaim has already indicated to stop processing elements for
	// any reason.
	Err error
}

Tracker tracks a restriction that can be represented as a range of integer values, for example for byte offsets in a file, or indices in an array. Note that this tracker makes no assumptions about the positions of blocks within the range, so users must handle validation of block positions if needed.

func NewTracker

func NewTracker(rest Restriction) *Tracker

NewTracker is a constructor for an Tracker given a start and end range.

func (*Tracker) GetError

func (tracker *Tracker) GetError() error

IsDone returns true if the most recent claimed element is past the end of the restriction.

func (*Tracker) GetProgress

func (tracker *Tracker) GetProgress() (done, remaining float64)

GetProgress reports progress based on the claimed size and unclaimed sizes of the restriction.

func (*Tracker) IsDone

func (tracker *Tracker) IsDone() bool

IsDone returns true if the most recent claimed element is past the end of the restriction.

func (*Tracker) TryClaim

func (tracker *Tracker) TryClaim(rawPos interface{}) bool

TryClaim accepts an int64 position and successfully claims it if that position is greater than the previously claimed position and less than the end of the restriction. Note that the Tracker is not considered done until a position >= tracker.end tries to be claimed, at which point this method signals to end processing.

func (*Tracker) TrySplit

func (tracker *Tracker) TrySplit(fraction float64) (primary, residual interface{}, err error)

TrySplit splits at the nearest integer greater than the given fraction of the remainder. If the fraction given is outside of the [0, 1] range, it is clamped to 0 or 1.

Jump to

Keyboard shortcuts

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