Follow the Rust API change of BTreeCursor

This commit is contained in:
Zhang Junyang
2024-06-20 15:50:29 +00:00
committed by Tate, Hongliang Tian
parent 8e3212449c
commit 5231005f37

View File

@ -860,55 +860,37 @@ impl<'a, V: Interval<Vaddr> + 'a> IntervalSet<'a, Vaddr> for BTreeMap<Vaddr, V>
type Item = V; type Item = V;
fn find(&'a self, range: &Range<Vaddr>) -> impl IntoIterator<Item = &'a Self::Item> + 'a { fn find(&'a self, range: &Range<Vaddr>) -> impl IntoIterator<Item = &'a Self::Item> + 'a {
let mut res = Vec::new(); let mut res = Vec::new();
let mut start_cursor = self.lower_bound(core::ops::Bound::Excluded(&range.start)); let mut cursor = self.lower_bound(core::ops::Bound::Excluded(&range.start));
let start_key = { // There's one previous element that may intersect with the range.
start_cursor.move_prev(); if let Some((_, v)) = cursor.peek_prev() {
if start_cursor.key().is_none() if v.range().end > range.start {
|| start_cursor.value().unwrap().range().end <= range.start res.push(v);
{
// the start_cursor is pointing to the "ghost" non-element before the first element
// or not intersected
start_cursor.move_next();
} }
if start_cursor.key().is_none() }
|| start_cursor.value().unwrap().range().start >= range.end // Find all intersected elements following it.
{ while let Some((_, v)) = cursor.next() {
// return None if the start_cursor is pointing to the "ghost" non-element after the last element if v.range().start >= range.end {
// or not intersected
return res;
}
start_cursor.key().unwrap()
};
let mut end_cursor = start_cursor.clone();
loop {
if end_cursor.key().is_none() || end_cursor.value().unwrap().range().start >= range.end
{
// the end_cursor is pointing to the "ghost" non-element after the last element
// or not intersected
break; break;
} }
res.push(end_cursor.value().unwrap()); res.push(v);
end_cursor.move_next();
} }
res res
} }
fn find_one(&'a self, point: &Vaddr) -> Option<&'a Self::Item> { fn find_one(&'a self, point: &Vaddr) -> Option<&'a Self::Item> {
let mut cursor = self.lower_bound(core::ops::Bound::Excluded(point)); let cursor = self.lower_bound(core::ops::Bound::Excluded(point));
cursor.move_prev(); // There's one previous element and one following element that may
if cursor.key().is_none() || cursor.value().unwrap().range().end <= *point { // contain the point. If they don't, there's no other chances.
// the cursor is pointing to the "ghost" non-element before the first element if let Some((_, v)) = cursor.peek_prev() {
// or not intersected if v.range().end > *point {
cursor.move_next(); return Some(v);
} }
// return None if the cursor is pointing to the "ghost" non-element after the last element } else if let Some((_, v)) = cursor.peek_next() {
cursor.key()?; if v.range().start <= *point {
return Some(v);
if cursor.value().unwrap().range().start > *point { }
None
} else {
Some(cursor.value().unwrap())
} }
None
} }
} }