MCPcopy Create free account
hub / github.com/csskit/csskit / is_last_child

Method is_last_child

crates/csskit/src/commands/tree.rs:90–114  ·  view source on GitHub ↗

Check if `node_idx` is the last direct child of its parent.

(&self, node_idx: usize)

Source from the content-addressed store, hash-verified

88
89 /// Check if `node_idx` is the last direct child of its parent.
90 fn is_last_child(&self, node_idx: usize) -> bool {
91 let node_depth = self.nodes[node_idx].depth;
92 if node_depth == 0 {
93 return false;
94 }
95
96 let Some(parent_idx) = self.find_ancestor_at_depth(node_idx, node_depth - 1) else {
97 return false;
98 };
99
100 let parent = &self.nodes[parent_idx];
101 let parent_depth = parent.depth;
102
103 // Find the last direct child of the parent
104 let mut last_child_idx = None;
105 for j in parent.child_start_idx..self.nodes.len() {
106 if self.nodes[j].depth == parent_depth + 1 {
107 last_child_idx = Some(j);
108 } else if self.nodes[j].depth <= parent_depth {
109 break;
110 }
111 }
112
113 last_child_idx == Some(node_idx)
114 }
115}
116
117#[visitor]

Callers 1

build_prefixMethod · 0.45

Calls 2

lenMethod · 0.45

Tested by

no test coverage detected