| Conditions | 5 |
| Paths | 5 |
| Total Lines | 19 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 41 | public function add($word) { |
||
| 42 | $word = trim($word); |
||
| 43 | if(mb_strlen($word) === 0) { |
||
| 44 | return; |
||
| 45 | } |
||
| 46 | |||
| 47 | $current = &$this->root; |
||
| 48 | for($i = 0; $i < mb_strlen($word); $i++) { |
||
| 49 | $char = mb_substr($word, $i, 1, 'UTF-8'); |
||
| 50 | if(!isset($current->children[$char])) { |
||
| 51 | if($i === mb_strlen($word) - 1) { |
||
| 52 | $current->children[$char] = new TrieNode($char, true); |
||
| 53 | } else { |
||
| 54 | $current->children[$char] = new TrieNode($char, false); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | $current = &$current->children[$char]; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 64 | } |