Struct tskit::OwnedEdgeTable

source ·
pub struct OwnedEdgeTable { /* private fields */ }
Expand description

A standalone edge table that owns its data.

Examples

use tskit::OwnedEdgeTable;

let mut edges = OwnedEdgeTable::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::OwnedEdgeTable;

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

let metadata = EdgeMetadata{value: 42};

let mut edges = OwnedEdgeTable::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

Clear the table.

Methods from Deref<Target = EdgeTable>

Return the number of rows

Return the parent value from row row of the table.

Returns
  • Some(parent) if u is valid.
  • None otherwise.

Return the child value from row row of the table.

Returns
  • Some(child) if u is valid.
  • None otherwise.

Return the left value from row row of the table.

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

Return the right value from row row of the table.

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

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.

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

Return row r of the table.

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

Return a view of row r of the table.

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

Get the left column as a slice

Get the left column as a slice of f64

Get the right column as a slice

Get the left column as a slice of f64

Get the parent column as a slice

Get the parent column as a slice of crate::bindings::tsk_id_t

Get the child column as a slice

Get the child column as a slice of crate::bindings::tsk_id_t

Trait Implementations

Returns the “default value” for a type. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Drops the content pointed by this pointer and frees it. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.