Documentation ¶
Overview ¶
Package circular implements "circular numbers". This is a number that can be increased (or decreased) indefinitely while only using up a limited amount of memory. This feature comes with the limitiation in how distant two such numbers can be. Circular numbers have a maximum. The maximum distance is half the maximum value. If a number that has the maximum value is increased by 1, it becomes 0. If a number that has the value of 0 is decreased by 1, it becomes the maximum value. By comparing two circular numbers it is not possible to tell how often they wrapped. Therefore these two numbers must come from the same domain in order to make sense of the camparison.
Index ¶
- type Number
- func (a Number) Add(b uint32) Number
- func (a Number) Dec() Number
- func (a Number) Distance(b Number) uint32
- func (a Number) Equals(b Number) bool
- func (a Number) Gt(b Number) bool
- func (a Number) Gte(b Number) bool
- func (a Number) Inc() Number
- func (a Number) Lt(b Number) bool
- func (a Number) Lte(b Number) bool
- func (a Number) Sub(b uint32) Number
- func (a Number) Val() uint32
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Number ¶
type Number struct {
// contains filtered or unexported fields
}
Number represents a "circular number". A Number is immutable. All modification to a Number will result in a new instance of a Number.
func (Number) Gte ¶
Gte returns whether the circular number is greather than or equal to the circular number b.
func (Number) Inc ¶
Inc returns a new circular number with a value that is increased by 1.
Example ¶
a := New(42, max) b := a.Inc() fmt.Println(b.Val())
Output: 43
func (Number) Lte ¶
Lte returns whether the circular number is lower than or equal to the circular number b.