11use std:: collections:: { BTreeMap , BTreeSet } ;
22
3+ use but_core:: ref_metadata:: StackId ;
34use but_graph:: {
45 EntryPoint , Graph , SegmentIndex , SegmentMetadata , projection:: StackCommitDebugFlags ,
56} ;
@@ -9,23 +10,43 @@ type StringTree = Tree<String>;
910
1011/// Visualize `graph` as a tree.
1112pub fn graph_workspace ( workspace : & but_graph:: projection:: Workspace < ' _ > ) -> StringTree {
13+ graph_workspace_inner ( workspace, None )
14+ }
15+
16+ /// Visualize `graph` as a tree, and remap random stack ids to something deterministic.
17+ pub fn graph_workspace_determinisitcally (
18+ workspace : & but_graph:: projection:: Workspace < ' _ > ,
19+ ) -> StringTree {
20+ graph_workspace_inner ( workspace, Some ( Default :: default ( ) ) )
21+ }
22+
23+ fn graph_workspace_inner (
24+ workspace : & but_graph:: projection:: Workspace < ' _ > ,
25+ mut stack_id_map : Option < BTreeMap < StackId , StackId > > ,
26+ ) -> StringTree {
1227 let commit_flags = if workspace. graph . hard_limit_hit ( ) {
1328 StackCommitDebugFlags :: HardLimitReached
1429 } else {
1530 Default :: default ( )
1631 } ;
1732 let mut root = Tree :: new ( workspace. debug_string ( ) ) ;
1833 for stack in & workspace. stacks {
19- root. push ( tree_for_stack ( stack, commit_flags) ) ;
34+ root. push ( tree_for_stack ( stack, commit_flags, stack_id_map . as_mut ( ) ) ) ;
2035 }
2136 root
2237}
2338
2439fn tree_for_stack (
2540 stack : & but_graph:: projection:: Stack ,
2641 commit_flags : StackCommitDebugFlags ,
42+ stack_id_map : Option < & mut BTreeMap < StackId , StackId > > ,
2743) -> StringTree {
28- let mut root = Tree :: new ( stack. debug_string ( ) ) ;
44+ let mut root = Tree :: new (
45+ stack. debug_string ( stack. id . zip ( stack_id_map) . map ( |( id, map) | {
46+ let next_id = StackId :: from_number_for_testing ( ( map. len ( ) + 1 ) as u128 ) ;
47+ * map. entry ( id) . or_insert ( next_id)
48+ } ) ) ,
49+ ) ;
2950 for segment in & stack. segments {
3051 root. push ( tree_for_stack_segment ( segment, commit_flags) ) ;
3152 }
0 commit comments