@@ -58,6 +58,7 @@ use super::Tree;
58
58
/// ```
59
59
pub struct TreeSequence {
60
60
pub ( crate ) inner : sys:: TreeSequence ,
61
+ tables : crate :: TableCollection ,
61
62
views : crate :: table_views:: TableViews ,
62
63
}
63
64
@@ -115,7 +116,16 @@ impl TreeSequence {
115
116
let raw_tables_ptr = tables. into_inner ( ) ;
116
117
let mut inner = sys:: TreeSequence :: new ( raw_tables_ptr, flags. into ( ) ) ?;
117
118
let views = crate :: table_views:: TableViews :: new_from_tree_sequence ( inner. as_mut ( ) ) ?;
118
- Ok ( Self { inner, views } )
119
+ let tables = unsafe {
120
+ TableCollection :: new_from_ll ( sys:: TableCollection :: new_borrowed (
121
+ std:: ptr:: NonNull :: new ( inner. as_mut ( ) . tables ) . unwrap ( ) ,
122
+ ) )
123
+ } ?;
124
+ Ok ( Self {
125
+ inner,
126
+ tables,
127
+ views,
128
+ } )
119
129
}
120
130
121
131
fn as_ref ( & self ) -> & ll_bindings:: tsk_treeseq_t {
@@ -335,8 +345,17 @@ impl TreeSequence {
335
345
} ,
336
346
) ?;
337
347
let views = crate :: table_views:: TableViews :: new_from_tree_sequence ( inner. as_mut ( ) ) ?;
348
+ let tables = unsafe {
349
+ TableCollection :: new_from_ll ( sys:: TableCollection :: new_borrowed (
350
+ std:: ptr:: NonNull :: new ( inner. as_mut ( ) . tables ) . unwrap ( ) ,
351
+ ) )
352
+ } ?;
338
353
Ok ( (
339
- Self { inner, views } ,
354
+ Self {
355
+ inner,
356
+ tables,
357
+ views,
358
+ } ,
340
359
match idmap {
341
360
true => Some ( output_node_map) ,
342
361
false => None ,
@@ -473,6 +492,22 @@ impl TreeSequence {
473
492
) -> Result < crate :: edge_differences:: EdgeDifferencesIterator , TskitError > {
474
493
crate :: edge_differences:: EdgeDifferencesIterator :: new_from_treeseq ( self , 0 )
475
494
}
495
+
496
+ /// Reference to the underlying table collection.
497
+ ///
498
+ /// # Examples
499
+ ///
500
+ /// ```
501
+ /// let mut tables = tskit::TableCollection::new(1000.).unwrap();
502
+ /// tables.add_node(tskit::NodeFlags::default(),0.0, -1, -1).unwrap();
503
+ /// tables.build_index();
504
+ /// let tcopy = tables.deepcopy().unwrap();
505
+ /// let tree_sequence = tskit::TreeSequence::try_from(tcopy).unwrap();
506
+ /// assert_eq!(tables.equals(tree_sequence.tables(), 0), true);
507
+ /// ```
508
+ pub fn tables ( & self ) -> & TableCollection {
509
+ & self . tables
510
+ }
476
511
}
477
512
478
513
impl TryFrom < TableCollection > for TreeSequence {
0 commit comments