Skip to content

Commit

Permalink
Fix issue with TrieNode when value is ending with same string.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 27, 2018
1 parent ba0b0b6 commit efd938b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions spec/drupol/phptree/Node/TrieNodeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public function it_can_add_node()
$this->beConstructedWith('root', 'root');

$nodes = [
1000,
1001,
10011,
2000,
2001,
20011,
'ab',
'abc',
'abcd',
Expand All @@ -31,12 +37,12 @@ public function it_can_add_node()
];

foreach ($nodes as $key => $value) {
$nodes[$key] = new KeyValueNode($key, $value);
$nodes[$key] = new KeyValueNode($key, (string) $value);
}

$this
->add(...$nodes)
->count()
->shouldReturn(25);
->shouldReturn(43);
}
}
2 changes: 1 addition & 1 deletion src/Node/TrieNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function add(NodeInterface ...$nodes): NodeInterface
$parent = $this->append($node);

$dataWithoutFirstLetter = \substr($data, 1);
if (!empty($dataWithoutFirstLetter)) {
if ($dataWithoutFirstLetter > '') {
$parent->add(new TrieNode($hash, $dataWithoutFirstLetter));
} else {
$nodes = [$node->getValue()];
Expand Down

0 comments on commit efd938b

Please sign in to comment.