@@ -14,6 +14,7 @@ use crate::SiteTable;
1414use crate :: TableAccess ;
1515use crate :: TableClearOptions ;
1616use crate :: TableEqualityOptions ;
17+ use crate :: TableIntegrityCheckFlags ;
1718use crate :: TableOutputOptions ;
1819use crate :: TableSortOptions ;
1920use crate :: TreeSequenceFlags ;
@@ -686,6 +687,56 @@ impl TableCollection {
686687 }
687688 )
688689 }
690+
691+ /// Validate the contents of the table collection
692+ ///
693+ /// # Parameters
694+ ///
695+ /// `flags` is an instance of [`TableIntegrityCheckFlags`]
696+ ///
697+ /// # Return value
698+ ///
699+ /// `0` upon success, or an error code.
700+ /// However, if `flags` contains [`TableIntegrityCheckFlags::CHECK_TREES`],
701+ /// and no error is returned, then the return value is the number
702+ /// of trees.
703+ ///
704+ /// # Note
705+ ///
706+ /// Creating a [`crate::TreeSequence`] from a table collection will automatically
707+ /// run an integrity check.
708+ /// See [`TableCollection::tree_sequence`].
709+ ///
710+ /// # Examples
711+ ///
712+ /// There are many ways for a table colletion to be invalid.
713+ /// These examples are just the tip of the iceberg.
714+ ///
715+ /// ```should_panic
716+ /// let mut tables = tskit::TableCollection::new(10.0).unwrap();
717+ /// // Right position is > sequence_length
718+ /// tables.add_edge(0.0, 11.0, 0, 0);
719+ /// tables.check_integrity(tskit::TableIntegrityCheckFlags::default()).unwrap();
720+ /// ```
721+ ///
722+ /// ```should_panic
723+ /// let mut tables = tskit::TableCollection::new(10.0).unwrap();
724+ /// // Left position is < 0.0
725+ /// tables.add_edge(-1., 10.0, 0, 0);
726+ /// tables.check_integrity(tskit::TableIntegrityCheckFlags::default()).unwrap();
727+ /// ```
728+ ///
729+ /// ```should_panic
730+ /// let mut tables = tskit::TableCollection::new(10.0).unwrap();
731+ /// // Edges cannot have null node ids
732+ /// tables.add_edge(0., 10.0, tskit::NodeId::NULL, 0);
733+ /// tables.check_integrity(tskit::TableIntegrityCheckFlags::default()).unwrap();
734+ /// ```
735+ pub fn check_integrity ( & self , flags : TableIntegrityCheckFlags ) -> TskReturnValue {
736+ let rv =
737+ unsafe { ll_bindings:: tsk_table_collection_check_integrity ( self . inner , flags. bits ( ) ) } ;
738+ handle_tsk_return_value ! ( rv)
739+ }
689740}
690741
691742impl TableAccess for TableCollection {
0 commit comments