}
pub fn get<'a, T: LoadPage, K: Representable<T>, V: Representable<T>, P: BTreePage<T, K, V>>(
txn: &'a T,
db: &Db<T, K, V, P>,
k: &K,
v: Option<&V>,
) -> Result<Option<(&'a K, &'a V)>, T::Error> {
// Set the "cursor stack" by setting a skip list cursor in
// each page from the root to the appropriate leaf.
let mut last_match = None;
let mut page = db.db;
for _ in 0..cursor::N_CURSORS {
let mut cursor = P::first_cursor(page.as_page());
if let Ok((kk, vv, _)) = P::set_cursor(txn, page.as_page(), &mut cursor, k, v) {
if v.is_some() {
return Ok(Some((kk, vv)));
}
last_match = Some((kk, vv));
} else if let Some((k, v, _)) = P::current(page.as_page(), &cursor) {
unsafe { last_match = Some((
core::mem::transmute(k),
core::mem::transmute(v),
)) }
}
let next_page = P::left_child(page.as_page(), &cursor);
if next_page > 0 {
page = txn.load_page(next_page)?;
} else {
break;
}
}
Ok(last_match)