Skip to content

Commit

Permalink
refactor: use get_prev for Index lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
rphmeier committed Nov 2, 2024
1 parent 722ce13 commit d9ebbfd
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions nomt/src/beatree/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! which is cheaply cloneable in O(1) and performs COW operations.
use std::iter::DoubleEndedIterator;
use std::ops::{Bound, RangeBounds, RangeToInclusive};
use std::ops::{Bound, RangeBounds};
use std::sync::Arc;

use imbl::OrdMap;
Expand All @@ -21,10 +21,7 @@ impl Index {
/// This is either a branch whose separator is exactly equal to this key or the branch with the
/// highest separator less than the key.
pub fn lookup(&self, key: Key) -> Option<(Key, Arc<BranchNode>)> {
self.first_key_map
.range(RangeToInclusive { end: key })
.next_back()
.map(|(sep, b)| (sep.clone(), b.clone()))
self.first_key_map.get_prev(&key).map(|(sep, b)| (sep.clone(), b.clone()))
}

/// Get the first branch with separator greater than the given key.
Expand Down

0 comments on commit d9ebbfd

Please sign in to comment.