Add more checks

This commit is contained in:
Joscha 2022-10-21 19:53:15 +02:00
parent 23463522f0
commit 78aa27c019

View file

@ -120,6 +120,22 @@ pub struct AdjacencyList {
impl AdjacencyList {
pub fn check_consistency(&self) {
// Check that all types are large enough
assert!(self.pages.len() <= u32::MAX as usize, "pages len");
assert!(self.links.len() <= u32::MAX as usize, "links len");
for page in &self.pages {
assert!(page.link_idx <= u32::MAX as u32, "page link_idx");
assert!(page.id <= u32::MAX as u32, "page id");
assert!(page.length <= u32::MAX as u32, "page length");
assert!(page.title.len() <= u8::MAX as usize, "page title len");
}
for link in &self.links {
assert!(link.to <= u32::MAX as u32, "link to");
assert!(link.start <= u32::MAX as u32, "link start");
assert!(link.end <= u32::MAX as u32, "link end");
}
// Check that all links contain valid indices
let range = 0..self.pages.len() as u32;
for link in &self.links {
if !range.contains(&link.to) {