data = []; } /** * @param string $a * @param string $b * @param bool $areMutuallyExclusive * * @return bool */ public function has($a, $b, $areMutuallyExclusive) { $first = $this->data[$a] ?? null; $result = $first && isset($first[$b]) ? $first[$b] : null; if ($result === null) { return false; } // areMutuallyExclusive being false is a superset of being true, // hence if we want to know if this PairSet "has" these two with no // exclusivity, we have to ensure it was added as such. if ($areMutuallyExclusive === false) { return $result === false; } return true; } /** * @param string $a * @param string $b * @param bool $areMutuallyExclusive */ public function add($a, $b, $areMutuallyExclusive) { $this->pairSetAdd($a, $b, $areMutuallyExclusive); $this->pairSetAdd($b, $a, $areMutuallyExclusive); } /** * @param string $a * @param string $b * @param bool $areMutuallyExclusive */ private function pairSetAdd($a, $b, $areMutuallyExclusive) { $this->data[$a] = $this->data[$a] ?? []; $this->data[$a][$b] = $areMutuallyExclusive; } }