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:
- Tracker for [0, 99]: sub-ranges [10, 19] and [30, 39] added -> neither complete nor partially complete.
- Tracker for [0, 99]: sub-ranges [0, 19] and [30, 39] added -> not complete, but partially complete upto 19.
- Tracker for [0, 99]: sub-ranges [0, 19] and [20, 39] added -> not complete, but partially complete upto 39.
- Tracker for [0, 99]: sub-ranges [50, 99] and [0, 49] added -> complete.
func NewTracker ¶
NewTracker returns a Tracker for the range [start, end].
func (*Tracker) AddSubRange ¶
AddSubRange records a sub-range. As sub-ranges are recorded, the low/mid/high watermarks are adjusted.
func (*Tracker) DebugString ¶
DebugString returns a verbose printable representation of the Tracker, including details of all added subranges, for debug use.
func (*Tracker) IsComplete ¶
IsComplete returns true if the union of recorded sub-ranges equals the expected range.
func (*Tracker) IsPartiallyComplete ¶
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 ¶
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.