Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use get_prev for Index lookup #541

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor: use get_prev for Index lookup
  • Loading branch information
rphmeier authored and pepyakin committed Nov 4, 2024
commit e470de5f0ba7b4de5f425b32ce2f4640c1026264
8 changes: 2 additions & 6 deletions nomt/src/beatree/index.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! In-memory index tracking bottom level branch nodes. This is an immutable data structure,
//! 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;
@@ -21,10 +20,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.