MCPcopy Create free account
hub / github.com/arktypeio/arktype / componentOf

Method componentOf

ark/aot/precompile.ts:3772–3812  ·  view source on GitHub ↗
(root: string)

Source from the content-addressed store, hash-verified

3770
3771 // Tarjan's algorithm, iteratively
3772 private componentOf(root: string): number {
3773 const components = this.componentsById
3774 if (root in components) return components[root]
3775 // past every component found so far
3776 let found = Object.keys(components).length
3777 let visited = 0
3778 const indices: Record<string, number> = Object.create(null)
3779 const lows: Record<string, number> = Object.create(null)
3780 const stack: string[] = []
3781 const frames: [id: string, targets: string[]][] = []
3782 const visit = (id: string) => {
3783 indices[id] = lows[id] = visited++
3784 stack.push(id)
3785 frames.push([
3786 id,
3787 this.textImportsOf(this.graph.host.readFile(id) ?? "", id)
3788 ])
3789 }
3790 visit(root)
3791 while (frames.length) {
3792 const [id, targets] = frames[frames.length - 1]
3793 const target = targets.pop()
3794 if (target !== undefined) {
3795 if (target in components) continue
3796 if (target in indices) lows[id] = Math.min(lows[id], indices[target])
3797 else visit(target)
3798 continue
3799 }
3800 frames.pop()
3801 if (frames.length) {
3802 const parent = frames[frames.length - 1][0]
3803 lows[parent] = Math.min(lows[parent], lows[id])
3804 }
3805 if (lows[id] !== indices[id]) continue
3806 let member: string
3807 do components[(member = stack.pop()!)] = found
3808 while (member !== id)
3809 found++
3810 }
3811 return components[root]
3812 }
3813
3814 private definesArk(binding: Binding, module: SourceModule): boolean {
3815 return this.graph.definesArk({

Callers 1

isReachedEarlyMethod · 0.95

Calls 2

popMethod · 0.80
visitFunction · 0.70

Tested by

no test coverage detected