UNPKG

mermaid

Version:

Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.

8 lines (7 loc) • 1.02 kB
{ "version": 3, "sources": ["../../../src/diagrams/common/containment.ts"], "sourcesContent": ["/**\n * True when `parentId` is `childId` itself or one of its descendants, so making `parentId`\n * the parent of `childId` would close a containment cycle.\n */\nexport const wouldCreateContainmentCycle = (\n childId: string,\n parentId: string,\n getParentId: (id: string) => string | undefined\n): boolean => {\n const visited = new Set<string>();\n let currentId: string | undefined = parentId;\n while (currentId !== undefined && !visited.has(currentId)) {\n if (currentId === childId) {\n return true;\n }\n visited.add(currentId);\n currentId = getParentId(currentId);\n }\n return false;\n};\n"], "mappings": ";;;;;AAIO,IAAM,8BAA8B,wBACzC,SACA,UACA,gBACY;AACZ,QAAM,UAAU,oBAAI,IAAY;AAChC,MAAI,YAAgC;AACpC,SAAO,cAAc,UAAa,CAAC,QAAQ,IAAI,SAAS,GAAG;AACzD,QAAI,cAAc,SAAS;AACzB,aAAO;AAAA,IACT;AACA,YAAQ,IAAI,SAAS;AACrB,gBAAY,YAAY,SAAS;AAAA,EACnC;AACA,SAAO;AACT,GAf2C;", "names": [] }