-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defines intergraph edges on the parent region, so mermaid renders them correctly .
- Loading branch information
Showing
7 changed files
with
132 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//! Lowest common ancestor algorithm on hierarchy forests. | ||
use std::collections::HashSet; | ||
|
||
use crate::{Hierarchy, NodeIndex}; | ||
|
||
/// Constructs a new lowest common ancestor data structure. | ||
pub fn lca(hierarchy: &Hierarchy) -> LCA { | ||
LCA { | ||
hierarchy: hierarchy.clone(), | ||
} | ||
} | ||
|
||
/// A precomputed data structure for lowest common ancestor queries between | ||
/// nodes in a hierarchy. | ||
#[derive(Debug, Clone)] | ||
pub struct LCA { | ||
hierarchy: Hierarchy, | ||
} | ||
|
||
impl LCA { | ||
/// Returns the lowest common ancestor of two nodes. | ||
pub fn lca(&self, a: NodeIndex, b: NodeIndex) -> Option<NodeIndex> { | ||
// Placeholder slow implementation. | ||
let mut parents = HashSet::new(); | ||
|
||
let mut a = Some(a); | ||
while let Some(node) = a { | ||
parents.insert(node); | ||
a = self.hierarchy.parent(node); | ||
} | ||
|
||
let mut b = Some(b); | ||
while let Some(node) = b { | ||
if parents.contains(&node) { | ||
return Some(node); | ||
} | ||
b = self.hierarchy.parent(node); | ||
} | ||
|
||
None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ source: src/render.rs | |
expression: mermaid | ||
--- | ||
graph LR | ||
2[2] | ||
1[1] | ||
0[0] | ||
0-->1 | ||
0-->2 | ||
1[1] | ||
2[2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,6 @@ graph LR | |
subgraph 0 [0] | ||
direction LR | ||
1[1] | ||
1-->2 | ||
2[2] | ||
1-->2 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,11 @@ graph LR | |
subgraph 1 [1] | ||
direction LR | ||
3[3] | ||
3-->4 | ||
end | ||
1-->2 | ||
subgraph 2 [2] | ||
direction LR | ||
4[4] | ||
end | ||
1-->2 | ||
3-->4 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters