Struct tskit::OwningEdgeTable
source · pub struct OwningEdgeTable { /* private fields */ }
Expand description
A standalone edge table that owns its data.
Examples
use tskit::OwningEdgeTable;
let mut edges = OwningEdgeTable::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::OwningEdgeTable;
#[derive(serde::Serialize,
serde::Deserialize,
tskit::metadata::EdgeMetadata)]
#[serializer("serde_json")]
struct EdgeMetadata {
value: i32,
}
let metadata = EdgeMetadata{value: 42};
let mut edges = OwningEdgeTable::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 OwningEdgeTable
impl OwningEdgeTable
sourcepub fn clear(&mut self) -> TskReturnValue
pub fn clear(&mut self) -> TskReturnValue
Clear the table.
source§impl OwningEdgeTable
impl OwningEdgeTable
pub fn as_ptr(&self) -> *const tsk_edge_table_t
pub fn as_mut_ptr(&mut self) -> *mut tsk_edge_table_t
source§impl OwningEdgeTable
impl OwningEdgeTable
pub fn add_row<L, R, P, C>( &mut self, left: L, right: R, parent: P, child: C ) -> Result<EdgeId, TskitError>where L: Into<Position>, R: Into<Position>, P: Into<NodeId>, C: Into<NodeId>,
pub fn add_row_with_metadata<L, R, P, C, M>( &mut self, left: L, right: R, parent: P, child: C, metadata: &M ) -> Result<EdgeId, TskitError>where L: Into<Position>, R: Into<Position>, P: Into<NodeId>, C: Into<NodeId>, M: EdgeMetadata,
Methods from Deref<Target = EdgeTable>§
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)
ifu
is valid.None
otherwise.
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)
ifu
is valid.None
otherwise.
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)
ifu
is valid.None
otherwise.
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)
ifu
is valid.None
otherwise.
sourcepub fn metadata<T: EdgeMetadata>(
&self,
row: EdgeId
) -> Option<Result<T, TskitError>>
pub fn metadata<T: EdgeMetadata>( &self, row: EdgeId ) -> Option<Result<T, TskitError>>
Retrieve decoded metadata for a row
.
Returns
Some(Ok(T))
ifrow
is valid and decoding succeeded.Some(Err(_))
ifrow
is not valid and decoding failed.None
ifrow
is not valid.
Errors
TskitError::MetadataError
if 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 = EdgeTableRow> + '_
pub fn iter(&self) -> impl Iterator<Item = EdgeTableRow> + '_
Return an iterator over rows of the table.
The value of the iterator is EdgeTableRow
.
pub fn lending_iter(&self) -> EdgeTableRowView<'_>
sourcepub fn row_view<E: Into<EdgeId> + Copy>(
&self,
r: E
) -> Option<EdgeTableRowView<'_>>
pub fn row_view<E: Into<EdgeId> + Copy>( &self, r: E ) -> Option<EdgeTableRowView<'_>>
Return a view of row r
of the table.
Parameters
r
: the row id.
Returns
Some(row_view)
ifr
is validNone
otherwise
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 crate::bindings::tsk_id_t
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 crate::bindings::tsk_id_t