github.com/metacubex/mihomo@v1.18.5/common/utils/range.go (about) 1 package utils 2 3 import ( 4 "golang.org/x/exp/constraints" 5 ) 6 7 type Range[T constraints.Ordered] struct { 8 start T 9 end T 10 } 11 12 func NewRange[T constraints.Ordered](start, end T) Range[T] { 13 if start > end { 14 return Range[T]{ 15 start: end, 16 end: start, 17 } 18 } 19 20 return Range[T]{ 21 start: start, 22 end: end, 23 } 24 } 25 26 func (r Range[T]) Contains(t T) bool { 27 return t >= r.start && t <= r.end 28 } 29 30 func (r Range[T]) LeftContains(t T) bool { 31 return t >= r.start && t < r.end 32 } 33 34 func (r Range[T]) RightContains(t T) bool { 35 return t > r.start && t <= r.end 36 } 37 38 func (r Range[T]) Start() T { 39 return r.start 40 } 41 42 func (r Range[T]) End() T { 43 return r.end 44 }