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

Function _isMutuallySimulated

ark/schema/node.ts:1851–1889  ·  view source on GitHub ↗
(
	l: BaseNode,
	r: BaseNode,
	how: Pick<SimulationState, "unfoldsAliases" | "subsumes">
)

Source from the content-addressed store, hash-verified

1849 _isMutuallySimulated(l, r, { unfoldsAliases: true, subsumes: true }))
1850
1851const _isMutuallySimulated = (
1852 l: BaseNode,
1853 r: BaseNode,
1854 how: Pick<SimulationState, "unfoldsAliases" | "subsumes">
1855): boolean => {
1856 const s: SimulationState = {
1857 pairs: {},
1858 pending: [],
1859 failed: {},
1860 comparing: "",
1861 ...how
1862 }
1863 const simulates = () => isSimulated(l, r, s) && isSimulated(r, l, s)
1864 if (!simulates()) return false
1865 // a pair whose unfoldings aren't related fails each comparison that assumed it
1866 while (s.pending.length) {
1867 const pair = s.pending.pop()!
1868 if (s.failed[pair]) continue
1869 const compared = s.pairs[pair]
1870 s.comparing = pair
1871 const l = compared.l.is("alias") ? compared.l.resolution : compared.l
1872 const r = compared.r.is("alias") ? compared.r.resolution : compared.r
1873 if (
1874 compared.relation === "within" ?
1875 isWithin(l as BaseRoot, r as BaseRoot, s)
1876 : isSimulated(l, r, s)
1877 )
1878 continue
1879 s.failed[pair] = true
1880 for (const comparison in compared.assumedBy) {
1881 if (comparison) s.pending.push(comparison)
1882 else {
1883 s.comparing = comparison
1884 if (!simulates()) return false
1885 }
1886 }
1887 }
1888 return true
1889}
1890
1891// a description written over a keyword's phrase drops the keyword's identity
1892const withoutReplacedKeyword = (

Callers 2

trackedIdFunction · 0.85
isMutuallySimulatedFunction · 0.85

Calls 6

simulatesFunction · 0.85
isSimulatedFunction · 0.85
popMethod · 0.80
isMethod · 0.80
isWithinFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected