huffman_encode_char assumes that the static_huffman_tree was previously initialized :param str|EOS c: a symbol to encode :return: (int, int): the bitstring of the symbol and its bitlength :raises: AssertionError
(cls, c)
| 999 | |
| 1000 | @classmethod |
| 1001 | def _huffman_encode_char(cls, c): |
| 1002 | # type: (Union[str, EOS]) -> Tuple[int, int] |
| 1003 | """ huffman_encode_char assumes that the static_huffman_tree was |
| 1004 | previously initialized |
| 1005 | |
| 1006 | :param str|EOS c: a symbol to encode |
| 1007 | :return: (int, int): the bitstring of the symbol and its bitlength |
| 1008 | :raises: AssertionError |
| 1009 | """ |
| 1010 | if isinstance(c, EOS): |
| 1011 | return cls.static_huffman_code[-1] |
| 1012 | else: |
| 1013 | assert isinstance(c, int) or len(c) == 1 |
| 1014 | return cls.static_huffman_code[orb(c)] |
| 1015 | |
| 1016 | @classmethod |
| 1017 | def huffman_encode(cls, s): |