@@ -237,25 +237,27 @@ impl<BorrowType: marker::BorrowType, K, V>
237
237
238
238
impl < K , V > Handle < NodeRef < marker:: Dying , K , V , marker:: Leaf > , marker:: Edge > {
239
239
/// 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.
242
241
///
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.
246
246
///
247
247
/// # 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
+ {
251
257
let mut edge = self . forget_node_type ( ) ;
252
258
loop {
253
259
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) ) ,
259
261
Err ( last_edge) => match unsafe { last_edge. into_node ( ) . deallocate_and_ascend ( ) } {
260
262
Some ( parent_edge) => parent_edge. forget_node_type ( ) ,
261
263
None => return None ,
@@ -265,25 +267,27 @@ impl<K, V> Handle<NodeRef<marker::Dying, K, V, marker::Leaf>, marker::Edge> {
265
267
}
266
268
267
269
/// 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.
270
271
///
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.
274
276
///
275
277
/// # 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
+ {
279
287
let mut edge = self . forget_node_type ( ) ;
280
288
loop {
281
289
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) ) ,
287
291
Err ( last_edge) => match unsafe { last_edge. into_node ( ) . deallocate_and_ascend ( ) } {
288
292
Some ( parent_edge) => parent_edge. forget_node_type ( ) ,
289
293
None => return None ,
@@ -373,13 +377,15 @@ impl<K, V> Handle<NodeRef<marker::Dying, K, V, marker::Leaf>, marker::Edge> {
373
377
///
374
378
/// # Safety
375
379
/// - 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.
378
383
///
379
384
/// 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 > {
383
389
super :: mem:: replace ( self , |leaf_edge| unsafe {
384
390
leaf_edge. deallocating_next ( ) . unwrap_unchecked ( )
385
391
} )
@@ -391,13 +397,15 @@ impl<K, V> Handle<NodeRef<marker::Dying, K, V, marker::Leaf>, marker::Edge> {
391
397
///
392
398
/// # Safety
393
399
/// - 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.
396
403
///
397
404
/// 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 > {
401
409
super :: mem:: replace ( self , |leaf_edge| unsafe {
402
410
leaf_edge. deallocating_next_back ( ) . unwrap_unchecked ( )
403
411
} )
0 commit comments