mihomo/common/utils/range.go
gVisor bot dadd626f91 [Feature] Proxy stores delay data of different URLs. And supports specifying different test URLs and expected statue by group (#588)
Co-authored-by: Larvan2 <78135608+Larvan2@users.noreply.github.com>
Co-authored-by: wwqgtxx <wwqgtxx@gmail.com>
2023-06-04 11:51:30 +08:00

44 lines
647 B
Go

package utils
import (
"golang.org/x/exp/constraints"
)
type Range[T constraints.Ordered] struct {
start T
end T
}
func NewRange[T constraints.Ordered](start, end T) Range[T] {
if start > end {
return Range[T]{
start: end,
end: start,
}
}
return Range[T]{
start: start,
end: end,
}
}
func (r Range[T]) Contains(t T) bool {
return t >= r.start && t <= r.end
}
func (r Range[T]) LeftContains(t T) bool {
return t >= r.start && t < r.end
}
func (r Range[T]) RightContains(t T) bool {
return t > r.start && t <= r.end
}
func (r Range[T]) Start() T {
return r.start
}
func (r Range[T]) End() T {
return r.end
}