MCPcopy Index your code
hub / github.com/douchuan/algorithm / expand_sharp

Function expand_sharp

src/tree/binary/builder/level.rs:65–97  ·  view source on GitHub ↗

"#" symbol as empty child

(vec: &[&'a str])

Source from the content-addressed store, hash-verified

63
64// "#" symbol as empty child
65fn expand_sharp<'a>(vec: &[&'a str]) -> Vec<&'a str> {
66 let mut results = Vec::new();
67
68 for &v in vec.iter() {
69 // root
70 if results.is_empty() {
71 results.push(v);
72 continue;
73 }
74
75 // child
76 if v == "#" {
77 results.push(v);
78 } else {
79 // child
80 loop {
81 // new child idx
82 let idx = results.len();
83 let parent = results[binary_tree::parent(idx)];
84 if parent == "#" {
85 // if parent is "#", children are "#",
86 // so just push "#"
87 results.push(parent);
88 } else {
89 results.push(v);
90 break;
91 }
92 }
93 }
94 }
95
96 results
97}
98
99#[test]
100fn t_expand_sharp() {

Callers 1

buildFunction · 0.85

Calls 5

parentFunction · 0.85
pushMethod · 0.80
iterMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected