huffman_conv2bitstring converts a string into its bitstring representation. It returns a tuple: the bitstring and its bitlength. This function DOES NOT compress/decompress the string! :param str s: the bytestring to convert. :return: (int, int): the bitstring of s,
(cls, s)
| 1130 | |
| 1131 | @classmethod |
| 1132 | def huffman_conv2bitstring(cls, s): |
| 1133 | # type: (str) -> Tuple[int, int] |
| 1134 | """ huffman_conv2bitstring converts a string into its bitstring |
| 1135 | representation. It returns a tuple: the bitstring and its bitlength. |
| 1136 | This function DOES NOT compress/decompress the string! |
| 1137 | |
| 1138 | :param str s: the bytestring to convert. |
| 1139 | :return: (int, int): the bitstring of s, and its bitlength. |
| 1140 | :raises: AssertionError |
| 1141 | """ |
| 1142 | i = 0 |
| 1143 | ibl = len(s) * 8 |
| 1144 | for c in s: |
| 1145 | i = (i << 8) + orb(c) |
| 1146 | |
| 1147 | ret = i, ibl |
| 1148 | assert ret[0] >= 0 |
| 1149 | assert ret[1] >= 0 |
| 1150 | return ret |
| 1151 | |
| 1152 | @classmethod |
| 1153 | def huffman_compute_decode_tree(cls): |