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

source

pub fn clear(&mut self) -> TskReturnValue

Clear the table.

source§

impl OwningEdgeTable

source§

impl OwningEdgeTable

source

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>,

source

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>§

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: 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 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 = EdgeTableRow> + '_

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

source

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

source

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

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<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) 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 crate::bindings::tsk_id_t

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 crate::bindings::tsk_id_t

Trait Implementations§

source§

impl Default for OwningEdgeTable

source§

fn default() -> Self

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

impl Deref for OwningEdgeTable

§

type Target = EdgeTable

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl DerefMut for OwningEdgeTable

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.