Calculate the longest possible match of text and window characters from text_index in text and window_index in window. Args: text: _description_ window: sliding window text_index: index of character in text window_index: index of chara
(
self, text: str, window: str, text_index: int, window_index: int
)
| 181 | return Token(offset, length, text[length]) |
| 182 | |
| 183 | def _match_length_from_index( |
| 184 | self, text: str, window: str, text_index: int, window_index: int |
| 185 | ) -> int: |
| 186 | """Calculate the longest possible match of text and window characters from |
| 187 | text_index in text and window_index in window. |
| 188 | |
| 189 | Args: |
| 190 | text: _description_ |
| 191 | window: sliding window |
| 192 | text_index: index of character in text |
| 193 | window_index: index of character in sliding window |
| 194 | |
| 195 | Returns: |
| 196 | The maximum match between text and window, from given indexes. |
| 197 | |
| 198 | Tests: |
| 199 | >>> lz77_compressor = LZ77Compressor(13, 6) |
| 200 | >>> lz77_compressor._match_length_from_index("rarrad", "adabrar", 0, 4) |
| 201 | 5 |
| 202 | >>> lz77_compressor._match_length_from_index("adabrarrarrad", |
| 203 | ... "cabrac", 0, 1) |
| 204 | 1 |
| 205 | """ |
| 206 | if not text or text[text_index] != window[window_index]: |
| 207 | return 0 |
| 208 | return 1 + self._match_length_from_index( |
| 209 | text, window + text[text_index], text_index + 1, window_index + 1 |
| 210 | ) |
| 211 | |
| 212 | |
| 213 | if __name__ == "__main__": |
no outgoing calls
no test coverage detected