rangeset

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2021 License: MIT Imports: 2 Imported by: 0

README

rangeset

Go Reference Build Status codecov

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

Documentation

Overview

Package rangeset is a library for manipulating sets of discrete 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 slice of discrete Ranges sorted in ascending order. The zero value for a RangeSet, i.e. a nil RangeSet, is an empty set.

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 range [low, high).

If low >= high, FromRange returns nil.

func Intersection added in v0.2.0

func Intersection(sets ...RangeSet) RangeSet

Intersection returns the intersection of zero or more sets.

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 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 element into set.

func (*RangeSet) AddRange

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

AddRange adds range [low, high) 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 element.

func (RangeSet) ContainsRange

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

ContainsRange reports whether or not set contains every element in range [low, high).

func (RangeSet) Count added in v0.3.0

func (set RangeSet) Count() uint64

Count returns the number of element in set.

func (*RangeSet) Delete

func (set *RangeSet) Delete(single int64)

Delete removes a single element from set.

func (*RangeSet) DeleteRange

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

DeleteRange removes range [low, high) 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 element in set.

func (RangeSet) Overlaps added in v0.4.0

func (set RangeSet) Overlaps(other RangeSet) bool

Overlaps reports whether or not the intersection of set and other are not empty.

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