Skip to content

Commit 59a973f

Browse files
committed
done?
1 parent 037b6f7 commit 59a973f

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed

examples/haploid_wright_fisher.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ fn stress_test_total_branch_length() {
163163
if let Some(tree) = tree_iter.next() {
164164
let b = tree.total_branch_length(false).unwrap();
165165
let b2 = unsafe {
166-
tskit::bindings::tsk_tree_get_total_branch_length(tree.as_ll_ref(), -1, &mut x)
166+
tskit::bindings::tsk_tree_get_total_branch_length(
167+
tree.as_ll_ref(),
168+
-1,
169+
&mut x,
170+
)
167171
};
168172
assert!(b2 >= 0, "{}", b2);
169173
assert!(f64::from(b) - x <= 1e-8);

src/edge_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl EdgeTable {
253253
/// * `Some(position)` if `u` is valid.
254254
/// * `None` otherwise.
255255
pub fn right<E: Into<EdgeId> + Copy>(&self, row: E) -> Option<Position> {
256-
self.table_.left(row.into())
256+
self.table_.right(row.into())
257257
}
258258

259259
/// Retrieve decoded metadata for a `row`.

src/mutation_table.rs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,7 @@ impl MutationTable {
233233
/// Will return [``IndexError``](crate::TskitError::IndexError)
234234
/// if ``row`` is out of range.
235235
pub fn site<M: Into<MutationId> + Copy>(&self, row: M) -> Option<SiteId> {
236-
assert!(self.num_rows() == 0 || !self.as_ref().site.is_null());
237-
// SAFETY: either the column is empty or the pointer is not null,
238-
// in which case the correct lengths are from the low-level objects
239-
unsafe {
240-
sys::tsk_column_access::<SiteId, _, _, _>(
241-
row.into(),
242-
self.as_ref().site,
243-
self.num_rows(),
244-
)
245-
}
236+
self.table_.site(row.into())
246237
}
247238

248239
/// Return the ``node`` value from row ``row`` of the table.
@@ -252,16 +243,7 @@ impl MutationTable {
252243
/// Will return [``IndexError``](crate::TskitError::IndexError)
253244
/// if ``row`` is out of range.
254245
pub fn node<M: Into<MutationId> + Copy>(&self, row: M) -> Option<NodeId> {
255-
assert!(self.num_rows() == 0 || !self.as_ref().node.is_null());
256-
// SAFETY: either the column is empty or the pointer is not null,
257-
// in which case the correct lengths are from the low-level objects
258-
unsafe {
259-
sys::tsk_column_access::<NodeId, _, _, _>(
260-
row.into(),
261-
self.as_ref().node,
262-
self.num_rows(),
263-
)
264-
}
246+
self.table_.node(row.into())
265247
}
266248

267249
/// Return the ``parent`` value from row ``row`` of the table.
@@ -271,16 +253,7 @@ impl MutationTable {
271253
/// Will return [``IndexError``](crate::TskitError::IndexError)
272254
/// if ``row`` is out of range.
273255
pub fn parent<M: Into<MutationId> + Copy>(&self, row: M) -> Option<MutationId> {
274-
assert!(self.num_rows() == 0 || !self.as_ref().parent.is_null());
275-
// SAFETY: either the column is empty or the pointer is not null,
276-
// in which case the correct lengths are from the low-level objects
277-
unsafe {
278-
sys::tsk_column_access::<MutationId, _, _, _>(
279-
row.into(),
280-
self.as_ref().parent,
281-
self.num_rows(),
282-
)
283-
}
256+
self.table_.parent(row.into())
284257
}
285258

286259
/// Return the ``time`` value from row ``row`` of the table.
@@ -290,12 +263,7 @@ impl MutationTable {
290263
/// Will return [``IndexError``](crate::TskitError::IndexError)
291264
/// if ``row`` is out of range.
292265
pub fn time<M: Into<MutationId> + Copy>(&self, row: M) -> Option<Time> {
293-
assert!(self.num_rows() == 0 || !self.as_ref().time.is_null());
294-
// SAFETY: either the column is empty or the pointer is not null,
295-
// in which case the correct lengths are from the low-level objects
296-
unsafe {
297-
sys::tsk_column_access::<Time, _, _, _>(row.into(), self.as_ref().time, self.num_rows())
298-
}
266+
self.table_.time(row.into())
299267
}
300268

301269
/// Get the ``derived_state`` value from row ``row`` of the table.

src/sys/mutation_table.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
use std::ptr::NonNull;
22

3+
use super::newtypes::MutationId;
4+
use super::newtypes::NodeId;
5+
use super::newtypes::SiteId;
6+
use super::newtypes::Time;
7+
38
use super::bindings::tsk_id_t;
49
use super::bindings::tsk_mutation_table_add_row;
510
use super::bindings::tsk_mutation_table_clear;
@@ -76,6 +81,22 @@ impl MutationTable {
7681
))
7782
}
7883
}
84+
85+
pub fn time(&self, row: MutationId) -> Option<Time> {
86+
safe_tsk_column_access!(self, row, Time, time)
87+
}
88+
89+
pub fn site(&self, row: MutationId) -> Option<SiteId> {
90+
safe_tsk_column_access!(self, row, SiteId, site)
91+
}
92+
93+
pub fn node(&self, row: MutationId) -> Option<NodeId> {
94+
safe_tsk_column_access!(self, row, NodeId, node)
95+
}
96+
97+
pub fn parent(&self, row: MutationId) -> Option<MutationId> {
98+
safe_tsk_column_access!(self, row, MutationId, parent)
99+
}
79100
}
80101

81102
impl Default for MutationTable {

0 commit comments

Comments
 (0)