Skip to content

feat: access to ergonomic edge table columns #730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/edge_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,22 @@ impl EdgeTable {
/// Get the child column as a slice of the underlying integer type
=> child, child_slice_raw, ll_bindings::tsk_id_t);

pub fn parent_column(&self) -> crate::EdgeTableColumn<crate::NodeId> {
crate::EdgeTableColumn::new(self.parent_slice())
}

pub fn child_column(&self) -> crate::EdgeTableColumn<crate::NodeId> {
crate::EdgeTableColumn::new(self.child_slice())
}

pub fn left_column(&self) -> crate::EdgeTableColumn<Position> {
crate::EdgeTableColumn::new(self.left_slice())
}

pub fn right_column(&self) -> crate::EdgeTableColumn<Position> {
crate::EdgeTableColumn::new(self.right_slice())
}

/// Clear all data from the table
pub fn clear(&mut self) -> Result<i32, TskitError> {
handle_tsk_return_value!(self.table_.clear())
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub use site_table::{SiteTable, SiteTableRow};
pub use sys::flags::*;
pub use sys::NodeTraversalOrder;
pub use table_collection::TableCollection;
pub use table_column::NodeTableColumn;
pub use table_column::{EdgeTableColumn, NodeTableColumn};
pub use traits::IndividualLocation;
pub use traits::IndividualParents;
pub use trees::{Tree, TreeSequence};
Expand Down
1 change: 1 addition & 0 deletions src/table_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ macro_rules! make_table_column {
}

make_table_column!(NodeTableColumn, NodeId);
make_table_column!(EdgeTableColumn, EdgeId);
30 changes: 30 additions & 0 deletions tests/test_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,33 @@ fn test_node_table_column_access() {
);
}
}

#[test]
fn test_edge_table_column_access() {
let mut table = tskit::EdgeTable::default();
let edge = table.add_row(0., 10., 1, 0).unwrap();

{
let column = table.left_column();
assert_eq!(column[edge], 0.0);
assert_eq!(column[edge], tskit::Position::from(0.));
}

{
let column = table.right_column();
assert_eq!(column[edge], 10.0);
assert_eq!(column[edge], tskit::Position::from(10.0));
}

{
let column = table.parent_column();
assert_eq!(column[edge], 1);
assert_eq!(column[edge], tskit::NodeId::from(1));
}

{
let column = table.child_column();
assert_eq!(column[edge], 0);
assert_eq!(column[edge], tskit::NodeId::from(0));
}
}
Loading