MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Nearest

Method Nearest

internal/caches/partial_ranges.go:141–155  ·  view source on GitHub ↗

Nearest 查找最近的某个范围

(begin int64, end int64)

Source from the content-addressed store, hash-verified

139
140// Nearest 查找最近的某个范围
141func (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// 转换为字符串
158func (this *PartialRanges) String() string {

Callers 2

ContainsRangeMethod · 0.80

Calls 1

minMethod · 0.95

Tested by 1