@@ -237,25 +237,27 @@ impl<BorrowType: marker::BorrowType, K, V>
237237
238238impl < K , V > Handle < NodeRef < marker:: Dying , K , V , marker:: Leaf > , marker:: Edge > {
239239 /// Given a leaf edge handle into a dying tree, returns the next leaf edge
240- /// on the right side, and the key-value pair in between, which is either
241- /// in the same leaf node, in an ancestor node, or non-existent.
240+ /// on the right side, and the key-value pair in between, if they exist.
242241 ///
243- /// This method also deallocates any node(s) it reaches the end of. This
244- /// implies that if no more key-value pair exists, the entire remainder of
245- /// the tree will have been deallocated and there is nothing left to return.
242+ /// If the given edge is the last one in a leaf, this method deallocates
243+ /// the leaf, as well as any ancestor nodes whose last edge was reached.
244+ /// This implies that if no more key-value pair follows, the entire tree
245+ /// will have been deallocated and there is nothing left to return.
246246 ///
247247 /// # Safety
248- /// The given edge must not have been previously returned by counterpart
249- /// `deallocating_next_back`.
250- unsafe fn deallocating_next ( self ) -> Option < ( Self , ( K , V ) ) > {
248+ /// - The given edge must not have been previously returned by counterpart
249+ /// `deallocating_next_back`.
250+ /// - The returned KV handle is only valid to access the key and value,
251+ /// and only valid until the next call to this method or counterpart
252+ /// `deallocating_next_back`.
253+ pub unsafe fn deallocating_next (
254+ self ,
255+ ) -> Option < ( Self , Handle < NodeRef < marker:: Dying , K , V , marker:: LeafOrInternal > , marker:: KV > ) >
256+ {
251257 let mut edge = self . forget_node_type ( ) ;
252258 loop {
253259 edge = match edge. right_kv ( ) {
254- Ok ( kv) => {
255- let k = unsafe { ptr:: read ( kv. reborrow ( ) . into_kv ( ) . 0 ) } ;
256- let v = unsafe { ptr:: read ( kv. reborrow ( ) . into_kv ( ) . 1 ) } ;
257- return Some ( ( kv. next_leaf_edge ( ) , ( k, v) ) ) ;
258- }
260+ Ok ( kv) => return Some ( ( unsafe { ptr:: read ( & kv) } . next_leaf_edge ( ) , kv) ) ,
259261 Err ( last_edge) => match unsafe { last_edge. into_node ( ) . deallocate_and_ascend ( ) } {
260262 Some ( parent_edge) => parent_edge. forget_node_type ( ) ,
261263 None => return None ,
@@ -265,25 +267,27 @@ impl<K, V> Handle<NodeRef<marker::Dying, K, V, marker::Leaf>, marker::Edge> {
265267 }
266268
267269 /// Given a leaf edge handle into a dying tree, returns the next leaf edge
268- /// on the left side, and the key-value pair in between, which is either
269- /// in the same leaf node, in an ancestor node, or non-existent.
270+ /// on the left side, and the key-value pair in between, if they exist.
270271 ///
271- /// This method also deallocates any node(s) it reaches the end of. This
272- /// implies that if no more key-value pair exists, the entire remainder of
273- /// the tree will have been deallocated and there is nothing left to return.
272+ /// If the given edge is the first one in a leaf, this method deallocates
273+ /// the leaf, as well as any ancestor nodes whose first edge was reached.
274+ /// This implies that if no more key-value pair follows, the entire tree
275+ /// will have been deallocated and there is nothing left to return.
274276 ///
275277 /// # Safety
276- /// The given edge must not have been previously returned by counterpart
277- /// `deallocating_next`.
278- unsafe fn deallocating_next_back ( self ) -> Option < ( Self , ( K , V ) ) > {
278+ /// - The given edge must not have been previously returned by counterpart
279+ /// `deallocating_next`.
280+ /// - The returned KV handle is only valid to access the key and value,
281+ /// and only valid until the next call to this method or counterpart
282+ /// `deallocating_next`.
283+ unsafe fn deallocating_next_back (
284+ self ,
285+ ) -> Option < ( Self , Handle < NodeRef < marker:: Dying , K , V , marker:: LeafOrInternal > , marker:: KV > ) >
286+ {
279287 let mut edge = self . forget_node_type ( ) ;
280288 loop {
281289 edge = match edge. left_kv ( ) {
282- Ok ( kv) => {
283- let k = unsafe { ptr:: read ( kv. reborrow ( ) . into_kv ( ) . 0 ) } ;
284- let v = unsafe { ptr:: read ( kv. reborrow ( ) . into_kv ( ) . 1 ) } ;
285- return Some ( ( kv. next_back_leaf_edge ( ) , ( k, v) ) ) ;
286- }
290+ Ok ( kv) => return Some ( ( unsafe { ptr:: read ( & kv) } . next_back_leaf_edge ( ) , kv) ) ,
287291 Err ( last_edge) => match unsafe { last_edge. into_node ( ) . deallocate_and_ascend ( ) } {
288292 Some ( parent_edge) => parent_edge. forget_node_type ( ) ,
289293 None => return None ,
@@ -373,13 +377,15 @@ impl<K, V> Handle<NodeRef<marker::Dying, K, V, marker::Leaf>, marker::Edge> {
373377 ///
374378 /// # Safety
375379 /// - There must be another KV in the direction travelled.
376- /// - That KV was not previously returned by counterpart `next_back_unchecked`
377- /// on any copy of the handles being used to traverse the tree.
380+ /// - That KV was not previously returned by counterpart
381+ /// `deallocating_next_back_unchecked` on any copy of the handles
382+ /// being used to traverse the tree.
378383 ///
379384 /// The only safe way to proceed with the updated handle is to compare it, drop it,
380- /// call this method again subject to its safety conditions, or call counterpart
381- /// `next_back_unchecked` subject to its safety conditions.
382- pub unsafe fn deallocating_next_unchecked ( & mut self ) -> ( K , V ) {
385+ /// or call this method or counterpart `deallocating_next_back_unchecked` again.
386+ pub unsafe fn deallocating_next_unchecked (
387+ & mut self ,
388+ ) -> Handle < NodeRef < marker:: Dying , K , V , marker:: LeafOrInternal > , marker:: KV > {
383389 super :: mem:: replace ( self , |leaf_edge| unsafe {
384390 leaf_edge. deallocating_next ( ) . unwrap_unchecked ( )
385391 } )
@@ -391,13 +397,15 @@ impl<K, V> Handle<NodeRef<marker::Dying, K, V, marker::Leaf>, marker::Edge> {
391397 ///
392398 /// # Safety
393399 /// - There must be another KV in the direction travelled.
394- /// - That leaf edge was not previously returned by counterpart `next_unchecked`
395- /// on any copy of the handles being used to traverse the tree.
400+ /// - That leaf edge was not previously returned by counterpart
401+ /// `deallocating_next_unchecked` on any copy of the handles
402+ /// being used to traverse the tree.
396403 ///
397404 /// The only safe way to proceed with the updated handle is to compare it, drop it,
398- /// call this method again subject to its safety conditions, or call counterpart
399- /// `next_unchecked` subject to its safety conditions.
400- pub unsafe fn deallocating_next_back_unchecked ( & mut self ) -> ( K , V ) {
405+ /// or call this method or counterpart `deallocating_next_unchecked` again.
406+ pub unsafe fn deallocating_next_back_unchecked (
407+ & mut self ,
408+ ) -> Handle < NodeRef < marker:: Dying , K , V , marker:: LeafOrInternal > , marker:: KV > {
401409 super :: mem:: replace ( self , |leaf_edge| unsafe {
402410 leaf_edge. deallocating_next_back ( ) . unwrap_unchecked ( )
403411 } )
0 commit comments