mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-08-24 03:48:08 +08:00
fix binarySearchCompactSection
This commit is contained in:
parent
d3839fe279
commit
141d302492
@ -165,19 +165,29 @@ func (cm *CompactMap) Get(key NeedleId) (*NeedleValue, bool) {
|
|||||||
return cm.list[x].Get(key)
|
return cm.list[x].Get(key)
|
||||||
}
|
}
|
||||||
func (cm *CompactMap) binarySearchCompactSection(key NeedleId) int {
|
func (cm *CompactMap) binarySearchCompactSection(key NeedleId) int {
|
||||||
if len(cm.list) == 0 {
|
l, h := 0, len(cm.list)-1
|
||||||
return -1
|
if h < 0 {
|
||||||
|
return -5
|
||||||
}
|
}
|
||||||
x := sort.Search(len(cm.list), func(i int) bool {
|
if cm.list[h].start <= key {
|
||||||
return cm.list[i].start >= key
|
if cm.list[h].counter < batch || key <= cm.list[h].end {
|
||||||
})
|
return h
|
||||||
if len(cm.list) == x {
|
|
||||||
return -1
|
|
||||||
}
|
}
|
||||||
if cm.list[x].start == key {
|
return -4
|
||||||
return x
|
|
||||||
}
|
}
|
||||||
return x - 1
|
for l <= h {
|
||||||
|
m := (l + h) / 2
|
||||||
|
if key < cm.list[m].start {
|
||||||
|
h = m - 1
|
||||||
|
} else { // cm.list[m].start <= key
|
||||||
|
if cm.list[m+1].start <= key {
|
||||||
|
l = m + 1
|
||||||
|
} else {
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -3
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visit visits all entries or stop if any error when visiting
|
// Visit visits all entries or stop if any error when visiting
|
||||||
|
Loading…
Reference in New Issue
Block a user