|
1 | 1 | ## Accessing table rows
|
2 | 2 |
|
3 |
| -We may also access entire table rows by a row id: |
| 3 | +The rows of a table contain two types of data: |
| 4 | + |
| 5 | +* Numerical data consisting of a single value. |
| 6 | +* Ragged data. Examples include metadata for all tables, |
| 7 | + ancestral states for sites, derived states for mutations, |
| 8 | + parent and location information for individuals, etc.. |
| 9 | + |
| 10 | +`tskit` provides two ways to access row data. |
| 11 | +The first is by a "view", which contains non-owning references |
| 12 | +to the ragged column data. |
| 13 | +The second is by row objects containing *copies* of the ragged column data. |
| 14 | + |
| 15 | +The former will be more efficient when the ragged columns are populated. |
| 16 | +The latter will be more convenient to work with because the API is a standard |
| 17 | +rust iterator. |
| 18 | + |
| 19 | +### Row views |
| 20 | + |
| 21 | +To iterate over all views we use *lending* iterators: |
| 22 | + |
| 23 | +```rust, noplaygound, ignore |
| 24 | +{{#include ../../tests/book_table_collection.rs:get_edge_table_rows_by_lending_iterator}} |
| 25 | +``` |
| 26 | + |
| 27 | +#### Lending iterators |
| 28 | + |
| 29 | +The lending iterators are implemented using the [`streaming_iterator`](https://docs.rs/streaming-iterator/latest/streaming_iterator/) crate. |
| 30 | +(The community now prefers the term "lending" over "streaming" for this concept.) |
| 31 | +The `tskit` prelude includes the trait declarations that allow the code shown above to compile. |
| 32 | + |
| 33 | +rust 1.65.0 stabilized Generic Associated Types, or GATs. |
| 34 | +GATs allows lending iterators to be implemented directly without the workarounds used in the `streaming_iterator` crate. |
| 35 | +We have decided not to implement our own lending iterator using GATs. |
| 36 | +Rather, we will see what the community settles on and will decide in the future whether or not to adopt it. |
| 37 | + |
| 38 | +### Row objects |
| 39 | + |
| 40 | +We may access entire table rows by a row id: |
4 | 41 |
|
5 | 42 | ```rust, noplaygound, ignore
|
6 | 43 | {{#include ../../tests/book_table_collection.rs:get_edge_table_row_by_id}}
|
|
0 commit comments