Skip to content

Commit 5045d0a

Browse files
committed
remove use of table views in table collection
1 parent 7b843d0 commit 5045d0a

File tree

1 file changed

+180
-8
lines changed

1 file changed

+180
-8
lines changed

src/table_collection.rs

Lines changed: 180 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use delegate::delegate;
21
use std::vec;
32

43
use crate::error::TskitError;
@@ -7,6 +6,8 @@ use crate::metadata::MigrationMetadata;
76
use crate::metadata::MutationMetadata;
87
use crate::metadata::PopulationMetadata;
98
use crate::metadata::SiteMetadata;
9+
#[cfg(feature = "provenance")]
10+
use crate::provenance::ProvenanceTable;
1011
use crate::sys::bindings as ll_bindings;
1112
use crate::sys::TableCollection as LLTableCollection;
1213
use crate::types::Bookmark;
@@ -16,6 +17,7 @@ use crate::MigrationId;
1617
use crate::MigrationTable;
1718
use crate::MutationId;
1819
use crate::MutationTable;
20+
use crate::NodeTable;
1921
use crate::PopulationId;
2022
use crate::Position;
2123
use crate::SimplificationOptions;
@@ -69,7 +71,15 @@ use ll_bindings::tsk_size_t;
6971
pub struct TableCollection {
7072
inner: LLTableCollection,
7173
idmap: Vec<NodeId>,
72-
views: crate::table_views::TableViews,
74+
edges: EdgeTable,
75+
nodes: NodeTable,
76+
sites: SiteTable,
77+
mutations: MutationTable,
78+
individuals: IndividualTable,
79+
populations: PopulationTable,
80+
migrations: MigrationTable,
81+
#[cfg(feature = "provenance")]
82+
provenances: ProvenanceTable,
7383
}
7484

7585
impl TableCollection {
@@ -1348,14 +1358,176 @@ impl TableCollection {
13481358
handle_tsk_return_value!(rv)
13491359
}
13501360

1351-
delegate! {
1352-
to self.views {
1353-
/// Get mutable reference to the [``NodeTable``](crate::NodeTable).
1354-
pub fn nodes_mut(&mut self) -> &mut crate::NodeTable;
1355-
}
1361+
/// Get reference to the [``EdgeTable``](crate::EdgeTable).
1362+
pub fn edges(&self) -> &EdgeTable {
1363+
&self.edges
1364+
}
1365+
1366+
pub fn edges_mut(&mut self) -> &mut EdgeTable {
1367+
&mut self.edges
1368+
}
1369+
1370+
/// Get reference to the [``NodeTable``](crate::NodeTable).
1371+
pub fn nodes(&self) -> &NodeTable {
1372+
&self.nodes
1373+
}
1374+
1375+
/// Get mutable reference to the [``NodeTable``](crate::NodeTable).
1376+
pub fn nodes_mut(&mut self) -> &mut NodeTable {
1377+
&mut self.nodes
1378+
}
1379+
1380+
/// Get reference to the [``SiteTable``](crate::SiteTable).
1381+
pub fn sites(&self) -> &SiteTable {
1382+
&self.sites
1383+
}
1384+
1385+
pub fn sites_mut(&mut self) -> &mut SiteTable {
1386+
&mut self.sites
1387+
}
1388+
1389+
/// Get reference to the [``MutationTable``](crate::MutationTable).
1390+
pub fn mutations(&self) -> &MutationTable {
1391+
&self.mutations
1392+
}
1393+
1394+
pub fn mutations_mut(&mut self) -> &mut MutationTable {
1395+
&mut self.mutations
1396+
}
1397+
1398+
/// Get reference to the [``IndividualTable``](crate::IndividualTable).
1399+
pub fn individuals(&self) -> &IndividualTable {
1400+
&self.individuals
1401+
}
1402+
1403+
pub fn individuals_mut(&mut self) -> &mut IndividualTable {
1404+
&mut self.individuals
1405+
}
1406+
1407+
/// Get reference to the [``PopulationTable``](crate::PopulationTable).
1408+
pub fn populations(&self) -> &PopulationTable {
1409+
&self.populations
1410+
}
1411+
1412+
pub fn populations_mut(&mut self) -> &mut PopulationTable {
1413+
&mut self.populations
1414+
}
1415+
1416+
/// Get reference to the [``MigrationTable``](crate::MigrationTable).
1417+
pub fn migrations(&self) -> &MigrationTable {
1418+
&self.migrations
1419+
}
1420+
1421+
pub fn migrations_mut(&mut self) -> &mut MigrationTable {
1422+
&mut self.migrations
1423+
}
1424+
1425+
#[cfg(feature = "provenance")]
1426+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
1427+
/// Get reference to the [``ProvenanceTable``](crate::provenance::ProvenanceTable)
1428+
pub fn provenances(&self) -> &ProvenanceTable {
1429+
&self.provenances
1430+
}
1431+
1432+
#[cfg(feature = "provenance")]
1433+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
1434+
/// Get reference to the [``ProvenanceTable``](crate::provenance::ProvenanceTable)
1435+
pub fn provenances_mut(&mut self) -> &mut ProvenanceTable {
1436+
&mut self.provenances
1437+
}
1438+
1439+
/// Return an iterator over the edges.
1440+
pub fn edges_iter(&self) -> impl Iterator<Item = crate::EdgeTableRow> + '_ {
1441+
self.edges.iter()
1442+
}
1443+
1444+
/// Return an iterator over the nodes.
1445+
pub fn nodes_iter(&self) -> impl Iterator<Item = crate::NodeTableRow> + '_ {
1446+
self.nodes.iter()
1447+
}
1448+
1449+
/// Return an iterator over the sites.
1450+
pub fn sites_iter(&self) -> impl Iterator<Item = crate::SiteTableRow> + '_ {
1451+
self.sites.iter()
1452+
}
1453+
1454+
/// Return an iterator over the mutations.
1455+
pub fn mutations_iter(&self) -> impl Iterator<Item = crate::MutationTableRow> + '_ {
1456+
self.mutations.iter()
13561457
}
13571458

1358-
delegate_table_view_api!();
1459+
/// Return an iterator over the individuals.
1460+
pub fn individuals_iter(&self) -> impl Iterator<Item = crate::IndividualTableRow> + '_ {
1461+
self.individuals.iter()
1462+
}
1463+
1464+
/// Return an iterator over the populations.
1465+
pub fn populations_iter(&self) -> impl Iterator<Item = crate::PopulationTableRow> + '_ {
1466+
self.populations.iter()
1467+
}
1468+
1469+
/// Return an iterator over the migrations.
1470+
pub fn migrations_iter(&self) -> impl Iterator<Item = crate::MigrationTableRow> + '_ {
1471+
self.migrations.iter()
1472+
}
1473+
1474+
#[cfg(feature = "provenance")]
1475+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
1476+
/// Return an iterator over provenances
1477+
pub fn provenances_iter(
1478+
&self,
1479+
) -> impl Iterator<Item = crate::provenance::ProvenanceTableRow> + '_ {
1480+
self.provenances.iter()
1481+
}
1482+
1483+
/// Obtain a vector containing the indexes ("ids")
1484+
/// of all nodes for which [`crate::NodeFlags::is_sample`]
1485+
/// is `true`.
1486+
///
1487+
/// The provided implementation dispatches to
1488+
/// [`crate::NodeTable::samples_as_vector`].
1489+
pub fn samples_as_vector(&self) -> Vec<crate::NodeId> {
1490+
self.nodes().samples_as_vector()
1491+
}
1492+
1493+
/// Obtain a vector containing the indexes ("ids") of all nodes
1494+
/// satisfying a certain criterion.
1495+
///
1496+
/// The provided implementation dispatches to
1497+
/// [`crate::NodeTable::create_node_id_vector`].
1498+
///
1499+
/// # Parameters
1500+
///
1501+
/// * `f`: a function. The function is passed the current table
1502+
/// collection and each [`crate::node_table::NodeTableRow`].
1503+
/// If `f` returns `true`, the index of that row is included
1504+
/// in the return value.
1505+
///
1506+
/// # Examples
1507+
///
1508+
/// Get all nodes with time > 0.0:
1509+
///
1510+
/// ```
1511+
/// let mut tables = tskit::TableCollection::new(100.).unwrap();
1512+
/// tables
1513+
/// .add_node(tskit::NodeFlags::new_sample(), 0.0, tskit::PopulationId::NULL,
1514+
/// tskit::IndividualId::NULL)
1515+
/// .unwrap();
1516+
/// tables
1517+
/// .add_node(tskit::NodeFlags::new_sample(), 1.0, tskit::PopulationId::NULL,
1518+
/// tskit::IndividualId::NULL)
1519+
/// .unwrap();
1520+
/// let samples = tables.create_node_id_vector(
1521+
/// |row: &tskit::NodeTableRow| row.time > 0.,
1522+
/// );
1523+
/// assert_eq!(samples[0], 1);
1524+
/// ```
1525+
pub fn create_node_id_vector(
1526+
&self,
1527+
f: impl FnMut(&crate::NodeTableRow) -> bool,
1528+
) -> Vec<crate::NodeId> {
1529+
self.nodes().create_node_id_vector(f)
1530+
}
13591531

13601532
/// Pointer to the low-level C type.
13611533
pub fn as_ptr(&self) -> *const ll_bindings::tsk_table_collection_t {

0 commit comments

Comments
 (0)