Adds new strings (curr_string + "0", curr_string + "1") to the lexicon
(
lexicon: dict[str, str], curr_string: str, index: int, last_match_id: str
)
| 26 | |
| 27 | |
| 28 | def add_key_to_lexicon( |
| 29 | lexicon: dict[str, str], curr_string: str, index: int, last_match_id: str |
| 30 | ) -> None: |
| 31 | """ |
| 32 | Adds new strings (curr_string + "0", curr_string + "1") to the lexicon |
| 33 | """ |
| 34 | lexicon.pop(curr_string) |
| 35 | lexicon[curr_string + "0"] = last_match_id |
| 36 | |
| 37 | if math.log2(index).is_integer(): |
| 38 | for curr_key, value in lexicon.items(): |
| 39 | lexicon[curr_key] = f"0{value}" |
| 40 | |
| 41 | lexicon[curr_string + "1"] = bin(index)[2:] |
| 42 | |
| 43 | |
| 44 | def compress_data(data_bits: str) -> str: |