@@ -23,12 +23,12 @@ pub use crate::storage::in_memory_storage::InMemoryStorage;
2323pub use crate :: storage:: query:: Match ;
2424
2525use crate :: {
26- adg:: { AdgNode , DepGraph , DepGraphInner } ,
26+ adg:: { adg_internal :: AdgInner , AdgNode } ,
2727 artifact_id:: ArtifactId ,
2828 error:: InputManifestError ,
2929 hash_algorithm:: HashAlgorithm ,
3030 input_manifest:: InputManifest ,
31- Identify ,
31+ Adg , Identify ,
3232} ;
3333
3434/// Represents the interface for storing and querying manifests.
@@ -78,13 +78,13 @@ pub trait Storage<H: HashAlgorithm> {
7878 I : Identify < H > ;
7979
8080 /// Get the Artifact Dependency Graph of the target.
81- fn get_adg < I > ( & self , target_aid : I ) -> Result < DepGraph < H > , InputManifestError >
81+ fn get_adg < I > ( & self , target_aid : I ) -> Result < Adg < H > , InputManifestError >
8282 where
8383 I : Identify < H > ,
8484 {
8585 let target_aid = target_aid. identify ( ) ?;
86- let graph = build_graph ( target_aid, self ) ?;
87- Ok ( DepGraph :: from_graph ( graph) )
86+ let ( graph, root ) = build_graph ( target_aid, self ) ?;
87+ Ok ( Adg :: new ( graph, root ) )
8888 }
8989}
9090
@@ -137,29 +137,29 @@ impl<H: HashAlgorithm, S: Storage<H>> Storage<H> for &mut S {
137137fn build_graph < H , S > (
138138 target_aid : ArtifactId < H > ,
139139 storage : & S ,
140- ) -> Result < DepGraphInner < H > , InputManifestError >
140+ ) -> Result < ( AdgInner < H > , NodeIndex ) , InputManifestError >
141141where
142142 H : HashAlgorithm ,
143143 S : Storage < H > + ?Sized ,
144144{
145145 let mut graph = Graph :: new ( ) ;
146- populate_graph ( & mut graph, target_aid, None , storage) ?;
147- Ok ( graph)
146+ let root = populate_graph ( & mut graph, target_aid, None , storage) ?;
147+ Ok ( ( graph, root ) )
148148}
149149
150150/// Build one layer of the ADG, recursing down for further layers.
151151fn populate_graph < H , S > (
152- graph : & mut DepGraphInner < H > ,
152+ graph : & mut AdgInner < H > ,
153153 target_aid : ArtifactId < H > ,
154154 parent_idx : Option < NodeIndex > ,
155155 storage : & S ,
156- ) -> Result < ( ) , InputManifestError >
156+ ) -> Result < NodeIndex , InputManifestError >
157157where
158158 H : HashAlgorithm ,
159159 S : Storage < H > + ?Sized ,
160160{
161161 // Add current node to the graph.
162- let self_idx = graph. add_node ( AdgNode { id : target_aid } ) ;
162+ let self_idx = graph. add_node ( AdgNode :: new ( target_aid) ) ;
163163
164164 // If there's a parent, add an edge from the parent to the current node.
165165 if let Some ( parent_idx) = parent_idx {
@@ -169,9 +169,9 @@ where
169169 // If there's a manifest for current node, recurse for each child.
170170 if let Some ( manifest) = storage. get_manifest ( Match :: target ( target_aid) ) ? {
171171 for input in manifest. inputs ( ) {
172- populate_graph ( graph, input. artifact ( ) , Some ( self_idx) , storage) ?;
172+ let _ = populate_graph ( graph, input. artifact ( ) , Some ( self_idx) , storage) ?;
173173 }
174174 }
175175
176- Ok ( ( ) )
176+ Ok ( self_idx )
177177}
0 commit comments