rangeset

package
v3.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package rangeset implements a half-open interval set [start, end). It is intended to be used for working with many large ranges of valid or invalid rows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Range

type Range struct {
	Start uint64
	End   uint64
}

Range is a half-open interval [Start, End).

Invariant: Start < End

func (Range) Contains

func (r Range) Contains(row uint64) bool

Contains returns true if a value is inside r.

func (Range) ContainsRange

func (r Range) ContainsRange(other Range) bool

ContainsRange returns true if all rows in other are inside r.

func (Range) IsValid

func (r Range) IsValid() bool

IsValid returns true if r is valid.

func (Range) Len

func (r Range) Len() uint64

Len returns the size of r.

func (Range) Overlaps

func (r Range) Overlaps(other Range) bool

Overlaps returns true if r overlaps with other.

func (Range) String

func (r Range) String() string

String returns r in a human-readable format "[r.Start,r.End)".

type Set

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

Set holds a sorted list of non-overlapping [Range]s. The zero value is ready for use.

func From

func From(ranges ...Range) Set

From creates a new Set from a slice of ranges. Invalid ranges (those of length zero or negative length) are ignored.

func Intersect

func Intersect(a, b Set) Set

Intersect returns a new set, holding the intersection of a and b.

func Union

func Union(a, b Set) Set

Union returns a new set, holding the union of a and b.

func (*Set) Add

func (s *Set) Add(r Range)

Add inserts r into s. If r overlaps with any existing ranges in s, the ranges are merged.

func (*Set) IncludesRange

func (s *Set) IncludesRange(r Range) bool

IncludesRange returns true if the range r is fully contained inside s.

func (*Set) IncludesValue

func (s *Set) IncludesValue(value uint64) bool

IncludesValue returns true if the set contains the value.

func (*Set) Iter

func (s *Set) Iter() iter.Seq[Range]

Iter returns an iterator over the ranges in s.

func (*Set) Len

func (s *Set) Len() int

Len returns the number of values covered by all ranges in s.

func (*Set) Next

func (s *Set) Next(value uint64) (uint64, bool)

Next returns the next value in s after the given value. If there are no more values in s after value, Next returns math.MaxUint64 and false.

func (*Set) Overlaps

func (s *Set) Overlaps(r Range) bool

Overlaps returns true if r overlaps with s, false if no value in r is found in s.

func (*Set) RangeFor

func (s *Set) RangeFor(value uint64) Range

RangeFor returns the range containing the value, or an invalid range of length zero if no such range exists.

func (*Set) Reset

func (s *Set) Reset()

Reset removes all ranges from the set but retains underlying memory.

Jump to

Keyboard shortcuts

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