pub struct EdgeTable { /* private fields */ }Expand description
An edge table.
§Examples
use tskit::EdgeTable;
let mut edges = EdgeTable::default();
let rowid = edges.add_row(1., 2., 0, 1).unwrap();
assert_eq!(rowid, 0);
assert_eq!(edges.num_rows(), 1);
edges.clear().unwrap();
assert_eq!(edges.num_rows(), 0);An example with metadata.
This requires the cargo feature "derive" for tskit.
use tskit::EdgeTable;
#[derive(serde::Serialize,
serde::Deserialize,
tskit::metadata::EdgeMetadata)]
#[serializer("serde_json")]
struct EdgeMetadata {
value: i32,
}
let metadata = EdgeMetadata{value: 42};
let mut edges = EdgeTable::default();
let rowid = edges.add_row_with_metadata(0., 1., 5, 10, &metadata).unwrap();
assert_eq!(rowid, 0);
match edges.metadata::<EdgeMetadata>(rowid) {
// rowid is in range, decoding succeeded
Some(Ok(decoded)) => assert_eq!(decoded.value, 42),
// rowid is in range, decoding failed
Some(Err(e)) => panic!("error decoding metadata: {:?}", e),
None => panic!("row id out of range")
}Implementations§
Source§impl EdgeTable
impl EdgeTable
pub fn new() -> Result<Self, TskitError>
Sourcepub fn parent<E: Into<EdgeId> + Copy>(&self, row: E) -> Option<NodeId>
pub fn parent<E: Into<EdgeId> + Copy>(&self, row: E) -> Option<NodeId>
Return the parent value from row row of the table.
§Returns
Some(parent)ifuis valid.Noneotherwise.
Sourcepub fn child<E: Into<EdgeId> + Copy>(&self, row: E) -> Option<NodeId>
pub fn child<E: Into<EdgeId> + Copy>(&self, row: E) -> Option<NodeId>
Return the child value from row row of the table.
§Returns
Some(child)ifuis valid.Noneotherwise.
Sourcepub fn left<E: Into<EdgeId> + Copy>(&self, row: E) -> Option<Position>
pub fn left<E: Into<EdgeId> + Copy>(&self, row: E) -> Option<Position>
Return the left value from row row of the table.
§Returns
Some(position)ifuis valid.Noneotherwise.
Sourcepub fn right<E: Into<EdgeId> + Copy>(&self, row: E) -> Option<Position>
pub fn right<E: Into<EdgeId> + Copy>(&self, row: E) -> Option<Position>
Return the right value from row row of the table.
§Returns
Some(position)ifuis valid.Noneotherwise.
Sourcepub fn metadata<T: EdgeMetadata>(
&self,
row: impl Into<EdgeId>,
) -> Option<Result<T, TskitError>>
pub fn metadata<T: EdgeMetadata>( &self, row: impl Into<EdgeId>, ) -> Option<Result<T, TskitError>>
Retrieve decoded metadata for a row.
§Returns
Some(Ok(T))ifrowis valid and decoding succeeded.Some(Err(_))ifrowis valid and decoding failed.Noneifrowis not valid or the row has no metadata.
§Errors
TskitError::MetadataErrorif decoding fails.
§Examples.
The big-picture semantics are the same for all table types.
See crate::IndividualTable::metadata for examples.
Sourcepub fn iter(&self) -> impl Iterator<Item = Edge<'_>>
pub fn iter(&self) -> impl Iterator<Item = Edge<'_>>
Return an iterator over rows of the table.
The value of the iterator is crate::Edge.
Sourcepub fn left_slice(&self) -> &[Position]
pub fn left_slice(&self) -> &[Position]
Get the left column as a slice
Sourcepub fn left_slice_raw(&self) -> &[f64]
pub fn left_slice_raw(&self) -> &[f64]
Get the left column as a slice of f64
Sourcepub fn right_slice(&self) -> &[Position]
pub fn right_slice(&self) -> &[Position]
Get the right column as a slice
Sourcepub fn right_slice_raw(&self) -> &[f64]
pub fn right_slice_raw(&self) -> &[f64]
Get the left column as a slice of f64
Sourcepub fn parent_slice(&self) -> &[NodeId]
pub fn parent_slice(&self) -> &[NodeId]
Get the parent column as a slice
Sourcepub fn parent_slice_raw(&self) -> &[tsk_id_t] ⓘ
pub fn parent_slice_raw(&self) -> &[tsk_id_t] ⓘ
Get the parent column as a slice of the underlying integer type
Sourcepub fn child_slice(&self) -> &[NodeId]
pub fn child_slice(&self) -> &[NodeId]
Get the child column as a slice
Sourcepub fn child_slice_raw(&self) -> &[tsk_id_t] ⓘ
pub fn child_slice_raw(&self) -> &[tsk_id_t] ⓘ
Get the child column as a slice of the underlying integer type
pub fn parent_column(&self) -> impl TableColumn<EdgeId, NodeId> + '_
pub fn child_column(&self) -> impl TableColumn<EdgeId, NodeId> + '_
pub fn left_column(&self) -> impl TableColumn<EdgeId, Position> + '_
pub fn right_column(&self) -> impl TableColumn<EdgeId, Position> + '_
Sourcepub fn clear(&mut self) -> Result<i32, TskitError>
pub fn clear(&mut self) -> Result<i32, TskitError>
Clear all data from the table
Sourcepub fn add_row<L: Into<Position>, R: Into<Position>, P: Into<NodeId>, C: Into<NodeId>>(
&mut self,
left: L,
right: R,
parent: P,
child: C,
) -> Result<EdgeId, TskitError>
pub fn add_row<L: Into<Position>, R: Into<Position>, P: Into<NodeId>, C: Into<NodeId>>( &mut self, left: L, right: R, parent: P, child: C, ) -> Result<EdgeId, TskitError>
Add a row without metadata.
See crate::TableCollection::add_edge for examples
Sourcepub fn add_row_with_metadata<L: Into<Position>, R: Into<Position>, P: Into<NodeId>, C: Into<NodeId>, M: EdgeMetadata>(
&mut self,
left: L,
right: R,
parent: P,
child: C,
metadata: &M,
) -> Result<EdgeId, TskitError>
pub fn add_row_with_metadata<L: Into<Position>, R: Into<Position>, P: Into<NodeId>, C: Into<NodeId>, M: EdgeMetadata>( &mut self, left: L, right: R, parent: P, child: C, metadata: &M, ) -> Result<EdgeId, TskitError>
Add a row with metadata.
See crate::TableCollection::add_edge_with_metadata for examples