Skip to content

Commit fa0067c

Browse files
author
Ismael Taboada
committed
Comments at principal scripts
1 parent 3d67b58 commit fa0067c

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

huffman.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# -*- coding: utf-8 -*-
33

44
"""Python implementation of Huffman Coding
5-
65
"""
76
__author__ = 'Ismael Taboada'
87
__version__= '1.0'
@@ -12,7 +11,7 @@
1211

1312

1413
class HuffmanCoding(object):
15-
"""docstring for HuffmanCoding"""
14+
"""HuffmanCoding implementation"""
1615

1716
def __init__(self):
1817
super(HuffmanCoding, self).__init__()
@@ -32,7 +31,7 @@ def encode(self,symb2freq):
3231
self.tree = heap[0]
3332

3433
def tree_to_graph(self,tree=None,n="",comment="Huffman Coding",formatin="png",graph=None):
35-
"""Based on the Huffman Coding it create a graph with graphviz library
34+
"""Based on the Huffman Coding it creates a graph with graphviz library
3635
3736
:param comment: graph comment
3837
:param formatin: graph format

main.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
"""Python implementation of Huffman Coding
55
6-
This program implements the huffman coding used for encoding a group of symbols
7-
by a preface
6+
This script test the implementation software of Huffman Coding at \'main.py\'.
87
"""
98
__author__ = 'Ismael Taboada'
109
__version__= '1.0'
@@ -22,28 +21,41 @@
2221
LOG_FILE = 'log.csv'
2322
TEST = "this is an example for huffman encoding"
2423

24+
"""Test for Graphviz software
25+
"""
2526
try:
2627
dot = Digraph()
2728
except Exception as e:
2829
raise
2930
print "Error: Graphviz software not found.\nPlease install Graphviz software on your computer.(http://www.graphviz.org/Download.php)"
3031
exit(1)
3132

32-
33+
"""User input
34+
"""
3335
txtin = raw_input("Write some symbols(blank for sample case):")
3436
txtin = TEST if txtin=="" else txtin
3537
txtout = txtin
38+
39+
"""Extract frecuency of each symbol of set
40+
"""
3641
symb2freq = defaultdict(int)
3742
for ch in txtin:
3843
symb2freq[ch] += 1
3944

45+
"""Implementation of Huffman Algorithm
46+
"""
4047
start = time.time()
4148
huff = HuffmanCoding()
4249
huff.encode(symb2freq)
4350
end = time.time()
4451
time_lapse = end - start
52+
53+
"""Conversion from Huffman Coding Tree to Coding table
54+
"""
4555
coding_table = huff.tree_to_table()
4656

57+
"""Outputs
58+
"""
4759
print "Codes table"
4860
print "Symbol\tFrec\tCode"
4961
for coding in coding_table:
@@ -55,10 +67,15 @@
5567
print "\nText input:",txtin
5668
print "Text output:",txtout
5769

70+
"""Huffman tree Graphviz visualization
71+
"""
5872
dot = huff.tree_to_graph()
5973
print "\nDiagram saved at: ",DIA_FILE+'.png'
6074
dot.render(DIA_FILE, view=DEBUG)
6175

76+
77+
"""Log of input's size and execution time
78+
"""
6279
log_exits = os.path.isfile(LOG_FILE)
6380

6481
with open(LOG_FILE, 'ab') as csvfile:

0 commit comments

Comments
 (0)