rangeset

package module
v0.0.0-...-bc774d2 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: MIT Imports: 3 Imported by: 0

README

rangeset

A Go library for manipulating sets of discrete ranges.

Deprecated: Development moved to https://github.com/b97tsk/intervals.

Documentation

Overview

Package rangeset is a library for manipulating sets of discrete ranges.

Deprecated: Development moved to https://github.com/b97tsk/intervals.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Elem added in v0.5.0

type Elem constraints.Integer

Elem is the type set containing all supported element types.

type Range

type Range[E Elem] struct {
	Low  E // inclusive
	High E // exclusive
}

A Range is a half-open interval of type E.

type RangeSet

type RangeSet[E Elem] []Range[E]

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 the maximum value of E into a RangeSet.

func FromRange added in v0.1.1

func FromRange[E Elem](lo, hi E) RangeSet[E]

FromRange creates a RangeSet from range [lo, hi).

If lo >= hi, FromRange returns nil.

func Intersection added in v0.2.0

func Intersection[E Elem](sets ...RangeSet[E]) RangeSet[E]

Intersection returns the intersection of zero or more sets.

func SymmetricDifference added in v0.2.0

func SymmetricDifference[E Elem](s1, s2 RangeSet[E]) RangeSet[E]

SymmetricDifference returns the symmetric difference of two sets.

func Union

func Union[E Elem](sets ...RangeSet[E]) RangeSet[E]

Union returns the union of zero or more sets.

func Universal added in v0.1.1

func Universal[E Elem]() RangeSet[E]

Universal returns the largest RangeSet, which contains every E except one, the maximum value of E.

func (*RangeSet[E]) Add

func (set *RangeSet[E]) Add(v E)

Add adds a single element into set.

func (*RangeSet[E]) AddRange

func (set *RangeSet[E]) AddRange(lo, hi E)

AddRange adds range [lo, hi) into set.

func (RangeSet[E]) Complement

func (set RangeSet[E]) Complement() RangeSet[E]

Complement returns the inverse of set.

Complement of an empty set is the return value of Universal[E](), which contains every E except one, the maximum value of E.

func (RangeSet[E]) Contains

func (set RangeSet[E]) Contains(v E) bool

Contains reports whether set contains a single element.

func (RangeSet[E]) ContainsRange

func (set RangeSet[E]) ContainsRange(lo, hi E) bool

ContainsRange reports whether set contains every element in range [lo, hi).

func (RangeSet[E]) Count added in v0.3.0

func (set RangeSet[E]) Count() uint64

Count returns the number of element in set.

func (*RangeSet[E]) Delete

func (set *RangeSet[E]) Delete(v E)

Delete removes a single element from set.

func (*RangeSet[E]) DeleteRange

func (set *RangeSet[E]) DeleteRange(lo, hi E)

DeleteRange removes range [lo, hi) from set.

func (RangeSet[E]) Difference added in v0.2.1

func (set RangeSet[E]) Difference(other RangeSet[E]) RangeSet[E]

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

func (RangeSet[E]) Equal added in v0.5.0

func (set RangeSet[E]) Equal(other RangeSet[E]) bool

Equal reports whether set is identical to other.

func (RangeSet[E]) Extent added in v0.2.0

func (set RangeSet[E]) Extent() Range[E]

Extent returns the smallest Range that covers the whole set.

If set is empty, Extent returns the zero value.

func (RangeSet[E]) Intersection added in v0.2.0

func (set RangeSet[E]) Intersection(other RangeSet[E]) RangeSet[E]

Intersection returns the intersection of set and other.

func (RangeSet[E]) IsSubsetOf added in v0.2.0

func (set RangeSet[E]) IsSubsetOf(other RangeSet[E]) bool

IsSubsetOf reports whether other contains every element in set.

func (RangeSet[E]) Overlaps added in v0.4.0

func (set RangeSet[E]) Overlaps(other RangeSet[E]) bool

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

func (RangeSet[E]) Union

func (set RangeSet[E]) Union(other RangeSet[E]) RangeSet[E]

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