MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / compute_visibility

Function compute_visibility

atomic-cli/src/commands/view/list.rs:243–277  ·  view source on GitHub ↗

Decide which views are shown. With `show_all`, every view is visible. Otherwise a view is visible when it has changes of its own, or it is the current view, or it is an ancestor of such a view (so the hierarchy stays connected). Returns the visible name set and the hidden count.

(
    entries: &[ViewEntry],
    show_all: bool,
)

Source from the content-addressed store, hash-verified

241/// ancestor of such a view (so the hierarchy stays connected). Returns the
242/// visible name set and the hidden count.
243pub(crate) fn compute_visibility(
244 entries: &[ViewEntry],
245 show_all: bool,
246) -> (HashSet<String>, usize) {
247 if show_all {
248 let all = entries.iter().map(|e| e.name.clone()).collect();
249 return (all, 0);
250 }
251
252 let by_name: HashMap<&str, &ViewEntry> = entries.iter().map(|e| (e.name.as_str(), e)).collect();
253
254 let mut visible: HashSet<String> = HashSet::new();
255 let mut stack: Vec<&str> = entries
256 .iter()
257 .filter(|e| e.own_change_count > 0 || e.is_current)
258 .map(|e| e.name.as_str())
259 .collect();
260
261 while let Some(name) = stack.pop() {
262 // Revisiting a name means a parent cycle — stop walking that chain.
263 if !visible.insert(name.to_string()) {
264 continue;
265 }
266 if let Some(entry) = by_name.get(name) {
267 if let Some(parent) = &entry.parent {
268 if by_name.contains_key(parent.as_str()) {
269 stack.push(parent.as_str());
270 }
271 }
272 }
273 }
274
275 let hidden = entries.len() - visible.len();
276 (visible, hidden)
277}
278
279/// Order the visible views depth-first along the parent chains.
280///

Calls 9

contains_keyMethod · 0.80
getMethod · 0.65
collectMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
as_strMethod · 0.45
insertMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45