MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cachedGeometry

Function cachedGeometry

graph-ui/src/galaxy/organic-clusters.ts:53–71  ·  view source on GitHub ↗

Exact comparisons avoid hashing or sorting on a warm selection. Metadata * unrelated to geometry is intentionally excluded and always read afresh.

(data: GraphData, roots: ReadonlySet<number> | undefined, previous: Map<number, GraphNode>)

Source from the content-addressed store, hash-verified

51/** Exact comparisons avoid hashing or sorting on a warm selection. Metadata
52 * unrelated to geometry is intentionally excluded and always read afresh. */
53function cachedGeometry(data: GraphData, roots: ReadonlySet<number> | undefined, previous: Map<number, GraphNode>): OrganicClusterLayout | undefined {
54 for (let index = 0; index < geometryMemo.length; index++) {
55 const cached = geometryMemo[index]!;
56 if (cached.nodes.size !== data.nodes.length || cached.edges.length !== data.edges.length || cached.hasPrevious !== (previous.size > 0)) continue;
57 if (!data.nodes.every(node => {
58 const saved = cached.nodes.get(node.id);
59 return saved && Object.is(saved.size, node.size) && saved.file === node.file_path
60 && saved.root === Boolean(roots?.has(node.id)) && samePoint(saved.previous, previous.get(node.id));
61 })) continue;
62 if (!data.edges.every((edge, at) => {
63 const saved = cached.edges[at]!;
64 return saved[0] === edge.id && saved[1] === edge.source && saved[2] === edge.target && saved[3] === edge.type;
65 })) continue;
66 geometryMemo.splice(index, 1); geometryMemo.unshift(cached);
67 return { data: { ...data, nodes: data.nodes.map(node => ({ ...node, ...cached.positions.get(node.id)! })) },
68 groups: copyGroups(cached.groups), groupByNode: new Map(cached.groupByNode) };
69 }
70 return undefined;
71}
72
73function rememberGeometry(data: GraphData, result: OrganicClusterLayout, roots: ReadonlySet<number> | undefined, previous: Map<number, GraphNode>): void {
74 const weight = data.nodes.length * 4 + data.edges.length;

Callers 1

layoutOrganicClustersFunction · 0.85

Calls 3

samePointFunction · 0.85
copyGroupsFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected