github.com/puellanivis/breton@v0.2.16/lib/mapreduce/range.go (about) 1 package mapreduce 2 3 import ( 4 "fmt" 5 ) 6 7 // A Range is a mathematical range defined as starting at Start and ending just before End. 8 // In mathematical notation [Start,End). 9 type Range struct { 10 Start, End int 11 } 12 13 // String returns the Range in mathematical range notation. 14 func (r Range) String() string { 15 return fmt.Sprintf("[%d,%d)", r.Start, r.End) 16 } 17 18 // Width returns the number of integers within the Range. 19 func (r Range) Width() int { 20 return r.End - r.Start 21 } 22 23 // Add returns a new Range that is offset by the given amount, i.e. [Start+offset,End+offset). 24 func (r Range) Add(offset int) Range { 25 return Range{ 26 Start: r.Start + offset, 27 End: r.End + offset, 28 } 29 }