This commit is contained in:
33333-33333 2026-07-05 18:01:36 +09:00
commit 8f9f5b5100
108 changed files with 2139 additions and 1500 deletions

View file

@ -78,50 +78,12 @@
return childListsParent || parentListsChild;
}
function relatedNodesFromIndex(family = {}, relationIndex = buildRelationIndex(family)) {
const relatedIds = new Set();
for (const n of Object.values(family || {})) {
if (!n?.id) continue;
const parents = relationIndex.parentsByChild.get(n.id) || new Set();
const children = relationIndex.childrenByParent.get(n.id) || new Set();
if (parents.size || children.size) relatedIds.add(n.id);
for (const id of parents) relatedIds.add(id);
for (const id of children) relatedIds.add(id);
}
return Array.from(relatedIds).map(id => family[id]).filter(Boolean);
}
function buildLineageGraph(family = {}, nodes = relatedNodesFromIndex(family), relationIndex = buildRelationIndex(family)) {
const graph = new Map();
for (const n of nodes || []) if (n?.id) graph.set(n.id, new Set());
const addGraphEdge = (a, b) => {
if (!a || !b || !graph.has(a) || !graph.has(b)) return;
graph.get(a).add(b);
graph.get(b).add(a);
};
for (const n of nodes || []) {
if (!n?.id) continue;
const parentCandidates = new Set((n.parents || []).filter(Boolean));
for (const parentId of relationIndex.parentsByChild.get(n.id) || []) parentCandidates.add(parentId);
for (const parentId of parentCandidates) {
if (parentId !== n.id && relationAllowsParentChild(family, n.id, parentId)) addGraphEdge(n.id, parentId);
}
const childCandidates = new Set((n.children || []).filter(Boolean));
for (const childId of relationIndex.childrenByParent.get(n.id) || []) childCandidates.add(childId);
for (const childId of childCandidates) {
if (childId !== n.id && relationAllowsParentChild(family, childId, n.id)) addGraphEdge(n.id, childId);
}
}
return graph;
}
global.TarinaiFamilyGraph = {
connectedComponents,
addParentEdge,
buildRelationIndex,
buildLineageGraph,
relatedNodesFromIndex,
relationAllowsParentChild,
};
})(typeof window !== "undefined" ? window : globalThis);