[mypy] annotate compression (#5570)

This commit is contained in:
Erwin Junge
2021-10-26 12:29:27 +02:00
committed by GitHub
parent de07245c17
commit e49d8e3af4
4 changed files with 40 additions and 28 deletions

View File

@ -12,6 +12,13 @@ of text compression algorithms, costing only some extra computation.
"""
from __future__ import annotations
from typing import TypedDict
class BWTTransformDict(TypedDict):
bwt_string: str
idx_original_string: int
def all_rotations(s: str) -> list[str]:
"""
@ -43,7 +50,7 @@ def all_rotations(s: str) -> list[str]:
return [s[i:] + s[:i] for i in range(len(s))]
def bwt_transform(s: str) -> dict:
def bwt_transform(s: str) -> BWTTransformDict:
"""
:param s: The string that will be used at bwt algorithm
:return: the string composed of the last char of each row of the ordered
@ -75,10 +82,11 @@ def bwt_transform(s: str) -> dict:
rotations = all_rotations(s)
rotations.sort() # sort the list of rotations in alphabetically order
# make a string composed of the last char of each rotation
return {
response: BWTTransformDict = {
"bwt_string": "".join([word[-1] for word in rotations]),
"idx_original_string": rotations.index(s),
}
return response
def reverse_bwt(bwt_string: str, idx_original_string: int) -> str: