@@ -20,6 +20,7 @@ use crate::TreeSequenceFlags;
20
20
use crate :: TskReturnValue ;
21
21
use crate :: TskitTypeAccess ;
22
22
use crate :: { tsk_flags_t, tsk_id_t, tsk_size_t, TSK_NULL } ;
23
+ use crate :: { IndividualId , NodeId } ;
23
24
use ll_bindings:: tsk_table_collection_free;
24
25
25
26
/// A table collection.
@@ -165,7 +166,7 @@ impl TableCollection {
165
166
}
166
167
167
168
/// Add a row to the edge table
168
- pub fn add_edge < P : Into < crate :: NodeId > , C : Into < crate :: NodeId > > (
169
+ pub fn add_edge < P : Into < NodeId > , C : Into < NodeId > > (
169
170
& mut self ,
170
171
left : f64 ,
171
172
right : f64 ,
@@ -176,7 +177,7 @@ impl TableCollection {
176
177
}
177
178
178
179
/// Add a row with metadata to the edge table
179
- pub fn add_edge_with_metadata < P : Into < crate :: NodeId > , C : Into < crate :: NodeId > > (
180
+ pub fn add_edge_with_metadata < P : Into < NodeId > , C : Into < NodeId > > (
180
181
& mut self ,
181
182
left : f64 ,
182
183
right : f64 ,
@@ -201,23 +202,23 @@ impl TableCollection {
201
202
}
202
203
203
204
/// Add a row to the individual table
204
- pub fn add_individual < N : Into < crate :: NodeId > > (
205
+ pub fn add_individual < N : Into < NodeId > > (
205
206
& mut self ,
206
207
flags : tsk_flags_t ,
207
208
location : & [ f64 ] ,
208
209
parents : & [ N ] ,
209
- ) -> TskReturnValue {
210
+ ) -> Result < IndividualId , TskitError > {
210
211
self . add_individual_with_metadata ( flags, location, parents, None )
211
212
}
212
213
213
214
/// Add a row with metadata to the individual table
214
- pub fn add_individual_with_metadata < N : Into < crate :: NodeId > > (
215
+ pub fn add_individual_with_metadata < N : Into < NodeId > > (
215
216
& mut self ,
216
217
flags : tsk_flags_t ,
217
218
location : & [ f64 ] ,
218
219
parents : & [ N ] ,
219
220
metadata : Option < & dyn MetadataRoundtrip > ,
220
- ) -> TskReturnValue {
221
+ ) -> Result < IndividualId , TskitError > {
221
222
let md = EncodedMetadata :: new ( metadata) ?;
222
223
let rv = unsafe {
223
224
ll_bindings:: tsk_individual_table_add_row (
@@ -231,7 +232,7 @@ impl TableCollection {
231
232
md. len ( ) ,
232
233
)
233
234
} ;
234
- handle_tsk_return_value ! ( rv)
235
+ handle_tsk_return_value ! ( rv, IndividualId :: from ( rv ) )
235
236
}
236
237
237
238
/// Add a row to the migration table
@@ -240,7 +241,7 @@ impl TableCollection {
240
241
///
241
242
/// Migration tables are not currently supported
242
243
/// by tree sequence simplification.
243
- pub fn add_migration < N : Into < crate :: NodeId > > (
244
+ pub fn add_migration < N : Into < NodeId > > (
244
245
& mut self ,
245
246
span : ( f64 , f64 ) ,
246
247
node : N ,
@@ -256,7 +257,7 @@ impl TableCollection {
256
257
///
257
258
/// Migration tables are not currently supported
258
259
/// by tree sequence simplification.
259
- pub fn add_migration_with_metadata < N : Into < crate :: NodeId > > (
260
+ pub fn add_migration_with_metadata < N : Into < NodeId > > (
260
261
& mut self ,
261
262
span : ( f64 , f64 ) ,
262
263
node : N ,
@@ -282,33 +283,33 @@ impl TableCollection {
282
283
}
283
284
284
285
/// Add a row to the node table
285
- pub fn add_node (
286
+ pub fn add_node < I : Into < IndividualId > > (
286
287
& mut self ,
287
288
flags : ll_bindings:: tsk_flags_t ,
288
289
time : f64 ,
289
290
population : tsk_id_t ,
290
- individual : tsk_id_t ,
291
- ) -> Result < crate :: NodeId , TskitError > {
291
+ individual : I ,
292
+ ) -> Result < NodeId , TskitError > {
292
293
self . add_node_with_metadata ( flags, time, population, individual, None )
293
294
}
294
295
295
296
/// Add a row with metadata to the node table
296
- pub fn add_node_with_metadata (
297
+ pub fn add_node_with_metadata < I : Into < IndividualId > > (
297
298
& mut self ,
298
299
flags : ll_bindings:: tsk_flags_t ,
299
300
time : f64 ,
300
301
population : tsk_id_t ,
301
- individual : tsk_id_t ,
302
+ individual : I ,
302
303
metadata : Option < & dyn MetadataRoundtrip > ,
303
- ) -> Result < crate :: NodeId , TskitError > {
304
+ ) -> Result < NodeId , TskitError > {
304
305
let md = EncodedMetadata :: new ( metadata) ?;
305
306
let rv = unsafe {
306
307
ll_bindings:: tsk_node_table_add_row (
307
308
& mut ( * self . as_mut_ptr ( ) ) . nodes ,
308
309
flags,
309
310
time,
310
311
population,
311
- individual,
312
+ individual. into ( ) . 0 ,
312
313
md. as_ptr ( ) ,
313
314
md. len ( ) ,
314
315
)
@@ -347,7 +348,7 @@ impl TableCollection {
347
348
}
348
349
349
350
/// Add a row to the mutation table.
350
- pub fn add_mutation < N : Into < crate :: NodeId > > (
351
+ pub fn add_mutation < N : Into < NodeId > > (
351
352
& mut self ,
352
353
site : tsk_id_t ,
353
354
node : N ,
@@ -359,7 +360,7 @@ impl TableCollection {
359
360
}
360
361
361
362
/// Add a row with metadata to the mutation table.
362
- pub fn add_mutation_with_metadata < N : Into < crate :: NodeId > > (
363
+ pub fn add_mutation_with_metadata < N : Into < NodeId > > (
363
364
& mut self ,
364
365
site : tsk_id_t ,
365
366
node : N ,
@@ -558,13 +559,13 @@ impl TableCollection {
558
559
/// in length to the input node table. For each input node,
559
560
/// this vector either contains the node's new index or [`TSK_NULL`]
560
561
/// if the input node is not part of the simplified history.
561
- pub fn simplify < N : Into < crate :: NodeId > > (
562
+ pub fn simplify < N : Into < NodeId > > (
562
563
& mut self ,
563
564
samples : & [ N ] ,
564
565
options : SimplificationOptions ,
565
566
idmap : bool ,
566
- ) -> Result < Option < Vec < crate :: NodeId > > , TskitError > {
567
- let mut output_node_map: Vec < crate :: NodeId > = vec ! [ ] ;
567
+ ) -> Result < Option < Vec < NodeId > > , TskitError > {
568
+ let mut output_node_map: Vec < NodeId > = vec ! [ ] ;
568
569
if idmap {
569
570
output_node_map. resize ( self . nodes ( ) . num_rows ( ) as usize , TSK_NULL . into ( ) ) ;
570
571
}
0 commit comments