File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,18 @@ macro_rules! make_table_column {
1414 pub fn as_slice( & self ) -> & [ T ] {
1515 self . 0
1616 }
17+
18+ pub fn get_with_id( & self , index: crate :: $index) -> Option <& T > {
19+ self . get_with_usize( usize :: try_from( index) . ok( ) ?)
20+ }
21+
22+ pub fn get_with_size_type( & self , index: crate :: SizeType ) -> Option <& T > {
23+ self . get_with_usize( usize :: try_from( index) . ok( ) ?)
24+ }
25+
26+ pub fn get_with_usize( & self , index: usize ) -> Option <& T > {
27+ self . 0 . get( index)
28+ }
1729 }
1830
1931 impl <T > std:: ops:: Index <usize > for $name<' _, T > {
Original file line number Diff line number Diff line change @@ -559,10 +559,23 @@ fn test_node_table_column_access() {
559559 . unwrap ( ) ;
560560 let individual = t. individual_column ( ) ;
561561 assert_eq ! ( individual[ node] , tskit:: IndividualId :: NULL ) ;
562+ assert_eq ! (
563+ individual. get_with_id( node) . unwrap( ) ,
564+ & tskit:: IndividualId :: NULL
565+ ) ;
562566 let population = t. population_column ( ) ;
563567 assert_eq ! ( population[ node] , tskit:: PopulationId :: NULL ) ;
568+ assert_eq ! (
569+ population. get_with_id( node) . unwrap( ) ,
570+ & tskit:: PopulationId :: NULL
571+ ) ;
564572 let time = t. time_column ( ) ;
565573 assert_eq ! ( time[ node] , 0.0 ) ;
574+ assert_eq ! ( time. get_with_id( node) . unwrap( ) , & 0.0 ) ;
566575 let flags = t. flags_column ( ) ;
567576 assert_eq ! ( flags[ node] , tskit:: NodeFlags :: IS_SAMPLE ) ;
577+ assert_eq ! (
578+ flags. get_with_id( node) . unwrap( ) ,
579+ & tskit:: NodeFlags :: IS_SAMPLE
580+ ) ;
568581}
You can’t perform that action at this time.
0 commit comments