@@ -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): string |
39 | 39 | { |
40 | 40 | $this->strings = array_unique($strings); |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | - * Compare given strings |
|
60 | - */ |
|
59 | + * Compare given strings |
|
60 | + */ |
|
61 | 61 | protected static function compareStrings(string $a, string $b): int |
62 | 62 | { |
63 | 63 | $aLen = strlen($a); |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | - * Match and merge a string by key |
|
77 | - * |
|
78 | - * @param integer $leftKey Left string's key |
|
79 | - * @return bool Whether a match was found and strings merged |
|
80 | - */ |
|
76 | + * Match and merge a string by key |
|
77 | + * |
|
78 | + * @param integer $leftKey Left string's key |
|
79 | + * @return bool Whether a match was found and strings merged |
|
80 | + */ |
|
81 | 81 | protected function mergeString(int $leftKey): bool |
82 | 82 | { |
83 | 83 | // Temporarily remove this string's prefix from the array to avoid matches |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | - * Merge two stored strings together at current affix length |
|
109 | - */ |
|
108 | + * Merge two stored strings together at current affix length |
|
109 | + */ |
|
110 | 110 | protected function mergeStringPair(int $leftKey, int $rightKey): void |
111 | 111 | { |
112 | 112 | $this->strings[$leftKey] .= substr($this->strings[$rightKey], $this->len); |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
125 | - * Merge all stored strings using current affix length |
|
126 | - */ |
|
125 | + * Merge all stored strings using current affix length |
|
126 | + */ |
|
127 | 127 | protected function mergeStrings(): void |
128 | 128 | { |
129 | 129 | $this->storeMatchingAffixes(); |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
143 | - * Match and merge strings from given group |
|
144 | - * |
|
145 | - * @param integer[] $keys List of keys |
|
146 | - * @return void |
|
147 | - */ |
|
143 | + * Match and merge strings from given group |
|
144 | + * |
|
145 | + * @param integer[] $keys List of keys |
|
146 | + * @return void |
|
147 | + */ |
|
148 | 148 | protected function mergeStringsGroup(array $keys): void |
149 | 149 | { |
150 | 150 | foreach ($keys as $leftKey) |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | - * Remove empty strings from the list |
|
161 | - */ |
|
160 | + * Remove empty strings from the list |
|
161 | + */ |
|
162 | 162 | protected function removeEmptyStrings(): void |
163 | 163 | { |
164 | 164 | if (end($this->strings) === '') |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
171 | - * Remove fully-overlapping strings from the list |
|
172 | - */ |
|
171 | + * Remove fully-overlapping strings from the list |
|
172 | + */ |
|
173 | 173 | protected function removeFullyOverlappingStrings(): void |
174 | 174 | { |
175 | 175 | // Copy the list of strings ordered by ascending length and create a master string by |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
205 | - * Reset the keys in the string list to remove the gaps |
|
206 | - */ |
|
205 | + * Reset the keys in the string list to remove the gaps |
|
206 | + */ |
|
207 | 207 | protected function resetKeys(): void |
208 | 208 | { |
209 | 209 | end($this->strings); |
@@ -214,19 +214,19 @@ discard block |
||
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
217 | - * Sort the stored strings |
|
218 | - */ |
|
217 | + * Sort the stored strings |
|
218 | + */ |
|
219 | 219 | protected function sortStrings(): void |
220 | 220 | { |
221 | 221 | usort($this->strings, [__CLASS__, 'compareStrings']); |
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
225 | - * Capture and store matching affixes of current length |
|
226 | - * |
|
227 | - * Will only store affixes from strings that are longer than current affix length and that have |
|
228 | - * a match on the other end of a string |
|
229 | - */ |
|
225 | + * Capture and store matching affixes of current length |
|
226 | + * |
|
227 | + * Will only store affixes from strings that are longer than current affix length and that have |
|
228 | + * a match on the other end of a string |
|
229 | + */ |
|
230 | 230 | protected function storeMatchingAffixes(): void |
231 | 231 | { |
232 | 232 | $this->prefixes = []; |
@@ -113,8 +113,7 @@ |
||
113 | 113 | if (isset($this->suffixes[$rightKey])) |
114 | 114 | { |
115 | 115 | $this->suffixes[$leftKey] = $this->suffixes[$rightKey]; |
116 | - } |
|
117 | - else |
|
116 | + } else |
|
118 | 117 | { |
119 | 118 | unset($this->suffixes[$leftKey]); |
120 | 119 | } |