@@ -82,35 +82,55 @@ impl<'treeseq> LLTree<'treeseq> {
8282 }
8383
8484 pub fn left_sib ( & self , u : NodeId ) -> Option < NodeId > {
85- super :: tsk_column_access :: < NodeId , _ , _ , _ > (
86- u,
87- self . as_ll_ref ( ) . left_sib ,
88- self . treeseq . num_nodes_raw ( ) + 1 ,
89- )
85+ assert ! ( !self . as_ll_ref( ) . left_sib. is_null( ) ) ;
86+ // SAFETY: since the length is at least 1,
87+ // the left_sib pointer cannot be NULL
88+ unsafe {
89+ super :: tsk_column_access :: < NodeId , _ , _ , _ > (
90+ u,
91+ self . as_ll_ref ( ) . left_sib ,
92+ self . treeseq . num_nodes_raw ( ) + 1 ,
93+ )
94+ }
9095 }
9196
9297 pub fn right_sib ( & self , u : NodeId ) -> Option < NodeId > {
93- super :: tsk_column_access :: < NodeId , _ , _ , _ > (
94- u,
95- self . as_ll_ref ( ) . right_sib ,
96- self . treeseq . num_nodes_raw ( ) + 1 ,
97- )
98+ assert ! ( !self . as_ll_ref( ) . right_sib. is_null( ) ) ;
99+ // SAFETY: since the length is at least 1,
100+ // the right_sib pointer cannot be NULL
101+ unsafe {
102+ super :: tsk_column_access :: < NodeId , _ , _ , _ > (
103+ u,
104+ self . as_ll_ref ( ) . right_sib ,
105+ self . treeseq . num_nodes_raw ( ) + 1 ,
106+ )
107+ }
98108 }
99109
100110 pub fn left_child ( & self , u : NodeId ) -> Option < NodeId > {
101- super :: tsk_column_access :: < NodeId , _ , _ , _ > (
102- u,
103- self . as_ll_ref ( ) . left_child ,
104- self . treeseq . num_nodes_raw ( ) + 1 ,
105- )
111+ assert ! ( !self . as_ll_ref( ) . left_child. is_null( ) ) ;
112+ // SAFETY: since the length is at least 1,
113+ // the left_child pointer cannot be NULL
114+ unsafe {
115+ super :: tsk_column_access :: < NodeId , _ , _ , _ > (
116+ u,
117+ self . as_ll_ref ( ) . left_child ,
118+ self . treeseq . num_nodes_raw ( ) + 1 ,
119+ )
120+ }
106121 }
107122
108123 pub fn right_child ( & self , u : NodeId ) -> Option < NodeId > {
109- super :: tsk_column_access :: < NodeId , _ , _ , _ > (
110- u,
111- self . as_ll_ref ( ) . right_child ,
112- self . treeseq . num_nodes_raw ( ) + 1 ,
113- )
124+ assert ! ( !self . as_ll_ref( ) . right_child. is_null( ) ) ;
125+ // SAFETY: since the length is at least 1,
126+ // the right_child pointer cannot be NULL
127+ unsafe {
128+ super :: tsk_column_access :: < NodeId , _ , _ , _ > (
129+ u,
130+ self . as_ll_ref ( ) . right_child ,
131+ self . treeseq . num_nodes_raw ( ) + 1 ,
132+ )
133+ }
114134 }
115135
116136 pub fn num_tracked_samples ( & self , u : NodeId ) -> Result < SizeType , TskitError > {
@@ -124,31 +144,46 @@ impl<'treeseq> LLTree<'treeseq> {
124144 }
125145
126146 pub fn left_sample ( & self , u : NodeId ) -> Option < NodeId > {
127- super :: tsk_column_access :: < NodeId , _ , _ , _ > (
128- u,
129- self . as_ll_ref ( ) . left_sample ,
130- self . treeseq . num_nodes_raw ( ) ,
131- )
147+ assert ! ( !self . as_ll_ref( ) . left_sample. is_null( ) ) ;
148+ // SAFETY: since the length is at least 1,
149+ // the left_sample pointer cannot be NULL
150+ unsafe {
151+ super :: tsk_column_access :: < NodeId , _ , _ , _ > (
152+ u,
153+ self . as_ll_ref ( ) . left_sample ,
154+ self . treeseq . num_nodes_raw ( ) ,
155+ )
156+ }
132157 }
133158
134159 pub fn right_sample ( & self , u : NodeId ) -> Option < NodeId > {
135- super :: tsk_column_access :: < NodeId , _ , _ , _ > (
136- u,
137- self . as_ll_ref ( ) . right_sample ,
138- self . treeseq . num_nodes_raw ( ) ,
139- )
160+ assert ! ( !self . as_ll_ref( ) . right_sample. is_null( ) ) ;
161+ // SAFETY: since the length is at least 1,
162+ // the right_sample pointer cannot be NULL
163+ unsafe {
164+ super :: tsk_column_access :: < NodeId , _ , _ , _ > (
165+ u,
166+ self . as_ll_ref ( ) . right_sample ,
167+ self . treeseq . num_nodes_raw ( ) ,
168+ )
169+ }
140170 }
141171
142172 pub fn samples ( & self , u : NodeId ) -> Result < impl Iterator < Item = NodeId > + ' _ , TskitError > {
143173 Ok ( NodeIteratorAdapter ( SamplesIterator :: new ( self , u) ?) )
144174 }
145175
146176 pub fn parent ( & self , u : NodeId ) -> Option < NodeId > {
147- super :: tsk_column_access :: < NodeId , _ , _ , _ > (
148- u,
149- self . as_ll_ref ( ) . parent ,
150- self . treeseq . num_nodes_raw ( ) + 1 ,
151- )
177+ assert ! ( !self . as_ll_ref( ) . parent. is_null( ) ) ;
178+ // SAFETY: since the length is at least 1,
179+ // the parent pointer cannot be NULL
180+ unsafe {
181+ super :: tsk_column_access :: < NodeId , _ , _ , _ > (
182+ u,
183+ self . as_ll_ref ( ) . parent ,
184+ self . treeseq . num_nodes_raw ( ) + 1 ,
185+ )
186+ }
152187 }
153188
154189 pub fn flags ( & self ) -> TreeFlags {
0 commit comments