Huffan Algo: count_frequencies func

This commit is contained in:
helldh 2026-01-13 20:07:53 +03:00
commit c1ca54db6b
8 changed files with 59 additions and 0 deletions

22
huffman.py Normal file
View file

@ -0,0 +1,22 @@
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: Реализовать логику дерева хаффмана, пока что остановимся на этом