Make stored data more compact
This commit is contained in:
parent
f6bcb39c52
commit
51096c99e1
3 changed files with 55 additions and 4 deletions
|
|
@ -21,3 +21,49 @@ pub struct AdjacencyList {
|
|||
pub pages: Vec<Page>,
|
||||
pub links: Vec<Link>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct SlimAdjacencyList {
|
||||
pages: Vec<(u32, u32, u16, String, bool)>,
|
||||
links: Vec<(u32, u32, u32)>,
|
||||
}
|
||||
|
||||
impl SlimAdjacencyList {
|
||||
pub fn from_alist(alist: AdjacencyList) -> Self {
|
||||
let pages = alist
|
||||
.pages
|
||||
.into_iter()
|
||||
.map(|p| (p.link_idx, p.id, p.ns, p.title, p.redirect))
|
||||
.collect();
|
||||
|
||||
let links = alist
|
||||
.links
|
||||
.into_iter()
|
||||
.map(|l| (l.to, l.start, l.end))
|
||||
.collect();
|
||||
|
||||
Self { pages, links }
|
||||
}
|
||||
|
||||
pub fn to_alist(self) -> AdjacencyList {
|
||||
let pages = self
|
||||
.pages
|
||||
.into_iter()
|
||||
.map(|(link_idx, id, ns, title, redirect)| Page {
|
||||
link_idx,
|
||||
ns,
|
||||
id,
|
||||
title,
|
||||
redirect,
|
||||
})
|
||||
.collect();
|
||||
|
||||
let links = self
|
||||
.links
|
||||
.into_iter()
|
||||
.map(|(to, start, end)| Link { to, start, end })
|
||||
.collect();
|
||||
|
||||
AdjacencyList { pages, links }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue