Nearest 查找最近的某个范围
(begin int64, end int64)
| 139 | |
| 140 | // Nearest 查找最近的某个范围 |
| 141 | func (this *PartialRanges) Nearest(begin int64, end int64) (r [2]int64, ok bool) { |
| 142 | if len(this.Ranges) == 0 { |
| 143 | return |
| 144 | } |
| 145 | |
| 146 | // TODO 使用二分法查找改进性能 |
| 147 | for _, r2 := range this.Ranges { |
| 148 | if r2[0] <= begin && r2[1] > begin { |
| 149 | r = [2]int64{begin, this.min(end, r2[1])} |
| 150 | ok = true |
| 151 | return |
| 152 | } |
| 153 | } |
| 154 | return |
| 155 | } |
| 156 | |
| 157 | // 转换为字符串 |
| 158 | func (this *PartialRanges) String() string { |