Calculate previous and next sibling in tree
This commit is contained in:
parent
54fc4b59ce
commit
9a351b5eb3
2 changed files with 30 additions and 26 deletions
|
|
@ -99,6 +99,24 @@ impl<M: Msg> Tree<M> {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prev_sibling(&self, id: &M::Id) -> Option<M::Id> {
|
||||
let siblings = self.siblings(id)?;
|
||||
siblings
|
||||
.iter()
|
||||
.zip(siblings.iter().skip(1))
|
||||
.find(|(_, s)| *s == id)
|
||||
.map(|(s, _)| s.clone())
|
||||
}
|
||||
|
||||
pub fn next_sibling(&self, id: &M::Id) -> Option<M::Id> {
|
||||
let siblings = self.siblings(id)?;
|
||||
siblings
|
||||
.iter()
|
||||
.zip(siblings.iter().skip(1))
|
||||
.find(|(s, _)| *s == id)
|
||||
.map(|(_, s)| s.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue