22 lines
No EOL
573 B
Python
22 lines
No EOL
573 B
Python
import heapq as hq
|
|
from typing import BinaryIO, Dict
|
|
from collections import Counter
|
|
|
|
def count_frequencies(fd: BinaryIO) -> Dict[int, int]:
|
|
entropy = list()
|
|
|
|
content = fd.read()
|
|
|
|
for byte in content:
|
|
entropy.append(byte)
|
|
|
|
byte_counter = Counter(entropy)
|
|
|
|
return dict(byte_counter)
|
|
|
|
def make_tree(frequencies_table: Dict[int, int]):
|
|
ft = frequencies_table # short alias
|
|
|
|
huffman_tree = hq.heapify(list())
|
|
|
|
# TODO: Реализовать логику дерева хаффмана, пока что остановимся на этом |