https://github.com/bsiegert/ranges
Go packages to handle integer ranges like "1,3,5-8"
https://github.com/bsiegert/ranges
Last synced: 5 months ago
JSON representation
Go packages to handle integer ranges like "1,3,5-8"
- Host: GitHub
- URL: https://github.com/bsiegert/ranges
- Owner: bsiegert
- Created: 2011-12-18T13:30:04.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2011-12-22T12:40:38.000Z (over 14 years ago)
- Last Synced: 2023-07-27T21:58:24.291Z (almost 3 years ago)
- Language: Go
- Homepage:
- Size: 97.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
PACKAGE
package ranges
import "."
Package ranges contains tools for working with integer ranges.
An "integer range" allows to give a set of numbers as a string, which
can be parsed by a call to Parse. The result can be obtained as a slice
of integers by calling Expand or be tested against with Contains.
FUNCTIONS
func Parse(r string) ([]int, error)
TYPES
type IntRange struct {
Lo, Hi int
}
An IntRange is a single component of an integer range expression.
func (ir *IntRange) Clean()
Clean exchanges the upper and lower bound if the upper bound is smaller
than the lower one.
func (ir *IntRange) Contains(value int) bool
Contains returns true if ir contains value.
func (ir *IntRange) Expand() []int
Expand returns a sorted slice of integers that contains all the numbers
in ir.
type IntRanges []IntRange
IntRanges is a slice of multiple integer ranges, allowing the expression
of non-contiguous ranges (for example "1,3-4").
func (ir *IntRanges) Contains(value int) bool
Contains returns true if ir contains value.
func (ir *IntRanges) Expand() []int
Expand returns a slice of integers that contains all the numbers in ir.
If ir has been cleaned by calling Clean, the slice will be sorted.
func (ir *IntRanges) Len() int
Len returns the number of distinct ranges in ir.
func (ir *IntRanges) Less(i, j int) bool
Less returns true if the lower bound of the i-th element is smaller than
the one of the j-th element.
func (ir *IntRanges) Swap(i, j int)
Swap swaps the i-th and the j-th element.