Huffan Algo: count_frequencies func
This commit is contained in:
commit
c1ca54db6b
8 changed files with 59 additions and 0 deletions
22
huffman.py
Normal file
22
huffman.py
Normal 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: Реализовать логику дерева хаффмана, пока что остановимся на этом
|
||||
Loading…
Add table
Add a link
Reference in a new issue