pub struct OwningMigrationTable { /* private fields */ }
Expand description

A standalone migration table that owns its data.

Examples

use tskit::OwningMigrationTable;

let mut migrations = OwningMigrationTable::default();
let rowid = migrations.add_row((0., 1.), 1, (0, 1), 10.3).unwrap();
assert_eq!(rowid, 0);
assert_eq!(migrations.num_rows(), 1);

An example with metadata. This requires the cargo feature "derive" for tskit.

use tskit::OwningMigrationTable;

#[derive(serde::Serialize,
         serde::Deserialize,
         tskit::metadata::MigrationMetadata)]
#[serializer("serde_json")]
struct MigrationMetadata {
    value: i32,
}

let metadata = MigrationMetadata{value: 42};

let mut migrations = OwningMigrationTable::default();

let rowid = migrations.add_row_with_metadata((0., 1.), 1, (0, 1), 10.3, &metadata).unwrap();
assert_eq!(rowid, 0);

match migrations.metadata::<MigrationMetadata>(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 OwningMigrationTable

source

pub fn clear(&mut self) -> TskReturnValue

Clear the table.

source§

impl OwningMigrationTable

source§

impl OwningMigrationTable

source

pub fn add_row<LEFT, RIGHT, N, SOURCE, DEST, T>( &mut self, span: (LEFT, RIGHT), node: N, source_dest: (SOURCE, DEST), time: T ) -> Result<MigrationId, TskitError>where LEFT: Into<Position>, RIGHT: Into<Position>, N: Into<NodeId>, SOURCE: Into<PopulationId>, DEST: Into<PopulationId>, T: Into<Time>,

source

pub fn add_row_with_metadata<LEFT, RIGHT, N, SOURCE, DEST, T, M>( &mut self, span: (LEFT, RIGHT), node: N, source_dest: (SOURCE, DEST), time: T, metadata: &M ) -> Result<MigrationId, TskitError>where LEFT: Into<Position>, RIGHT: Into<Position>, N: Into<NodeId>, SOURCE: Into<PopulationId>, DEST: Into<PopulationId>, T: Into<Time>, M: MigrationMetadata,

Methods from Deref<Target = MigrationTable>§

source

pub fn num_rows(&self) -> SizeType

Return the number of rows

source

pub fn left<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<Position>

Return the left coordinate for a given row.

Returns
  • Some(position) if row is valid.
  • None otherwise.
source

pub fn right<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<Position>

Return the right coordinate for a given row.

Returns
  • Some(positions) if row is valid.
  • None otherwise.
source

pub fn node<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<NodeId>

Return the node for a given row.

Returns
  • Some(node) if row is valid.
  • None otherwise.
source

pub fn source<M: Into<MigrationId> + Copy>( &self, row: M ) -> Option<PopulationId>

Return the source population for a given row.

Returns
  • Some(population) if row is valid.
  • None otherwise.
source

pub fn dest<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<PopulationId>

Return the destination population for a given row.

Returns
  • Some(population) if row is valid.
  • None otherwise.
source

pub fn time<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<Time>

Return the time of the migration event for a given row.

Returns
  • Some(time) if row is valid.
  • None otherwise.
source

pub fn metadata<T: MigrationMetadata>( &self, row: MigrationId ) -> 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 not valid and decoding failed.
  • None if row is not valid.
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 = MigrationTableRow> + '_

Return an iterator over rows of the table. The value of the iterator is MigrationTableRow.

source

pub fn lending_iter(&self) -> MigrationTableRowView<'_>

source

pub fn row<M: Into<MigrationId> + Copy>( &self, r: M ) -> Option<MigrationTableRow>

Return row r of the table.

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

pub fn row_view<M: Into<MigrationId> + Copy>( &self, r: M ) -> Option<MigrationTableRowView<'_>>

Return a view of r of the table.

Parameters
  • r: the row id.
Returns
  • Some(row view) 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

source

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

Get the right column as a slice

source

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

Get the right column as a slice

source

pub fn time_slice(&self) -> &[Time]

Get the time column as a slice

source

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

Get the time column as a slice

source

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

Get the node column as a slice

source

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

Get the node column as a slice

source

pub fn source_slice(&self) -> &[PopulationId]

Get the source column as a slice

source

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

Get the source column as a slice

source

pub fn dest_slice(&self) -> &[PopulationId]

Get the dest column as a slice

source

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

Get the dest column as a slice

Trait Implementations§

source§

impl Default for OwningMigrationTable

source§

fn default() -> Self

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

impl Deref for OwningMigrationTable

§

type Target = MigrationTable

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for OwningMigrationTable

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> Free for T

source§

unsafe default fn free(ptr_ref: NonNull<T>)

Drops the content pointed by this pointer and frees it. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.