rangeset

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 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 non-overlapping non-adjacent 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 non-overlapping non-adjacent ordered Ranges. 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 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 element into set.

func (*RangeSet) AddRange

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

AddRange adds 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 element.

func (RangeSet) ContainsAny

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

ContainsAny reports whether or not set contains any element in range [low, high).

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) 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 element 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