|
1 | 1 | use crate::tsdef::{IdType, Position, Time, NULL_ID}; |
| 2 | +use bitflags::bitflags; |
2 | 3 | use std::cmp::Ordering; |
3 | 4 | use thiserror::Error; |
4 | 5 |
|
@@ -269,6 +270,40 @@ fn sort_mutation_table(sites: &[Site], mutations: &mut MutationTable) { |
269 | 270 | }); |
270 | 271 | } |
271 | 272 |
|
| 273 | +bitflags! { |
| 274 | + /// Modifies behavior of |
| 275 | + /// [``TableCollection::validate_tables``] |
| 276 | + /// |
| 277 | + /// ``` |
| 278 | + /// let f = forrustts::TableValidationFlags::empty(); |
| 279 | + /// assert_eq!(f.contains(forrustts::TableValidationFlags::VALIDATE_ALL), true); |
| 280 | + /// ``` |
| 281 | + #[derive(Default)] |
| 282 | + pub struct TableValidationFlags: u32 { |
| 283 | + /// Validate all tables. |
| 284 | + /// This is also the "default"/empty. |
| 285 | + const VALIDATE_ALL = 0; |
| 286 | + } |
| 287 | +} |
| 288 | + |
| 289 | +bitflags! { |
| 290 | + /// Modifies behavior of |
| 291 | + /// [``TableCollection::sort_tables``] |
| 292 | + /// |
| 293 | + /// ``` |
| 294 | + /// let f = forrustts::TableSortingFlags::empty(); |
| 295 | + /// assert_eq!(f.contains(forrustts::TableSortingFlags::SORT_ALL), true); |
| 296 | + /// ``` |
| 297 | + #[derive(Default)] |
| 298 | + pub struct TableSortingFlags: u32 { |
| 299 | + /// Sort all tables. |
| 300 | + /// This is also the "default"/empty. |
| 301 | + const SORT_ALL = 0; |
| 302 | + /// Do not sort the edge table. |
| 303 | + const SKIP_EDGE_TABLE = 1 << 0; |
| 304 | + } |
| 305 | +} |
| 306 | + |
272 | 307 | /// Perform a data integrity check on an [``EdgeTable``]. |
273 | 308 | /// |
274 | 309 | /// This checks, amongst other things, the sorting order |
@@ -653,10 +688,26 @@ impl TableCollection { |
653 | 688 | } |
654 | 689 |
|
655 | 690 | /// Sort all tables for simplification. |
| 691 | + #[deprecated(since = "0.1.0", note = "use sort_tables instead")] |
656 | 692 | pub fn sort_tables_for_simplification(&mut self) { |
657 | | - sort_edge_table(&self.nodes_, &mut self.edges_); |
| 693 | + self.sort_tables(TableSortingFlags::empty()); |
| 694 | + } |
| 695 | + |
| 696 | + /// Sort all tables for simplification. |
| 697 | + pub fn sort_tables(&mut self, flags: TableSortingFlags) { |
| 698 | + if !flags.contains(TableSortingFlags::SKIP_EDGE_TABLE) { |
| 699 | + sort_edge_table(&self.nodes_, &mut self.edges_); |
| 700 | + } |
658 | 701 | sort_mutation_table(&self.sites_, &mut self.mutations_); |
659 | 702 | } |
| 703 | + |
| 704 | + /// Run a validation check on the tables. |
| 705 | + pub fn validate(&self, flags: TableValidationFlags) -> TablesResult<bool> { |
| 706 | + if flags.contains(TableValidationFlags::VALIDATE_ALL) { |
| 707 | + validate_edge_table(self.genome_length(), &self.edges_, &self.nodes_)?; |
| 708 | + } |
| 709 | + Ok(true) |
| 710 | + } |
660 | 711 | } |
661 | 712 |
|
662 | 713 | #[cfg(test)] |
|
0 commit comments