Huffan Algo: count_frequencies func
This commit is contained in:
commit
c1ca54db6b
8 changed files with 59 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
bigfile.pdf
|
||||||
|
.venv
|
||||||
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
10
.idea/huffman.iml
generated
Normal file
10
.idea/huffman.iml
generated
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.13 (huffman)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.13 (huffman)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (huffman)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/huffman.iml" filepath="$PROJECT_DIR$/.idea/huffman.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
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: Реализовать логику дерева хаффмана, пока что остановимся на этом
|
||||||
1
main.py
Normal file
1
main.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
# заглушка
|
||||||
Loading…
Add table
Add a link
Reference in a new issue