Class: SuffixArray
- Inherits:
-
Array
- Object
- Array
- SuffixArray
- Defined in:
- lib/adlint/prelude.rb
Instance Method Summary collapse
-
#initialize(suffixes) ⇒ SuffixArray
constructor
A new instance of SuffixArray.
- #longest_common_prefix_length ⇒ Object
- #longest_common_substrings ⇒ Object
Constructor Details
#initialize(suffixes) ⇒ SuffixArray
Returns a new instance of SuffixArray.
269 270 271 272 |
# File 'lib/adlint/prelude.rb', line 269 def initialize(suffixes) super(suffixes.sort.map { |suffix| [suffix, 0] }) update_height_of_each_suffixes! end |
Instance Method Details
#longest_common_prefix_length ⇒ Object
284 285 286 |
# File 'lib/adlint/prelude.rb', line 284 def longest_common_prefix_length self.map { |suffix, height| height }.max end |
#longest_common_substrings ⇒ Object
274 275 276 277 278 279 280 281 282 |
# File 'lib/adlint/prelude.rb', line 274 def longest_common_substrings len = self.longest_common_prefix_length return [] if len == 0 self.each_index.reduce([]) { |result, idx| self[idx][1] == len ? result + create_substring_pairs(idx, len) : result } end |