1 | <?php |
||
23 | class TrieTree implements Countable { |
||
24 | private $root; |
||
25 | private $numWords; |
||
26 | private $size; |
||
27 | |||
28 | public function __construct() { |
||
33 | |||
34 | /** |
||
35 | * Returns the number of words stored in the trie. |
||
36 | * |
||
37 | * @return int the number of words. |
||
38 | */ |
||
39 | public function numWords() : int { |
||
42 | |||
43 | /** |
||
44 | * Returns true if the tree is empty. Number of prefixes is 0. |
||
45 | * |
||
46 | * @return bool true if empty. |
||
47 | */ |
||
48 | public function empty() : bool { |
||
51 | |||
52 | /** |
||
53 | * Returns the number of prefixes that are contained in the trie. |
||
54 | * |
||
55 | * @return int the num of prefixes. |
||
56 | */ |
||
57 | public function size() : int { |
||
60 | |||
61 | /** |
||
62 | * Inserts a new word in the tree. If the word exists it doesn't do nothing. |
||
63 | * |
||
64 | * @param string $word the word to be added. |
||
65 | */ |
||
66 | public function add($word) { |
||
96 | |||
97 | /** |
||
98 | * Returns true if the word is stored in the tree. |
||
99 | * |
||
100 | * @param string $word The word to check if exists. |
||
101 | * @param bool true if is contained. |
||
102 | */ |
||
103 | public function contains($word) : bool { |
||
129 | |||
130 | public function getWords() : array { |
||
133 | |||
134 | /** |
||
135 | * |
||
136 | */ |
||
137 | public function startsWith($prefix) : bool { |
||
140 | |||
141 | /** |
||
142 | * Retrieve the node where ends the prefix especified. |
||
143 | * |
||
144 | * @param string $prefix The prefix to look for. |
||
145 | * @return DataStructures\Trees\Nodes\TrieNode|null null if not found. |
||
146 | */ |
||
147 | private function getNodeFromPrefix($prefix) { |
||
166 | |||
167 | /** |
||
168 | * Gets the number of words stored in the tree. |
||
169 | * |
||
170 | * @return int The word count. |
||
171 | */ |
||
172 | public function wordCount() : int { |
||
175 | |||
176 | /** |
||
177 | * Gets the number of prefixes stored in the tree. |
||
178 | * |
||
179 | * @return int The word count. |
||
180 | */ |
||
181 | public function count() : int { |
||
184 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.