diff --git a/brood/src/commands/ingest.rs b/brood/src/commands/ingest.rs index e1714b7..4fc182d 100644 --- a/brood/src/commands/ingest.rs +++ b/brood/src/commands/ingest.rs @@ -14,7 +14,7 @@ struct JsonPage { id: u32, title: String, length: u32, - links: Vec<(String, u32, u32)>, + links: Vec<(String, u32, u32, u8)>, redirect: Option, } @@ -83,14 +83,14 @@ fn first_stage() -> io::Result<(AdjacencyList, Titles)> { let to = titles.insert(util::normalize_link(&to)); result.links.push(Link { to, - data: LinkInfo { start: 0, end: 0 }, + data: LinkInfo::default(), }); } else { - for (to, start, end) in json_page.links { + for (to, start, len, flags) in json_page.links { let to = titles.insert(util::normalize_link(&to)); result.links.push(Link { to, - data: LinkInfo { start, end }, + data: LinkInfo { start, len, flags }, }); } } diff --git a/brood/src/data.rs b/brood/src/data.rs index afca0e1..164f1f1 100644 --- a/brood/src/data.rs +++ b/brood/src/data.rs @@ -102,10 +102,25 @@ impl

Page

{ } } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Default, Clone, Copy)] pub struct LinkInfo { pub start: u32, - pub end: u32, + pub len: u32, + pub flags: u8, +} + +impl LinkInfo { + pub fn end(self) -> u32 { + self.start + self.len + } + + pub fn in_parens(self) -> bool { + self.flags & 0b1 != 0 + } + + pub fn in_structure(self) -> bool { + self.flags & 0b10 != 0 + } } #[derive(Debug, Clone, Copy)] @@ -118,7 +133,8 @@ impl Link { pub fn write(&self, to: &mut W) -> io::Result<()> { ioutil::write_u32(self.to, to)?; ioutil::write_u32(self.data.start, to)?; - ioutil::write_u32(self.data.end, to)?; + ioutil::write_u32(self.data.len, to)?; + ioutil::write_u8(self.data.flags, to)?; Ok(()) } @@ -126,11 +142,12 @@ impl Link { pub fn read(from: &mut R) -> io::Result { let to = ioutil::read_u32(from)?; let start = ioutil::read_u32(from)?; - let end = ioutil::read_u32(from)?; + let len = ioutil::read_u32(from)?; + let flags = ioutil::read_u8(from)?; Ok(Self { to, - data: LinkInfo { start, end }, + data: LinkInfo { start, len, flags }, }) } } @@ -204,7 +221,7 @@ impl AdjacencyList { for link in &self.links { assert!(link.to <= u32::MAX as u32, "link to"); assert!(link.data.start <= u32::MAX as u32, "link start"); - assert!(link.data.end <= u32::MAX as u32, "link end"); + assert!(link.data.len <= u32::MAX as u32, "link end"); } // Check that all links contain valid indices