Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
ee4fc09
added "run on repl.it" badge
kgashok Jan 1, 2020
b3e54f9
removed unnecessary files
kgashok Jan 1, 2020
7011eee
heapq used as max heap
kgashok Jan 1, 2020
abd9a9d
added pytest
kgashok Jan 1, 2020
671005f
added new test cases
kgashok Jan 1, 2020
6c61e39
added back .gitignore file
kgashok Jan 1, 2020
f5a7df4
added gitignore to overcome repo sync issue
kgashok Jan 1, 2020
57e16f8
added test.sh file
kgashok Jan 1, 2020
7f186b2
Delete huffman.cpython-36.pyc
kgashok Jan 1, 2020
172696c
Delete __init__.cpython-36.pyc
kgashok Jan 1, 2020
3e234e2
Delete test_huffman.cpython-36-pytest-5.3.2.pyc
kgashok Jan 1, 2020
088148e
updated gitignore
kgashok Jan 1, 2020
22d37fa
removed bin files
kgashok Jan 1, 2020
fb8504e
toying with annotations
kgashok Jan 1, 2020
f75c152
autopep8 formatted the files
kgashok Jan 1, 2020
1d198dc
removed bin files
kgashok Jan 1, 2020
ac84f92
minor edits
kgashok Jan 1, 2020
353e100
disabled all but one test
kgashok Jan 1, 2020
25f0c44
configured to run tests through .replit
kgashok Jan 1, 2020
ebeed8d
TDD based development for #2
kgashok Jan 1, 2020
3f67e26
Fixed #1 - one line fix!
kgashok Jan 1, 2020
0cb743b
Instructions for Repo to Repl
kgashok Jan 1, 2020
bde33d1
updated README.md for Repo to Repl (R2R)
kgashok Jan 1, 2020
4483e7d
minor edit
kgashok Jan 1, 2020
ec5860f
image cropped
kgashok Jan 1, 2020
e6dbeed
README edits
kgashok Jan 1, 2020
53bbdd3
Moved R2R instructions to the bottom
kgashok Jan 1, 2020
80e9e32
minor edits
kgashok Jan 1, 2020
93de2e0
README edits
kgashok Jan 1, 2020
2357232
refactored make_frequency
kgashok Jan 2, 2020
e09aa83
test for time comparison
kgashok Jan 2, 2020
4fb8880
fixed timing test
kgashok Jan 2, 2020
c8ebda5
improved performance statistics
kgashok Jan 2, 2020
02c3e53
Fixed #8
kgashok Jan 2, 2020
7cbe45a
huffman photo
kgashok Jan 2, 2020
04336af
added .bash_profile
kgashok Jan 2, 2020
459fda9
Create .bashrc
kgashok Jan 2, 2020
ee46d2e
used the -rP flag for better capture
kgashok Jan 2, 2020
17b4628
further test output refinement
kgashok Jan 2, 2020
cfe4e04
added annotations for class variables
kgashok Jan 2, 2020
32bcfac
formatting done
kgashok Jan 2, 2020
0ee0cbe
added bashrc
kgashok Jan 2, 2020
36eafa6
comments formatted
kgashok Jan 2, 2020
f2a3545
commented pad_encoded_text for #3
kgashok Jan 2, 2020
57b6c39
added annotations for #3
kgashok Jan 2, 2020
e813b9d
added bashprofile to tackle disappearing dot files
kgashok Jan 2, 2020
6b04917
documentation and annotation for padding for #3
kgashok Jan 2, 2020
5bffea2
some more comments to make it
kgashok Jan 2, 2020
79c041e
muted the performance test
kgashok Jan 2, 2020
fad1b6a
more links in README
kgashok Jan 2, 2020
e0d5065
Fixed #7 through decode_text2 method
kgashok Jan 2, 2020
906dabb
all commented except for @total_ordering
kgashok Jan 2, 2020
e12d019
some more refinements
kgashok Jan 2, 2020
df31f2a
using bidict merged two dict objects
kgashok Jan 3, 2020
75aa44f
displaying some bidicts in the test cases
kgashok Jan 3, 2020
cf7319e
cleaned up some code - #11
kgashok Jan 3, 2020
635c3d3
Create files
kgashok Jan 3, 2020
7669455
Delete files
kgashok Jan 3, 2020
c57fd9e
Create README.md
kgashok Jan 3, 2020
7194a6b
Add files via upload
kgashok Jan 3, 2020
dae8446
Added visual interactive
kgashok Jan 3, 2020
90a507a
added output capture
kgashok Jan 4, 2020
bf8db4e
Update README.md
kgashok Jan 4, 2020
112f72d
Update README.md
kgashok Jan 7, 2020
67fb666
using bitarray
kgashok Jan 7, 2020
59b0c11
Incorporated for #14, now need to refactor further
kgashok Jan 7, 2020
6c1745c
For #14, used update() and looks nice!
kgashok Jan 7, 2020
e7021d4
used bitarray to simpify code
kgashok Jan 18, 2020
6155e02
Fixed #15 - bit_string from file using bitarray
kgashok Jan 18, 2020
9625ad3
Refactored using encode and decode - Fixed #16
kgashok Jan 18, 2020
c6102be
autoformatted using autopep8
kgashok Jan 18, 2020
9a82726
refactored to remove all commented code
kgashok Jan 18, 2020
15efd20
auto formatted
kgashok Jan 18, 2020
4064af1
some minor edits
kgashok Jan 18, 2020
8fd4e29
removed comments
kgashok Jan 18, 2020
cdd1feb
Fixed #14
kgashok Jan 18, 2020
6c21664
added requirements.txt file
kgashok Jan 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 6 additions & 57 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,58 +1,7 @@
#####=== Python ===#####
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

.idea/
sample_decompressed.txt
sample.bin
tests/*.bin
3 changes: 3 additions & 0 deletions .replit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language = "python3"
#run = "python3 useHuffman.py"
run = "pip3 install -r requirements.txt; cd tests; python3 -m pytest -rP test_huffman.py"
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
### Python Implementaion of Huffman Coding
[![Run on Repl.it](https://repl.it/badge/github/kgashok/huffman-coding)](https://repl.it/github/kgashok/huffman-coding)
_(for additional configuration instructions, see [below](https://github.com/kgashok/huffman-coding#repo-to-repl))_

Explanation at http://bhrigu.me/blog/2017/01/17/huffman-coding-python-implementation/
#### The Visual that _really_ works!

A Glitch Project - https://shining-baroness.glitch.me/

### Python Implementation of Huffman Coding

Explanation at http://bhrigu.me/blog/2017/01/17/huffman-coding-python-implementation/ or http://j.mp/huffmanPy

Consists **compress** and **decompress** function.

Expand All @@ -16,3 +23,37 @@ To run the code for compression of any other text file, edit the `path` variable


For now, the *decompress()* function is to be called from the same object from which the *compress()* function was called, for compressing-decompressing a file (as the encoding information is stored in the data members of the object only)

## Repo to Repl
1. Click on the gray **repl.it badge** above.
2. Wait for the repo to get loaded into repl.it
3. Look for the green "Run" button at the top of the screen. Click on it and existing tests cases should run

![run](/img/runButton.png)

4. If you get an error **"No module named pytest"**, then run the following command in repl.it prompt (on the right hand side in the bash shell):
```bash
. install.sh # period and space and 'install.sh'
# wait for 'pytest' and 'autopep8' install to complete
```

5. Now, try clicking the green "Run" button again. IT should work.


### The Genius of David Huffman

- Read https://www.maa.org/press/periodicals/convergence/discovery-of-huffman-codes
- Analysis as greedy algorithm https://www.codesdope.com/course/algorithms-huffman-codes/
- Read http://www.skypape.com/huffman.htm

![huffman](/img/huffmanDr.jpg)

### From Huffman Visualizer (http://j.mp/huffVisual)

- The **padding** (red),
- The bidirectional **hashtable** (aka map), and
- the actual compressed **code** (3 bytes in blue) for "abracadabra" (11 bytes),

achieving a compression of **59**%

![outputForAbracadabra](/img/outputForAbracadabra.png)
Empty file added __init__.py
Empty file.
Binary file added __pycache__/huffman.cpython-36.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions bashprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if [ -f "$HOME/.bashrc" ] ; then
source $HOME/.bashrc
fi
2 changes: 2 additions & 0 deletions bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alias pytest="/home/runner/.local/bin/pytest"
alias autopep8="/home/runner/.local/bin/autopep8 --in-place --aggressive --aggressive --max-line-length=119 --indent-size 2"
Binary file not shown.
Binary file added files/Go deh!_ Huffman Encoding in Python.pdf
Binary file not shown.
Binary file added files/Huffman.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

7 changes: 7 additions & 0 deletions gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

sample_decompressed.txt
sample.bin
tests/*.bin
Loading