mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
3ef81afc76
Co-authored-by: Larvan2 <78135608+Larvan2@users.noreply.github.com> Co-authored-by: wwqgtxx <wwqgtxx@gmail.com>
45 lines
647 B
Go
45 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
|
|
}
|