rangeset

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 2 Imported by: 0

README

rangeset

Go Reference Build Status codecov

A Go library for manipulating non-overlapping sets of ranges.

Documentation

Overview

Package rangeset is a library for manipulating non-overlapping sets of ranges.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Range

type Range struct {
	Low  int64 // inclusive
	High int64 // exclusive
}

A Range is a half-open interval of int64.

type RangeSet

type RangeSet []Range

A RangeSet is a non-overlapping ordered slice of Ranges. The zero value for a RangeSet is an empty set ready to use.

Since Range is half-open, you can never add math.MaxInt64 into a RangeSet. Thus, complement of an empty set is [math.MinInt64, math.MaxInt64).

func FromRange added in v0.1.1

func FromRange(low, high int64) RangeSet

FromRange creates a RangeSet from a half-open range [low, high).

func Intersection added in v0.2.0

func Intersection(sets ...RangeSet) RangeSet

Intersection returns the intersection of zero or more sets.

func IntersectionBuffer added in v0.2.0

func IntersectionBuffer(s1, s2, buffer RangeSet) RangeSet

IntersectionBuffer returns the intersection of s1 and s2, uses buffer as its initial backing storage.

func SymmetricDifference added in v0.2.0

func SymmetricDifference(s1, s2 RangeSet) RangeSet

SymmetricDifference returns the symmetric difference of two sets.

func Union

func Union(sets ...RangeSet) RangeSet

Union returns the union of zero or more sets.

func UnionBuffer

func UnionBuffer(s1, s2, buffer RangeSet) RangeSet

UnionBuffer returns the union of s1 and s2, uses buffer as its initial backing storage.

func Universal added in v0.1.1

func Universal() RangeSet

Universal returns the largest RangeSet, which is the complement of an empty set, i.e. [math.MinInt64, math.MaxInt64).

func (*RangeSet) Add

func (set *RangeSet) Add(single int64)

Add adds a single int64 into set.

func (*RangeSet) AddRange

func (set *RangeSet) AddRange(low, high int64)

AddRange adds a half-open range [low, high) into set.

func (*RangeSet) AddRanges added in v0.2.0

func (set *RangeSet) AddRanges(ranges ...Range)

AddRanges adds zero or more half-open ranges into set.

func (RangeSet) Complement

func (set RangeSet) Complement() RangeSet

Complement returns the inverse of set.

func (RangeSet) Contains

func (set RangeSet) Contains(single int64) bool

Contains reports whether or not set contains a single int64.

func (RangeSet) ContainsAny

func (set RangeSet) ContainsAny(low, high int64) bool

ContainsAny reports whether or not set contains any int64 in a half-open range [low, high).

func (RangeSet) ContainsRange

func (set RangeSet) ContainsRange(low, high int64) bool

ContainsRange reports whether or not set contains every int64 in a half-open range [low, high).

func (*RangeSet) Delete

func (set *RangeSet) Delete(single int64)

Delete removes a single int64 from set.

func (*RangeSet) DeleteRange

func (set *RangeSet) DeleteRange(low, high int64)

DeleteRange removes a half-open range [low, high) from set.

func (*RangeSet) DeleteRanges added in v0.2.0

func (set *RangeSet) DeleteRanges(ranges ...Range)

DeleteRanges removes zero or more half-open ranges from set.

func (RangeSet) Difference added in v0.2.1

func (set RangeSet) Difference(other RangeSet) RangeSet

Difference returns the subset of set that having all elements in other excluded.

func (RangeSet) Equals

func (set RangeSet) Equals(other RangeSet) bool

Equals reports whether or not set is identical to other.

func (RangeSet) Extent added in v0.2.0

func (set RangeSet) Extent() Range

Extent returns the smallest Range that covers the whole set. If set is empty, Extent returns the zero value.

func (RangeSet) Intersection added in v0.2.0

func (set RangeSet) Intersection(other RangeSet) RangeSet

Intersection returns the intersection of set and other.

func (RangeSet) IsSubsetOf added in v0.2.0

func (set RangeSet) IsSubsetOf(other RangeSet) bool

IsSubsetOf reports whether or not other contains every int64 in set.

func (RangeSet) Length

func (set RangeSet) Length() uint64

Length returns the number of int64 in set.

func (RangeSet) Union

func (set RangeSet) Union(other RangeSet) RangeSet

Union returns the union of set and other.

Jump to

Keyboard shortcuts

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