diff options
Diffstat (limited to 'chain/src/archive.txt')
-rw-r--r-- | chain/src/archive.txt | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/chain/src/archive.txt b/chain/src/archive.txt index 7bd6f31..79fe6d8 100644 --- a/chain/src/archive.txt +++ b/chain/src/archive.txt @@ -540,3 +540,101 @@ // // Ok(None) // } + +// let mut builder = PLGBuilderMut::from_graph_mut(&mut self.graph); + +// // Just a dummy label for use in adding edges. +// // +// // REVIEW: I probably should refactor the API for builder_mut. +// let root_label = fragment +// .vertex_label(root)? +// .ok_or(Error::NodeNoLabel(root))?; + +// let nodes_len = fragment.nodes_len(); + +// /// If the fragment root has a duplicate label, the forest +// /// will not grow, so we use the label to find the adjoined +// /// node index. +// /// +// /// The nodes hava already been added to the forest, so it is +// /// safe to call unwrap. +// macro_rules! conversion ( +// ($node:expr) => { +// { +// builder +// .query_label( +// fragment +// .vertex_label($node)? +// .ok_or(Error::NodeNoLabel($node))? +// ).unwrap() +// } +// } +// ); + +// // If the fragment has been planted before, we just add an +// // edge. + +// if planted { +// builder.add_edge(node_id, conversion!(root), root_label)?; + +// return Ok(()); +// } + +// // First adjoin the relevant nodes and join the edges later. + +// let mut used_nodes: Vec<bool> = std::iter::repeat(false).take(nodes_len).collect(); + +// let mut stack = vec![root]; + +// while let Some(top) = stack.pop() { +// if used_nodes.get(top).copied() == Some(true) { +// continue; +// } + +// *used_nodes +// .get_mut(top) +// .ok_or(Error::IndexOutOfBounds(top, nodes_len))? = true; + +// stack.extend(fragment.children_of(top)?); +// } + +// let used_nodes = used_nodes; + +// for node in (0..nodes_len).filter(|node| used_nodes.get(*node).copied() == Some(true)) { +// let label = fragment +// .vertex_label(node)? +// .ok_or(Error::NodeNoLabel(node))?; + +// builder.add_vertex(label); +// } + +// // Don't forget to join the new sub-forest to the original +// // forest, at the specified position. + +// builder.add_edge(node_id, conversion!(root), root_label)?; + +// // We can try to calculate the depth of fragments, if we need +// // to lower the memory usage. But in our use cases, we +// // usually deal with fragments where each node has at most one +// // child, so the depth is supposed to be equal to the length +// // in this case. +// let mut stack = Vec::with_capacity(fragment.nodes_len()); + +// stack.push(root); + +// let mut seen_nodes = std::collections::HashSet::<usize>::new(); + +// while let Some(top) = stack.pop() { +// seen_nodes.insert(top); + +// for child in fragment.children_of(top)? { +// builder.add_edge(conversion!(top), conversion!(child), root_label)?; + +// if !seen_nodes.contains(&child) { +// seen_nodes.insert(child); +// stack.push(child); +// } +// } +// } + +// Ok(()) |