diff --git a/CHANGELOG.md b/CHANGELOG.md index 7534f2e..7d5b273 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip ### Removed - Possibility to get code map for root of character tree. +- `CharTree::getBranchesAfterRoot`. Use character treee cutter instead. ### Security - Nothing diff --git a/src/CharTree.php b/src/CharTree.php index 16fea21..f73f682 100644 --- a/src/CharTree.php +++ b/src/CharTree.php @@ -196,34 +196,6 @@ public function getBranches(): array return $this->branches; } - /** - * @param string $root Root that comes before the brances. - * @return self Character tree containing the branches of this character tree that come after $root. - */ - public function getBranchesAfterRoot(string $root): self - { - if ($this->root === null || $root === '') { - return $this; - } - - if ($this->root === $root) { - return self::fromString('', $this->branches); - } - - if ($this->root !== mb_substr($root, 0, mb_strlen($this->root))) { - return self::fromNothing(); - } - - $rootTail = mb_substr($root, mb_strlen($this->root)); - $rootHead = mb_substr($rootTail, 0, 1); - - if (!isset($this->branches[$rootHead])) { - return self::fromNothing(); - } - - return $this->branches[$rootHead]->getBranchesAfterRoot($rootTail); - } - /** * @param string $string String to check. * @return bool Whether the character tree contains the string. diff --git a/tests/CharTreeTest.php b/tests/CharTreeTest.php index 8cc03e9..652e9eb 100644 --- a/tests/CharTreeTest.php +++ b/tests/CharTreeTest.php @@ -233,147 +233,6 @@ public function testCanGetBranches(): void ], $charTree->getBranches(), '', 0, 10, true); } - /** - * @covers ::getBranchesAfterRoot - */ - public function testCanGetBranchesAfterEmptyRoot(): void - { - $charTree = CharTree::fromArray([ - CharTree::fromString('a'), - CharTree::fromString('ab'), - CharTree::fromString('abc'), - CharTree::fromString('acd'), - CharTree::fromString('foobar'), - CharTree::fromString('k'), - ]); - - self::assertSame(CharTree::fromArray([ - CharTree::fromString('a'), - CharTree::fromString('ab'), - CharTree::fromString('abc'), - CharTree::fromString('acd'), - CharTree::fromString('foobar'), - CharTree::fromString('k'), - ]), $charTree->getBranchesAfterRoot('')); - } - - /** - * @covers ::getBranchesAfterRoot - */ - public function testCanGetBranchesAfterRootOfSingleCharacter(): void - { - $charTree = CharTree::fromArray([ - CharTree::fromString('a'), - CharTree::fromString('ab'), - CharTree::fromString('abc'), - CharTree::fromString('acd'), - CharTree::fromString('foobar'), - CharTree::fromString('k'), - ]); - - self::assertSame(CharTree::fromArray([ - CharTree::fromString(''), - CharTree::fromString('b'), - CharTree::fromString('bc'), - CharTree::fromString('cd'), - ]), $charTree->getBranchesAfterRoot('a')); - } - - /** - * @covers ::getBranchesAfterRoot - */ - public function testCanGetBranchesAfterRootOfMultipleCharacters(): void - { - $charTree = CharTree::fromArray([ - CharTree::fromString('a'), - CharTree::fromString('ab'), - CharTree::fromString('abc'), - CharTree::fromString('acd'), - CharTree::fromString('foobar'), - CharTree::fromString('k'), - ]); - - self::assertSame(CharTree::fromArray([ - CharTree::fromString(''), - CharTree::fromString('c'), - ]), $charTree->getBranchesAfterRoot('ab')); - } - - /** - * @covers ::getBranchesAfterRoot - */ - public function testCanGetBranchesAfterRootMatchingFullString(): void - { - $charTree = CharTree::fromArray([ - CharTree::fromString('a'), - CharTree::fromString('ab'), - CharTree::fromString('abc'), - CharTree::fromString('acd'), - CharTree::fromString('foo'), - CharTree::fromString('foobar'), - CharTree::fromString('k'), - ]); - - self::assertSame(CharTree::fromArray([ - CharTree::fromString(''), - CharTree::fromString('bar'), - ]), $charTree->getBranchesAfterRoot('foo')); - } - - /** - * @covers ::getBranchesAfterRoot - */ - public function testCanGetBranchesAfterRootOfSingleCharacterThatDoesNotExist(): void - { - $charTree = CharTree::fromArray([ - CharTree::fromString('a'), - CharTree::fromString('ab'), - CharTree::fromString('abc'), - CharTree::fromString('acd'), - ]); - - self::assertSame(CharTree::fromArray([ - ]), $charTree->getBranchesAfterRoot('f')); - } - - /** - * @covers ::getBranchesAfterRoot - */ - public function testCanGetBranchesAfterRootOfMultipleCharactersThatDoesNotExist(): void - { - $charTree = CharTree::fromArray([ - CharTree::fromString('a'), - CharTree::fromString('ab'), - CharTree::fromString('abc'), - CharTree::fromString('acd'), - CharTree::fromString('foobar'), - CharTree::fromString('k'), - ]); - - self::assertSame(CharTree::fromArray([ - ]), $charTree->getBranchesAfterRoot('fu')); - } - - /** - * @covers ::getBranchesAfterRoot - */ - public function testCanGetBranchesAfterEmptyRootWhenTreeIsEmpty(): void - { - $charTree = CharTree::fromNothing(); - - self::assertSame(CharTree::fromNothing(), $charTree->getBranchesAfterRoot('')); - } - - /** - * @covers ::getBranchesAfterRoot - */ - public function testCanGetBranchesAfterEmptyRootWhenTreeIsEmptyString(): void - { - $charTree = CharTree::fromString(''); - - self::assertSame(CharTree::fromString(''), $charTree->getBranchesAfterRoot('')); - } - /** * @covers ::contains */