Adding rows to tables

  • For each table type (node, edge., etc.), we have a function to add a row.
  • We can only add rows to tables in mutable TableCollection instances.

For example, to add a node:

        let mut tables = tskit::TableCollection::new(100.0).unwrap();
        if let Ok(node_id) = tables.add_node(
            0,                         // Node flags
            tskit::Time::from(0.0),    // Birth time
            tskit::PopulationId::NULL, // Population id
            tskit::IndividualId::NULL, // Individual id
        ) {
            assert_eq!(node_id, 0);

We see from the if let pattern that functions adding rows return Result. In general, errors only occur when the C back-end fails to allocate memory to expand the table columns. If we add a row with invalid data, no error is returned! To catch such errors, we must explicitly check table integrity (see below).

Again, we can take advantage of being able to pass in any type that is Into<_> the required newtype:

        let node_id = tables.add_node(0, 0.0, -1, -1).unwrap();

See the API docs for more details and examples.