insert
This commit is contained in:
parent
599f641d34
commit
a280b83479
30
src/lib.rs
30
src/lib.rs
|
|
@ -380,7 +380,7 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V> {
|
|||
}
|
||||
|
||||
/// Borrows exclusive access to the leaf portion of a leaf or internal node.
|
||||
fn as_leaf_mut(&mut self) -> &mut LeafNode<K, V> {
|
||||
fn as_leaf_mut(&mut self) -> &'a mut LeafNode<K, V> {
|
||||
let ptr = Self::as_leaf_ptr(self);
|
||||
// SAFETY: we have exclusive access to the entire node.
|
||||
unsafe { &mut *ptr }
|
||||
|
|
@ -578,9 +578,12 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Immut<'a>, K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<BorrowType, K, V, HandleType> Handle<NodeRef<BorrowType, K, V>, HandleType> {
|
||||
impl<'a, BorrowType, K, V, HandleType> Handle<NodeRef<BorrowType, K, V>, HandleType>
|
||||
where
|
||||
BorrowType: 'a,
|
||||
{
|
||||
/// Temporarily takes out another immutable handle on the same location.
|
||||
pub(crate) fn reborrow(&self) -> Handle<NodeRef<marker::Immut<'_>, K, V>, HandleType> {
|
||||
pub(crate) fn reborrow(&self) -> Handle<NodeRef<marker::Immut<'a>, K, V>, HandleType> {
|
||||
// We can't use Handle::new_kv or Handle::new_edge because we don't know our type
|
||||
Handle {
|
||||
node: self.node.reborrow(),
|
||||
|
|
@ -630,7 +633,7 @@ impl<K, V> NodeRef<marker::Dying, K, V> {
|
|||
}
|
||||
|
||||
impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V>, marker::Value> {
|
||||
pub(crate) unsafe fn value_mut(&mut self) -> &mut V {
|
||||
pub(crate) unsafe fn value_mut(&mut self) -> &'a mut V {
|
||||
let leaf = self.node.as_leaf_mut();
|
||||
let v = leaf.value.as_mut().unwrap();
|
||||
v
|
||||
|
|
@ -1037,15 +1040,15 @@ mod entry {
|
|||
pub(crate) _marker: PhantomData<&'a mut (K, V)>,
|
||||
}
|
||||
|
||||
impl<'a, K, V> OccupiedEntry<'a, K, V> {
|
||||
pub fn get(&self) -> &V {
|
||||
impl<'entry, K, V> OccupiedEntry<'entry, K, V> {
|
||||
pub fn get(&self) -> &'entry V {
|
||||
unsafe { self.handle.reborrow().into_value_unchecked() }
|
||||
}
|
||||
pub fn get_mut(&mut self) -> &mut V {
|
||||
pub fn get_mut(&mut self) -> &'entry mut V {
|
||||
unsafe { self.handle.value_mut() }
|
||||
}
|
||||
|
||||
pub fn into_subtree(self) -> super::subtree::Subtree<K, V, marker::Mut<'a>> {
|
||||
pub fn into_subtree(self) -> super::subtree::Subtree<K, V, marker::Mut<'entry>> {
|
||||
Subtree::new_root(self.handle.node)
|
||||
}
|
||||
}
|
||||
|
|
@ -1264,6 +1267,11 @@ mod subtree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, key_seq: impl Iterator<Item = K> + 'tree, val: V) -> &'tree mut V {
|
||||
let mut entry = self.entry(key_seq).or_insert(val);
|
||||
entry.get_mut()
|
||||
}
|
||||
|
||||
pub fn get_subtree_mut<Q>(
|
||||
&'_ mut self,
|
||||
mut key_seq: Q,
|
||||
|
|
@ -1626,6 +1634,12 @@ where
|
|||
let mut subtree = self.as_subtree_mut();
|
||||
subtree.get_mut(key_seq)
|
||||
}
|
||||
|
||||
pub fn insert<'a>(&'a mut self, key_seq: impl Iterator<Item = K> + 'a, val: V) -> &mut V {
|
||||
let mut subtree = self.as_subtree_mut();
|
||||
let v = subtree.insert(key_seq, val);
|
||||
v
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn slice_insert<T>(slice: &mut [MaybeUninit<T>], idx: usize, value: T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue