ranges

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package ranges provides tools to track the completeness of a range composed of a number of sub-ranges which may be added in any order.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tracker

type Tracker struct {
	// contains filtered or unexported fields
}

Tracker tracks a range of integer indices which may be split into a set of non-overlapping sub-ranges. The Tracker is defined over a range [start, end] with 0 <= start <= end.

As sub-ranges are added to the Tracker, the range being tracked progresses towards becoming complete. When the set of sub-ranges that have been added form a contiguous range equal to [start, end] the Tracker is complete.

If the set of sub-ranges that have been added include a sub-range whose first index is 'start' the Tracker is considered partially complete. Then, PartiallyCompleteUpto() can be used to determine the last index in a sub- range contiguous to the start.

Examples:

  1. Tracker for [0, 99]: sub-ranges [10, 19] and [30, 39] added -> neither complete nor partially complete.
  2. Tracker for [0, 99]: sub-ranges [0, 19] and [30, 39] added -> not complete, but partially complete upto 19.
  3. Tracker for [0, 99]: sub-ranges [0, 19] and [20, 39] added -> not complete, but partially complete upto 39.
  4. Tracker for [0, 99]: sub-ranges [50, 99] and [0, 49] added -> complete.

func NewTracker

func NewTracker(start, end int64) (*Tracker, error)

NewTracker returns a Tracker for the range [start, end].

func (*Tracker) AddSubRange

func (rt *Tracker) AddSubRange(first, last int64) error

AddSubRange records a sub-range. As sub-ranges are recorded, the low/mid/high watermarks are adjusted.

func (*Tracker) DebugString

func (rt *Tracker) DebugString() string

DebugString returns a verbose printable representation of the Tracker, including details of all added subranges, for debug use.

func (*Tracker) IsComplete

func (rt *Tracker) IsComplete() bool

IsComplete returns true if the union of recorded sub-ranges equals the expected range.

func (*Tracker) IsPartiallyComplete

func (rt *Tracker) IsPartiallyComplete() bool

IsPartiallyComplete returns true if a sub-range has been recorded whose first entry is located at the start of the expected range.

func (*Tracker) PartiallyCompleteUpto

func (rt *Tracker) PartiallyCompleteUpto() int64

PartiallyCompleteUpto returns the last entry of a set of contiguous recorded subranges that begins at the Tracker's start, or -1 if there are no subranges that satisfy this.

func (*Tracker) String

func (rt *Tracker) String() string

String returns a printable representation of the Tracker.

Jump to

Keyboard shortcuts

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