diff --git a/src/StateSet/InMemoryStateSet.php b/src/StateSet/InMemoryStateSet.php index 2eb4392..d8ace4e 100644 --- a/src/StateSet/InMemoryStateSet.php +++ b/src/StateSet/InMemoryStateSet.php @@ -6,11 +6,17 @@ class InMemoryStateSet implements StateSetInterface { /** * Key: State - * Value: Children - * @var array + * Value: array + * + * @var array> */ private array $states = []; + /** + * @var array> + */ + private array $children = []; + /** * Key: State * Value: Mapped char @@ -27,20 +33,25 @@ class InMemoryStateSet implements StateSetInterface public function add(int $state, int $parentState, int $mappedChar): self { + $this->states[$state] = [$parentState, $mappedChar]; $this->mappedChars[$state] = $mappedChar; - - if (! isset($this->states[$parentState])) { - $this->states[$parentState] = []; - } - - $this->states[$parentState][] = $state; + $this->children[$parentState][$state] = true; return $this; } + public function all(): array + { + return $this->states; + } + public function getChildrenOfState(int $state): array { - return $this->states[$state] ?? []; + if (!isset($this->children[$state])) { + return []; + } + + return array_keys($this->children[$state]); } public function getCharForState(int $state): int