Refactor changing data
This commit is contained in:
parent
32b72c10c8
commit
d99b3d49e0
2 changed files with 6 additions and 6 deletions
|
|
@ -83,8 +83,8 @@ fn dijkstra(
|
||||||
) -> Option<Vec<u32>> {
|
) -> Option<Vec<u32>> {
|
||||||
println!("> Prepare state");
|
println!("> Prepare state");
|
||||||
let mut data = data
|
let mut data = data
|
||||||
.change_page_data(&DijkstraPageInfo::from_page_info)
|
.change_page_data(DijkstraPageInfo::from_page_info)
|
||||||
.change_link_data(&DijkstraLinkInfo::from_link_info);
|
.change_link_data(DijkstraLinkInfo::from_link_info);
|
||||||
let mut queue = BinaryHeap::new();
|
let mut queue = BinaryHeap::new();
|
||||||
data.page_mut(from_idx).data.cost = 0;
|
data.page_mut(from_idx).data.cost = 0;
|
||||||
queue.push(Entry::new(0, from_idx));
|
queue.push(Entry::new(0, from_idx));
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ impl Page<PageInfo> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P> Page<P> {
|
impl<P> Page<P> {
|
||||||
pub fn change_data<P2>(self, f: &impl Fn(P) -> P2) -> Page<P2> {
|
pub fn change_data<P2>(self, f: impl Fn(P) -> P2) -> Page<P2> {
|
||||||
Page {
|
Page {
|
||||||
link_idx: self.link_idx,
|
link_idx: self.link_idx,
|
||||||
data: f(self.data),
|
data: f(self.data),
|
||||||
|
|
@ -136,7 +136,7 @@ impl Link<LinkInfo> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L> Link<L> {
|
impl<L> Link<L> {
|
||||||
pub fn change_data<L2>(self, f: &impl Fn(L) -> L2) -> Link<L2> {
|
pub fn change_data<L2>(self, f: impl Fn(L) -> L2) -> Link<L2> {
|
||||||
Link {
|
Link {
|
||||||
to: self.to,
|
to: self.to,
|
||||||
data: f(self.data),
|
data: f(self.data),
|
||||||
|
|
@ -240,7 +240,7 @@ impl<P, L> AdjacencyList<P, L> {
|
||||||
&mut self.links[idx as usize]
|
&mut self.links[idx as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn change_page_data<P2>(self, page_f: &impl Fn(P) -> P2) -> AdjacencyList<P2, L> {
|
pub fn change_page_data<P2>(self, page_f: impl Fn(P) -> P2 + Copy) -> AdjacencyList<P2, L> {
|
||||||
let pages = self
|
let pages = self
|
||||||
.pages
|
.pages
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
@ -253,7 +253,7 @@ impl<P, L> AdjacencyList<P, L> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn change_link_data<L2>(self, link_f: &impl Fn(L) -> L2) -> AdjacencyList<P, L2> {
|
pub fn change_link_data<L2>(self, link_f: impl Fn(L) -> L2 + Copy) -> AdjacencyList<P, L2> {
|
||||||
let links = self
|
let links = self
|
||||||
.links
|
.links
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue