Documentation ¶
Overview ¶
Package interval handles sets of ordered values laying between two, possibly infinite, bounds.
Note: Intervals are usually defined as a set of [extended] real numbers. The model of the interval provided by Interface does not know - and thus does not care about the type of the bounds, if any. That may lead to correct but possibly surprising effects when the bounds domain is not ℝ. An interval may be non empty, like for example the open interval (1, 2), but no integer value lies between the bounds.
See also: http://en.wikipedia.org/wiki/Interval_(mathematics)
Index ¶
- type BigInt
- func (i *BigInt) Class() Class
- func (i *BigInt) Clone() Interface
- func (i *BigInt) CompareAA(other Interface) int
- func (i *BigInt) CompareAB(other Interface) int
- func (i *BigInt) CompareBB(other Interface) int
- func (i *BigInt) SetAB()
- func (i *BigInt) SetB(other Interface)
- func (i *BigInt) SetBA(other Interface)
- func (i *BigInt) SetClass(c Class)
- func (i *BigInt) String() string
- type BigRat
- func (i *BigRat) Class() Class
- func (i *BigRat) Clone() Interface
- func (i *BigRat) CompareAA(other Interface) int
- func (i *BigRat) CompareAB(other Interface) int
- func (i *BigRat) CompareBB(other Interface) int
- func (i *BigRat) SetAB()
- func (i *BigRat) SetB(other Interface)
- func (i *BigRat) SetBA(other Interface)
- func (i *BigRat) SetClass(c Class)
- func (i *BigRat) String() string
- type Byte
- func (i *Byte) Class() Class
- func (i *Byte) Clone() Interface
- func (i *Byte) CompareAA(other Interface) int
- func (i *Byte) CompareAB(other Interface) int
- func (i *Byte) CompareBB(other Interface) int
- func (i *Byte) SetAB()
- func (i *Byte) SetB(other Interface)
- func (i *Byte) SetBA(other Interface)
- func (i *Byte) SetClass(c Class)
- func (i *Byte) String() string
- type Class
- type Duration
- func (i *Duration) Class() Class
- func (i *Duration) Clone() Interface
- func (i *Duration) CompareAA(other Interface) int
- func (i *Duration) CompareAB(other Interface) int
- func (i *Duration) CompareBB(other Interface) int
- func (i *Duration) SetAB()
- func (i *Duration) SetB(other Interface)
- func (i *Duration) SetBA(other Interface)
- func (i *Duration) SetClass(c Class)
- func (i *Duration) String() string
- type Float32
- func (i *Float32) Class() Class
- func (i *Float32) Clone() Interface
- func (i *Float32) CompareAA(other Interface) int
- func (i *Float32) CompareAB(other Interface) int
- func (i *Float32) CompareBB(other Interface) int
- func (i *Float32) SetAB()
- func (i *Float32) SetB(other Interface)
- func (i *Float32) SetBA(other Interface)
- func (i *Float32) SetClass(c Class)
- func (i *Float32) String() string
- type Float64
- func (i *Float64) Class() Class
- func (i *Float64) Clone() Interface
- func (i *Float64) CompareAA(other Interface) int
- func (i *Float64) CompareAB(other Interface) int
- func (i *Float64) CompareBB(other Interface) int
- func (i *Float64) SetAB()
- func (i *Float64) SetB(other Interface)
- func (i *Float64) SetBA(other Interface)
- func (i *Float64) SetClass(c Class)
- func (i *Float64) String() string
- type Int
- func (i *Int) Class() Class
- func (i *Int) Clone() Interface
- func (i *Int) CompareAA(other Interface) int
- func (i *Int) CompareAB(other Interface) int
- func (i *Int) CompareBB(other Interface) int
- func (i *Int) SetAB()
- func (i *Int) SetB(other Interface)
- func (i *Int) SetBA(other Interface)
- func (i *Int) SetClass(c Class)
- func (i *Int) String() string
- type Int128
- func (i *Int128) Class() Class
- func (i *Int128) Clone() Interface
- func (i *Int128) CompareAA(other Interface) int
- func (i *Int128) CompareAB(other Interface) int
- func (i *Int128) CompareBB(other Interface) int
- func (i *Int128) SetAB()
- func (i *Int128) SetB(other Interface)
- func (i *Int128) SetBA(other Interface)
- func (i *Int128) SetClass(c Class)
- func (i *Int128) String() string
- type Int16
- func (i *Int16) Class() Class
- func (i *Int16) Clone() Interface
- func (i *Int16) CompareAA(other Interface) int
- func (i *Int16) CompareAB(other Interface) int
- func (i *Int16) CompareBB(other Interface) int
- func (i *Int16) SetAB()
- func (i *Int16) SetB(other Interface)
- func (i *Int16) SetBA(other Interface)
- func (i *Int16) SetClass(c Class)
- func (i *Int16) String() string
- type Int32
- func (i *Int32) Class() Class
- func (i *Int32) Clone() Interface
- func (i *Int32) CompareAA(other Interface) int
- func (i *Int32) CompareAB(other Interface) int
- func (i *Int32) CompareBB(other Interface) int
- func (i *Int32) SetAB()
- func (i *Int32) SetB(other Interface)
- func (i *Int32) SetBA(other Interface)
- func (i *Int32) SetClass(c Class)
- func (i *Int32) String() string
- type Int64
- func (i *Int64) Class() Class
- func (i *Int64) Clone() Interface
- func (i *Int64) CompareAA(other Interface) int
- func (i *Int64) CompareAB(other Interface) int
- func (i *Int64) CompareBB(other Interface) int
- func (i *Int64) SetAB()
- func (i *Int64) SetB(other Interface)
- func (i *Int64) SetBA(other Interface)
- func (i *Int64) SetClass(c Class)
- func (i *Int64) String() string
- type Int8
- func (i *Int8) Class() Class
- func (i *Int8) Clone() Interface
- func (i *Int8) CompareAA(other Interface) int
- func (i *Int8) CompareAB(other Interface) int
- func (i *Int8) CompareBB(other Interface) int
- func (i *Int8) SetAB()
- func (i *Int8) SetB(other Interface)
- func (i *Int8) SetBA(other Interface)
- func (i *Int8) SetClass(c Class)
- func (i *Int8) String() string
- type Interface
- type String
- func (i *String) Class() Class
- func (i *String) Clone() Interface
- func (i *String) CompareAA(other Interface) int
- func (i *String) CompareAB(other Interface) int
- func (i *String) CompareBB(other Interface) int
- func (i *String) SetAB()
- func (i *String) SetB(other Interface)
- func (i *String) SetBA(other Interface)
- func (i *String) SetClass(c Class)
- func (i *String) String() string
- type Time
- func (i *Time) Class() Class
- func (i *Time) Clone() Interface
- func (i *Time) CompareAA(other Interface) int
- func (i *Time) CompareAB(other Interface) int
- func (i *Time) CompareBB(other Interface) int
- func (i *Time) SetAB()
- func (i *Time) SetB(other Interface)
- func (i *Time) SetBA(other Interface)
- func (i *Time) SetClass(c Class)
- func (i *Time) String() string
- type Uint
- func (i *Uint) Class() Class
- func (i *Uint) Clone() Interface
- func (i *Uint) CompareAA(other Interface) int
- func (i *Uint) CompareAB(other Interface) int
- func (i *Uint) CompareBB(other Interface) int
- func (i *Uint) SetAB()
- func (i *Uint) SetB(other Interface)
- func (i *Uint) SetBA(other Interface)
- func (i *Uint) SetClass(c Class)
- func (i *Uint) String() string
- type Uint16
- func (i *Uint16) Class() Class
- func (i *Uint16) Clone() Interface
- func (i *Uint16) CompareAA(other Interface) int
- func (i *Uint16) CompareAB(other Interface) int
- func (i *Uint16) CompareBB(other Interface) int
- func (i *Uint16) SetAB()
- func (i *Uint16) SetB(other Interface)
- func (i *Uint16) SetBA(other Interface)
- func (i *Uint16) SetClass(c Class)
- func (i *Uint16) String() string
- type Uint32
- func (i *Uint32) Class() Class
- func (i *Uint32) Clone() Interface
- func (i *Uint32) CompareAA(other Interface) int
- func (i *Uint32) CompareAB(other Interface) int
- func (i *Uint32) CompareBB(other Interface) int
- func (i *Uint32) SetAB()
- func (i *Uint32) SetB(other Interface)
- func (i *Uint32) SetBA(other Interface)
- func (i *Uint32) SetClass(c Class)
- func (i *Uint32) String() string
- type Uint64
- func (i *Uint64) Class() Class
- func (i *Uint64) Clone() Interface
- func (i *Uint64) CompareAA(other Interface) int
- func (i *Uint64) CompareAB(other Interface) int
- func (i *Uint64) CompareBB(other Interface) int
- func (i *Uint64) SetAB()
- func (i *Uint64) SetB(other Interface)
- func (i *Uint64) SetBA(other Interface)
- func (i *Uint64) SetClass(c Class)
- func (i *Uint64) String() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BigInt ¶
BigInt is an interval having math/big.Int bounds.
Example ¶
x := &BigInt{LeftOpen, big.NewInt(1), big.NewInt(2)} y := &BigInt{LeftClosed, big.NewInt(2), big.NewInt(3)} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)
type BigRat ¶
BigRat is an interval having math/big.Rat bounds.
Example ¶
x := &BigRat{LeftOpen, big.NewRat(1, 1), big.NewRat(2, 1)} y := &BigRat{LeftClosed, big.NewRat(2, 1), big.NewRat(3, 1)} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1/1, 2/1], y [2/1, 3/1): x ∩ y {2/1}, x ∪ y (1/1, 3/1)
type Byte ¶
Byte is an interval having byte bounds.
Example ¶
x := &Byte{LeftOpen, 1, 2} y := &Byte{LeftClosed, 2, 3} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)
type Class ¶
type Class int
Class represent a type of an interval.
const ( Unbounded Class = iota // (-∞, ∞). Empty // {}. Degenerate // [a, a] = {a}. // Proper and bounded: Open // (a, b) = {x | a < x < b}. Closed // [a, b] = {x | a <= x <= b}. LeftOpen // (a, b] = {x | a < x <= b}. LeftClosed // [a, b) = {x | a <= x < b}. // Left-bounded and right-unbounded: LeftBoundedOpen // (a, ∞) = {x | x > a}. LeftBoundedClosed // [a, ∞) = {x | x >= a}. // Left-unbounded and right-bounded: RightBoundedOpen // (-∞, b) = {x | x < b}. RightBoundedClosed // (-∞, b] = {x | x <= b}. )
Interval classes.
type Duration ¶
Duration is an interval having time.Duration bounds.
Example ¶
x := &Duration{LeftOpen, 1, 2} y := &Duration{LeftClosed, 2, 3} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1ns, 2ns], y [2ns, 3ns): x ∩ y {2ns}, x ∪ y (1ns, 3ns)
type Float32 ¶
Float32 is an interval having float32 bounds.
Note: Using NaNs as bounds has undefined behavior.
Example ¶
x := &Float32{LeftOpen, 1, 2} y := &Float32{LeftClosed, 2, 3} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)
type Float64 ¶
Float64 is an interval having float64 bounds.
Note: Using NaNs as bounds has undefined behavior.
Example ¶
x := &Float32{LeftOpen, 1, 2} y := &Float32{LeftClosed, 2, 3} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)
type Int ¶
Int is an interval having int bounds.
Example ¶
x := &Int{LeftOpen, 1, 2} y := &Int{LeftClosed, 2, 3} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)
type Int128 ¶
Int128 is an interval having Int128 bounds.
Example ¶
x := &Int128{LeftOpen, int128.SetInt64(1), int128.SetInt64(2)} y := &Int128{LeftClosed, int128.SetInt64(2), int128.SetInt64(3)} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)
type Int16 ¶
Int16 is an interval having int16 bounds.
Example ¶
x := &Int16{LeftOpen, 1, 2} y := &Int16{LeftClosed, 2, 3} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)
type Int32 ¶
Int32 is an interval having int32 bounds.
Example ¶
x := &Int32{LeftOpen, 1, 2} y := &Int32{LeftClosed, 2, 3} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)
type Int64 ¶
Int64 is an interval having int64 bounds.
Example ¶
x := &Int64{LeftOpen, 1, 2} y := &Int64{LeftClosed, 2, 3} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)
type Int8 ¶
Int8 is an interval having int8 bounds.
Example ¶
x := &Int8{LeftOpen, 1, 2} y := &Int8{LeftClosed, 2, 3} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)
type Interface ¶
type Interface interface { // Class returns the interval class. Class() Class // Clone clones the interval. Clone() Interface // CompareAA compares interval.A and other.A. CompareAA(other Interface) int // CompareAB compares interval.A and other.B. CompareAB(other Interface) int // CompareBB compares interval.B and other.B. CompareBB(other Interface) int // SetClass sets the interval class. SetClass(Class) // SetAB sets interval.A using interval.B. SetAB() // SetB sets interval.B using other.B. SetB(other Interface) // SetBA sets interval.B using other.A. SetBA(other Interface) }
Interface represents an unbounded, empty, degenerate, proper, left-bounded or right-bounded interval. Where appropriate, the interval bounds are defined by ordered values, named by convention a and b, when present.
Proper intervals have an invariant: a < b.
CompareXX return value must obey these rules
< 0 if interval A or B < other interval A or B 0 if interval A or B == other interval A or B > 0 if interval A or B > other interval A or B
func Intersection ¶
Intersection returns the intersection of x and y.
type String ¶
String is an interval having string bounds.
Example ¶
x := &String{LeftOpen, "aqua", "bar"} y := &String{LeftClosed, "bar", "closed"} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (aqua, bar], y [bar, closed): x ∩ y {bar}, x ∪ y (aqua, closed)
type Time ¶
Time is an interval having time.Time bounds.
Example ¶
x := &Time{LeftOpen, time.Unix(1, 0), time.Unix(2, 0)} y := &Time{LeftClosed, time.Unix(2, 0), time.Unix(3, 0)} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1970-01-01 01:00:01 +0100 CET, 1970-01-01 01:00:02 +0100 CET], y [1970-01-01 01:00:02 +0100 CET, 1970-01-01 01:00:03 +0100 CET): x ∩ y {1970-01-01 01:00:02 +0100 CET}, x ∪ y (1970-01-01 01:00:01 +0100 CET, 1970-01-01 01:00:03 +0100 CET)
type Uint ¶
Uint is an interval having uint bounds.
Example ¶
x := &Uint{LeftOpen, 1, 2} y := &Uint{LeftClosed, 2, 3} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)
type Uint16 ¶
Uint16 is an interval having uint16 bounds.
Example ¶
x := &Uint16{LeftOpen, 1, 2} y := &Uint16{LeftClosed, 2, 3} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)
type Uint32 ¶
Uint32 is an interval having uint32 bounds.
Example ¶
x := &Uint32{LeftOpen, 1, 2} y := &Uint32{LeftClosed, 2, 3} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)
type Uint64 ¶
Uint64 is an interval having uint64 bounds.
Example ¶
x := &Uint64{LeftOpen, 1, 2} y := &Uint64{LeftClosed, 2, 3} fmt.Printf("x %v, y %v: x ∩ y %v, x ∪ y %v", x, y, Intersection(x, y), Union(x, y))
Output: x (1, 2], y [2, 3): x ∩ y {2}, x ∪ y (1, 3)