1
+ use std:: vec;
2
+
1
3
use crate :: bindings as ll_bindings;
2
4
use crate :: error:: TskitError ;
3
5
use crate :: types:: Bookmark ;
@@ -60,6 +62,7 @@ use mbox::MBox;
60
62
///
61
63
pub struct TableCollection {
62
64
inner : MBox < ll_bindings:: tsk_table_collection_t > ,
65
+ idmap : Vec < NodeId > ,
63
66
}
64
67
65
68
impl TskitTypeAccess < ll_bindings:: tsk_table_collection_t > for TableCollection {
@@ -119,7 +122,10 @@ impl TableCollection {
119
122
if rv < 0 {
120
123
return Err ( crate :: error:: TskitError :: ErrorCode { code : rv } ) ;
121
124
}
122
- let mut tables = Self { inner : mbox } ;
125
+ let mut tables = Self {
126
+ inner : mbox,
127
+ idmap : vec ! [ ] ,
128
+ } ;
123
129
unsafe {
124
130
( * tables. as_mut_ptr ( ) ) . sequence_length = sequence_length. 0 ;
125
131
}
@@ -134,7 +140,10 @@ impl TableCollection {
134
140
/// requiring an uninitialized table collection.
135
141
/// Consult the C API docs before using!
136
142
pub ( crate ) unsafe fn new_from_mbox ( mbox : MBox < ll_bindings:: tsk_table_collection_t > ) -> Self {
137
- Self { inner : mbox }
143
+ Self {
144
+ inner : mbox,
145
+ idmap : vec ! [ ] ,
146
+ }
138
147
}
139
148
140
149
pub ( crate ) fn into_raw ( self ) -> Result < * mut ll_bindings:: tsk_table_collection_t , TskitError > {
@@ -762,10 +771,10 @@ impl TableCollection {
762
771
samples : & [ N ] ,
763
772
options : O ,
764
773
idmap : bool ,
765
- ) -> Result < Option < Vec < NodeId > > , TskitError > {
766
- let mut output_node_map: Vec < NodeId > = vec ! [ ] ;
774
+ ) -> Result < Option < & [ NodeId ] > , TskitError > {
767
775
if idmap {
768
- output_node_map. resize ( usize:: try_from ( self . nodes ( ) . num_rows ( ) ) ?, NodeId :: NULL ) ;
776
+ self . idmap
777
+ . resize ( usize:: try_from ( self . nodes ( ) . num_rows ( ) ) ?, NodeId :: NULL ) ;
769
778
}
770
779
let rv = unsafe {
771
780
ll_bindings:: tsk_table_collection_simplify (
@@ -774,15 +783,15 @@ impl TableCollection {
774
783
samples. len ( ) as tsk_size_t ,
775
784
options. into ( ) . bits ( ) ,
776
785
match idmap {
777
- true => output_node_map . as_mut_ptr ( ) . cast :: < tsk_id_t > ( ) ,
786
+ true => self . idmap . as_mut_ptr ( ) . cast :: < tsk_id_t > ( ) ,
778
787
false => std:: ptr:: null_mut ( ) ,
779
788
} ,
780
789
)
781
790
} ;
782
791
handle_tsk_return_value ! (
783
792
rv,
784
793
match idmap {
785
- true => Some ( output_node_map ) ,
794
+ true => Some ( & self . idmap ) ,
786
795
false => None ,
787
796
}
788
797
)
0 commit comments