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.
|
/// 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);
|
let ptr = Self::as_leaf_ptr(self);
|
||||||
// SAFETY: we have exclusive access to the entire node.
|
// SAFETY: we have exclusive access to the entire node.
|
||||||
unsafe { &mut *ptr }
|
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.
|
/// 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
|
// We can't use Handle::new_kv or Handle::new_edge because we don't know our type
|
||||||
Handle {
|
Handle {
|
||||||
node: self.node.reborrow(),
|
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> {
|
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 leaf = self.node.as_leaf_mut();
|
||||||
let v = leaf.value.as_mut().unwrap();
|
let v = leaf.value.as_mut().unwrap();
|
||||||
v
|
v
|
||||||
|
|
@ -1037,15 +1040,15 @@ mod entry {
|
||||||
pub(crate) _marker: PhantomData<&'a mut (K, V)>,
|
pub(crate) _marker: PhantomData<&'a mut (K, V)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, K, V> OccupiedEntry<'a, K, V> {
|
impl<'entry, K, V> OccupiedEntry<'entry, K, V> {
|
||||||
pub fn get(&self) -> &V {
|
pub fn get(&self) -> &'entry V {
|
||||||
unsafe { self.handle.reborrow().into_value_unchecked() }
|
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() }
|
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)
|
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>(
|
pub fn get_subtree_mut<Q>(
|
||||||
&'_ mut self,
|
&'_ mut self,
|
||||||
mut key_seq: Q,
|
mut key_seq: Q,
|
||||||
|
|
@ -1626,6 +1634,12 @@ where
|
||||||
let mut subtree = self.as_subtree_mut();
|
let mut subtree = self.as_subtree_mut();
|
||||||
subtree.get_mut(key_seq)
|
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) {
|
unsafe fn slice_insert<T>(slice: &mut [MaybeUninit<T>], idx: usize, value: T) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue