@@ -10,31 +10,31 @@ discard block |
||
10 | 10 | class ShortestCommonSuperstring |
11 | 11 | { |
12 | 12 | /** |
13 | - * @var integer Affix length for current iteration |
|
14 | - */ |
|
13 | + * @var integer Affix length for current iteration |
|
14 | + */ |
|
15 | 15 | protected $len; |
16 | 16 | |
17 | 17 | /** |
18 | - * @var string[] Prefixes of current length |
|
19 | - */ |
|
18 | + * @var string[] Prefixes of current length |
|
19 | + */ |
|
20 | 20 | protected $prefixes; |
21 | 21 | |
22 | 22 | /** |
23 | - * @var string[] Strings being merged |
|
24 | - */ |
|
23 | + * @var string[] Strings being merged |
|
24 | + */ |
|
25 | 25 | protected $strings; |
26 | 26 | |
27 | 27 | /** |
28 | - * @var string[] Suffixes of current length |
|
29 | - */ |
|
28 | + * @var string[] Suffixes of current length |
|
29 | + */ |
|
30 | 30 | protected $suffixes; |
31 | 31 | |
32 | 32 | /** |
33 | - * Get the shortest string that contains all given strings |
|
34 | - * |
|
35 | - * @param string[] $strings |
|
36 | - * @return string |
|
37 | - */ |
|
33 | + * Get the shortest string that contains all given strings |
|
34 | + * |
|
35 | + * @param string[] $strings |
|
36 | + * @return string |
|
37 | + */ |
|
38 | 38 | public function getShortest(array $strings) |
39 | 39 | { |
40 | 40 | $this->strings = array_unique($strings); |
@@ -54,12 +54,12 @@ discard block |
||
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | - * Compare strings |
|
58 | - * |
|
59 | - * @param string $a |
|
60 | - * @param string $b |
|
61 | - * @return integer |
|
62 | - */ |
|
57 | + * Compare strings |
|
58 | + * |
|
59 | + * @param string $a |
|
60 | + * @param string $b |
|
61 | + * @return integer |
|
62 | + */ |
|
63 | 63 | protected static function compareStrings($a, $b) |
64 | 64 | { |
65 | 65 | $aLen = strlen($a); |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | - * Return the list of keys pointing to strings whose prefix is identical to their suffix |
|
79 | - * |
|
80 | - * @return integer[] |
|
81 | - */ |
|
78 | + * Return the list of keys pointing to strings whose prefix is identical to their suffix |
|
79 | + * |
|
80 | + * @return integer[] |
|
81 | + */ |
|
82 | 82 | protected function getIdenticalAffixKeys() |
83 | 83 | { |
84 | 84 | $identicalAffixKeys = []; |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | - * Match and merge a string by key |
|
98 | - * |
|
99 | - * @param integer $leftKey Left string's key |
|
100 | - * @return bool Whether a match was found and strings merged |
|
101 | - */ |
|
97 | + * Match and merge a string by key |
|
98 | + * |
|
99 | + * @param integer $leftKey Left string's key |
|
100 | + * @return bool Whether a match was found and strings merged |
|
101 | + */ |
|
102 | 102 | protected function mergeString($leftKey) |
103 | 103 | { |
104 | 104 | $suffix = $this->suffixes[$leftKey]; |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
119 | - * Merge two stored strings together at current affix length |
|
120 | - * |
|
121 | - * @param integer $leftKey Left string's key |
|
122 | - * @param integer $rightKey Right string's key |
|
123 | - * @return void |
|
124 | - */ |
|
119 | + * Merge two stored strings together at current affix length |
|
120 | + * |
|
121 | + * @param integer $leftKey Left string's key |
|
122 | + * @param integer $rightKey Right string's key |
|
123 | + * @return void |
|
124 | + */ |
|
125 | 125 | protected function mergeStringPair($leftKey, $rightKey) |
126 | 126 | { |
127 | 127 | $this->strings[$leftKey] .= substr($this->strings[$rightKey], $this->len); |
@@ -130,10 +130,10 @@ discard block |
||
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | - * Merge all stored strings using current affix length |
|
134 | - * |
|
135 | - * @return void |
|
136 | - */ |
|
133 | + * Merge all stored strings using current affix length |
|
134 | + * |
|
135 | + * @return void |
|
136 | + */ |
|
137 | 137 | protected function mergeStrings() |
138 | 138 | { |
139 | 139 | $this->storeAffixes(); |
@@ -150,11 +150,11 @@ discard block |
||
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
153 | - * Match and merge strings from given group |
|
154 | - * |
|
155 | - * @param integer[] $keys List of keys |
|
156 | - * @return void |
|
157 | - */ |
|
153 | + * Match and merge strings from given group |
|
154 | + * |
|
155 | + * @param integer[] $keys List of keys |
|
156 | + * @return void |
|
157 | + */ |
|
158 | 158 | protected function mergeStringsGroup(array $keys) |
159 | 159 | { |
160 | 160 | foreach ($keys as $leftKey) |
@@ -170,10 +170,10 @@ discard block |
||
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | - * Remove empty strings from the list |
|
174 | - * |
|
175 | - * @return void |
|
176 | - */ |
|
173 | + * Remove empty strings from the list |
|
174 | + * |
|
175 | + * @return void |
|
176 | + */ |
|
177 | 177 | protected function removeEmptyStrings() |
178 | 178 | { |
179 | 179 | if (end($this->strings) === '') |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | - * Remove fully-overlapping strings from the list |
|
187 | - * |
|
188 | - * @return void |
|
189 | - */ |
|
186 | + * Remove fully-overlapping strings from the list |
|
187 | + * |
|
188 | + * @return void |
|
189 | + */ |
|
190 | 190 | protected function removeFullyOverlappingStrings() |
191 | 191 | { |
192 | 192 | $i = count($this->strings); |
@@ -207,10 +207,10 @@ discard block |
||
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
210 | - * Reset the keys in the string list to remove the gaps |
|
211 | - * |
|
212 | - * @return void |
|
213 | - */ |
|
210 | + * Reset the keys in the string list to remove the gaps |
|
211 | + * |
|
212 | + * @return void |
|
213 | + */ |
|
214 | 214 | protected function resetKeys() |
215 | 215 | { |
216 | 216 | end($this->strings); |
@@ -221,22 +221,22 @@ discard block |
||
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | - * Sort the stored strings |
|
225 | - * |
|
226 | - * @return void |
|
227 | - */ |
|
224 | + * Sort the stored strings |
|
225 | + * |
|
226 | + * @return void |
|
227 | + */ |
|
228 | 228 | protected function sortStrings() |
229 | 229 | { |
230 | 230 | usort($this->strings, [__CLASS__, 'compareStrings']); |
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
234 | - * Capture and stored affixes of current length |
|
235 | - * |
|
236 | - * Will only store affixes from strings that are longer than current affix length |
|
237 | - * |
|
238 | - * @return void |
|
239 | - */ |
|
234 | + * Capture and stored affixes of current length |
|
235 | + * |
|
236 | + * Will only store affixes from strings that are longer than current affix length |
|
237 | + * |
|
238 | + * @return void |
|
239 | + */ |
|
240 | 240 | protected function storeAffixes() |
241 | 241 | { |
242 | 242 | $this->prefixes = []; |