Skip to main content

EdgeTable

Struct EdgeTable 

Source
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

Source

pub fn new() -> Result<Self, TskitError>

Source

pub fn num_rows(&self) -> SizeType

Return the number of rows

Source

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) if u is valid.
  • None otherwise.
Source

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) if u is valid.
  • None otherwise.
Source

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) if u is valid.
  • None otherwise.
Source

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) if u is valid.
  • None otherwise.
Source

pub fn metadata<T: EdgeMetadata>( &self, row: impl Into<EdgeId>, ) -> Option<Result<T, TskitError>>

Retrieve decoded metadata for a row.

§Returns
  • Some(Ok(T)) if row is valid and decoding succeeded.
  • Some(Err(_)) if row is valid and decoding failed.
  • None if row is not valid or the row has no metadata.
§Errors
§Examples.

The big-picture semantics are the same for all table types. See crate::IndividualTable::metadata for examples.

Source

pub fn iter(&self) -> impl Iterator<Item = Edge<'_>>

Return an iterator over rows of the table. The value of the iterator is crate::Edge.

Source

pub fn row<E: Into<EdgeId> + Copy>(&self, r: E) -> Option<Edge<'_>>

Return row r of the table.

§Parameters
  • r: the row id.
§Returns
  • Some(row) if r is valid
  • None otherwise
Source

pub fn left_slice(&self) -> &[Position]

Get the left column as a slice

Source

pub fn left_slice_raw(&self) -> &[f64]

Get the left column as a slice of f64

Source

pub fn right_slice(&self) -> &[Position]

Get the right column as a slice

Source

pub fn right_slice_raw(&self) -> &[f64]

Get the left column as a slice of f64

Source

pub fn parent_slice(&self) -> &[NodeId]

Get the parent column as a slice

Source

pub fn parent_slice_raw(&self) -> &[tsk_id_t]

Get the parent column as a slice of the underlying integer type

Source

pub fn child_slice(&self) -> &[NodeId]

Get the child column as a slice

Source

pub fn child_slice_raw(&self) -> &[tsk_id_t]

Get the child column as a slice of the underlying integer type

Source

pub fn parent_column(&self) -> impl TableColumn<EdgeId, NodeId> + '_

Source

pub fn child_column(&self) -> impl TableColumn<EdgeId, NodeId> + '_

Source

pub fn left_column(&self) -> impl TableColumn<EdgeId, Position> + '_

Source

pub fn right_column(&self) -> impl TableColumn<EdgeId, Position> + '_

Source

pub fn clear(&mut self) -> Result<i32, TskitError>

Clear all data from the table

Source

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

Source

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

Trait Implementations§

Source§

impl Debug for EdgeTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EdgeTable

Source§

fn default() -> EdgeTable

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.