MCPcopy
hub / github.com/opentrace/opentrace / computeLastAtDepth

Function computeLastAtDepth

ui/src/components/chat/results/TraverseResult.tsx:33–50  ·  view source on GitHub ↗

* Determine which entries are the last at their depth level. * An entry is "last at depth" if no subsequent sibling at the same depth * appears before the depth decreases or the list ends.

(entries: TraverseEntry[])

Source from the content-addressed store, hash-verified

31 * appears before the depth decreases or the list ends.
32 */
33function computeLastAtDepth(entries: TraverseEntry[]): Set<number> {
34 const lastSet = new Set<number>();
35 for (let i = entries.length - 1; i >= 0; i--) {
36 const depth = entries[i].depth;
37 // Check if any later entry at the same depth exists before
38 // the parent scope ends (i.e., a shallower depth appears)
39 let isLast = true;
40 for (let j = i + 1; j < entries.length; j++) {
41 if (entries[j].depth < depth) break;
42 if (entries[j].depth === depth) {
43 isLast = false;
44 break;
45 }
46 }
47 if (isLast) lastSet.add(i);
48 }
49 return lastSet;
50}
51
52/** Hierarchical tree view with CSS-based tree-line connectors */
53export default function TraverseResult({ entries, onNodeSelect }: Props) {

Callers 1

TraverseResultFunction · 0.85

Calls 1

addMethod · 0.45

Tested by

no test coverage detected