@@ -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 | $strlen = array_map('strlen', $this->strings); |
@@ -213,10 +213,10 @@ discard block |
||
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
| 216 | - * Reset the keys in the string list to remove the gaps |
|
| 217 | - * |
|
| 218 | - * @return void |
|
| 219 | - */ |
|
| 216 | + * Reset the keys in the string list to remove the gaps |
|
| 217 | + * |
|
| 218 | + * @return void |
|
| 219 | + */ |
|
| 220 | 220 | protected function resetKeys() |
| 221 | 221 | { |
| 222 | 222 | end($this->strings); |
@@ -227,22 +227,22 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
| 230 | - * Sort the stored strings |
|
| 231 | - * |
|
| 232 | - * @return void |
|
| 233 | - */ |
|
| 230 | + * Sort the stored strings |
|
| 231 | + * |
|
| 232 | + * @return void |
|
| 233 | + */ |
|
| 234 | 234 | protected function sortStrings() |
| 235 | 235 | { |
| 236 | 236 | usort($this->strings, [__CLASS__, 'compareStrings']); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
| 240 | - * Capture and stored affixes of current length |
|
| 241 | - * |
|
| 242 | - * Will only store affixes from strings that are longer than current affix length |
|
| 243 | - * |
|
| 244 | - * @return void |
|
| 245 | - */ |
|
| 240 | + * Capture and stored affixes of current length |
|
| 241 | + * |
|
| 242 | + * Will only store affixes from strings that are longer than current affix length |
|
| 243 | + * |
|
| 244 | + * @return void |
|
| 245 | + */ |
|
| 246 | 246 | protected function storeAffixes() |
| 247 | 247 | { |
| 248 | 248 | $this->prefixes = []; |