goProject/trunk/goutil/mathUtil/intRegion.go
皮蛋13361098506 1b77f62820 初始化项目
2025-01-06 16:01:02 +08:00

34 lines
608 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package mathUtil
import (
"fmt"
)
// int类型区间对象表示连续的int类型区间
type IntRegion struct {
Lower int
Upper int
}
func (this *IntRegion) String() string {
return fmt.Sprintf("%d-%d", this.Lower, this.Upper)
}
// 是否包含指定的值
func (this *IntRegion) Contains(value int) bool {
return this.Lower <= value && value <= this.Upper
}
// 是否是有序的
func (this *IntRegion) IsSorted() bool {
return this.Lower < this.Upper
}
// 创建int类型区间对象
func NewIntRegion(lower, upper int) *IntRegion {
return &IntRegion{
Lower: lower,
Upper: upper,
}
}