@@ -295,18 +295,18 @@ impl TreeInterface {
295
295
296
296
// error if we are not tracking samples,
297
297
// Ok(None) if u is out of range
298
- fn left_sample ( & self , u : NodeId ) -> Option < NodeId > {
298
+ fn left_sample < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
299
299
// SAFETY: internal pointer cannot be NULL
300
300
let ptr = unsafe { * self . as_ptr ( ) } ;
301
- unsafe_tsk_column_access ! ( u. 0 , 0 , self . num_nodes, ptr, left_sample, NodeId )
301
+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . num_nodes, ptr, left_sample, NodeId )
302
302
}
303
303
304
304
// error if we are not tracking samples,
305
305
// Ok(None) if u is out of range
306
- fn right_sample ( & self , u : NodeId ) -> Option < NodeId > {
306
+ fn right_sample < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
307
307
// SAFETY: internal pointer cannot be NULL
308
308
let ptr = unsafe { * self . as_ptr ( ) } ;
309
- unsafe_tsk_column_access ! ( u. 0 , 0 , self . num_nodes, ptr, right_sample, NodeId )
309
+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . num_nodes, ptr, right_sample, NodeId )
310
310
}
311
311
312
312
/// Return the `[left, right)` coordinates of the tree.
@@ -328,46 +328,46 @@ impl TreeInterface {
328
328
/// Get the parent of node `u`.
329
329
///
330
330
/// Returns `None` if `u` is out of range.
331
- pub fn parent ( & self , u : NodeId ) -> Option < NodeId > {
331
+ pub fn parent < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
332
332
// SAFETY: internal pointer cannot be NULL
333
333
let ptr = unsafe { * self . as_ptr ( ) } ;
334
- unsafe_tsk_column_access ! ( u. 0 , 0 , self . array_len, ptr, parent, NodeId )
334
+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . array_len, ptr, parent, NodeId )
335
335
}
336
336
337
337
/// Get the left child of node `u`.
338
338
///
339
339
/// Returns `None` if `u` is out of range.
340
- pub fn left_child ( & self , u : NodeId ) -> Option < NodeId > {
340
+ pub fn left_child < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
341
341
// SAFETY: internal pointer cannot be NULL
342
342
let ptr = unsafe { * self . as_ptr ( ) } ;
343
- unsafe_tsk_column_access ! ( u. 0 , 0 , self . array_len, ptr, left_child, NodeId )
343
+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . array_len, ptr, left_child, NodeId )
344
344
}
345
345
346
346
/// Get the right child of node `u`.
347
347
///
348
348
/// Returns `None` if `u` is out of range.
349
- pub fn right_child ( & self , u : NodeId ) -> Option < NodeId > {
349
+ pub fn right_child < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
350
350
// SAFETY: internal pointer cannot be NULL
351
351
let ptr = unsafe { * self . as_ptr ( ) } ;
352
- unsafe_tsk_column_access ! ( u. 0 , 0 , self . array_len, ptr, right_child, NodeId )
352
+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . array_len, ptr, right_child, NodeId )
353
353
}
354
354
355
355
/// Get the left sib of node `u`.
356
356
///
357
357
/// Returns `None` if `u` is out of range.
358
- pub fn left_sib ( & self , u : NodeId ) -> Option < NodeId > {
358
+ pub fn left_sib < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
359
359
// SAFETY: internal pointer cannot be NULL
360
360
let ptr = unsafe { * self . as_ptr ( ) } ;
361
- unsafe_tsk_column_access ! ( u. 0 , 0 , self . array_len, ptr, left_sib, NodeId )
361
+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . array_len, ptr, left_sib, NodeId )
362
362
}
363
363
364
364
/// Get the right sib of node `u`.
365
365
///
366
366
/// Returns `None` if `u` is out of range.
367
- pub fn right_sib ( & self , u : NodeId ) -> Option < NodeId > {
367
+ pub fn right_sib < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
368
368
// SAFETY: internal pointer cannot be NULL
369
369
let ptr = unsafe { * self . as_ptr ( ) } ;
370
- unsafe_tsk_column_access ! ( u. 0 , 0 , self . array_len, ptr, right_sib, NodeId )
370
+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . array_len, ptr, right_sib, NodeId )
371
371
}
372
372
373
373
/// Obtain the list of samples for the current tree/tree sequence
@@ -406,17 +406,17 @@ impl TreeInterface {
406
406
///
407
407
/// * `Some(iterator)` if `u` is valid
408
408
/// * `None` otherwise
409
- pub fn parents ( & self , u : NodeId ) -> impl Iterator < Item = NodeId > + ' _ {
410
- ParentsIterator :: new ( self , u)
409
+ pub fn parents < N : Into < NodeId > + Copy > ( & self , u : N ) -> impl Iterator < Item = NodeId > + ' _ {
410
+ ParentsIterator :: new ( self , u. into ( ) )
411
411
}
412
412
413
413
/// Return an [`Iterator`] over the children of node `u`.
414
414
/// # Returns
415
415
///
416
416
/// * `Some(iterator)` if `u` is valid
417
417
/// * `None` otherwise
418
- pub fn children ( & self , u : NodeId ) -> impl Iterator < Item = NodeId > + ' _ {
419
- ChildIterator :: new ( self , u)
418
+ pub fn children < N : Into < NodeId > + Copy > ( & self , u : N ) -> impl Iterator < Item = NodeId > + ' _ {
419
+ ChildIterator :: new ( self , u. into ( ) )
420
420
}
421
421
422
422
/// Return an [`Iterator`] over the sample nodes descending from node `u`.
@@ -430,8 +430,11 @@ impl TreeInterface {
430
430
/// * Some(Ok(iterator)) if [`TreeFlags::SAMPLE_LISTS`] is in [`TreeInterface::flags`]
431
431
/// * Some(Err(_)) if [`TreeFlags::SAMPLE_LISTS`] is not in [`TreeInterface::flags`]
432
432
/// * None if `u` is not valid.
433
- pub fn samples ( & self , u : NodeId ) -> Result < impl Iterator < Item = NodeId > + ' _ , TskitError > {
434
- SamplesIterator :: new ( self , u)
433
+ pub fn samples < N : Into < NodeId > + Copy > (
434
+ & self ,
435
+ u : N ,
436
+ ) -> Result < impl Iterator < Item = NodeId > + ' _ , TskitError > {
437
+ SamplesIterator :: new ( self , u. into ( ) )
435
438
}
436
439
437
440
/// Return an [`Iterator`] over the roots of the tree.
@@ -514,10 +517,10 @@ impl TreeInterface {
514
517
/// # Errors
515
518
///
516
519
/// * [`TskitError`] if [`TreeFlags::NO_SAMPLE_COUNTS`].
517
- pub fn num_tracked_samples ( & self , u : NodeId ) -> Result < SizeType , TskitError > {
520
+ pub fn num_tracked_samples < N : Into < NodeId > + Copy > ( & self , u : N ) -> Result < SizeType , TskitError > {
518
521
let mut n = SizeType ( tsk_size_t:: MAX ) ;
519
522
let np: * mut tsk_size_t = & mut n. 0 ;
520
- let code = unsafe { ll_bindings:: tsk_tree_get_num_tracked_samples ( self . as_ptr ( ) , u. 0 , np) } ;
523
+ let code = unsafe { ll_bindings:: tsk_tree_get_num_tracked_samples ( self . as_ptr ( ) , u. into ( ) . 0 , np) } ;
521
524
handle_tsk_return_value ! ( code, n)
522
525
}
523
526
0 commit comments