bogdasar1985 / huffmancode Goto Github PK
View Code? Open in Web Editor NEWA simple implementation of HuffmanCode
License: GNU General Public License v3.0
A simple implementation of HuffmanCode
License: GNU General Public License v3.0
$ valgrind --track-origins=yes -s ./coder ../sample-2mb-text-file.txt ../res.txt
==18668== Memcheck, a memory error detector
==18668== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==18668== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==18668== Command: ./coder ../sample-2mb-text-file.txt ../res.txt
==18668==
==18668== Conditional jump or move depends on uninitialised value(s)
==18668== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==18668== by 0x485548A: get_code (huffman.c:68)
==18668== by 0x1095DA: main (coder.c:53)
==18668== Uninitialised value was created by a stack allocation
==18668== at 0x10933D: main (coder.c:6)
==18668==
==18668== Conditional jump or move depends on uninitialised value(s)
==18668== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==18668== by 0x485544E: get_code (huffman.c:70)
==18668== by 0x1095DA: main (coder.c:53)
==18668== Uninitialised value was created by a stack allocation
==18668== at 0x10933D: main (coder.c:6)
==18668==
==18668== Conditional jump or move depends on uninitialised value(s)
==18668== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==18668== by 0x1096DA: main (coder.c:59)
==18668== Uninitialised value was created by a stack allocation
==18668== at 0x10933D: main (coder.c:6)
==18668==
==18668==
==18668== HEAP SUMMARY:
==18668== in use at exit: 944 bytes in 2 blocks
==18668== total heap usage: 16 allocs, 14 frees, 15,504 bytes allocated
==18668==
==18668== LEAK SUMMARY:
==18668== definitely lost: 0 bytes in 0 blocks
==18668== indirectly lost: 0 bytes in 0 blocks
==18668== possibly lost: 0 bytes in 0 blocks
==18668== still reachable: 944 bytes in 2 blocks
==18668== suppressed: 0 bytes in 0 blocks
==18668== Rerun with --leak-check=full to see details of leaked memory
==18668==
==18668== ERROR SUMMARY: 14 errors from 3 contexts (suppressed: 0 from 0)
==18668==
==18668== 3 errors in context 1 of 3:
==18668== Conditional jump or move depends on uninitialised value(s)
==18668== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==18668== by 0x485544E: get_code (huffman.c:70)
==18668== by 0x1095DA: main (coder.c:53)
==18668== Uninitialised value was created by a stack allocation
==18668== at 0x10933D: main (coder.c:6)
==18668==
==18668==
==18668== 4 errors in context 2 of 3:
==18668== Conditional jump or move depends on uninitialised value(s)
==18668== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==18668== by 0x485548A: get_code (huffman.c:68)
==18668== by 0x1095DA: main (coder.c:53)
==18668== Uninitialised value was created by a stack allocation
==18668== at 0x10933D: main (coder.c:6)
==18668==
==18668==
==18668== 7 errors in context 3 of 3:
==18668== Conditional jump or move depends on uninitialised value(s)
==18668== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==18668== by 0x1096DA: main (coder.c:59)
==18668== Uninitialised value was created by a stack allocation
==18668== at 0x10933D: main (coder.c:6)
==18668==
==18668== ERROR SUMMARY: 14 errors from 3 contexts (suppressed: 0 from 0)
Valgrind found a memory leaks, made by merge()
function. This function return a pointer received from malloc()
.
We can use Makefile, CMake or shell script.
Input:
aaabbababababahhaahba
Output:
aaabbababababahhahba
We lose one a
.
Now priority_queue
implemented by using list
, we should use binary_tree
to make them faster. Change complexity from O(n) to O(log n).
Function getb(FILE *stream)
don't work correct. It does not read all the entire file when using, like
while((ch = getb(fl)) != EOF)
{
/*code*/
}
.
Implement writing in file, using Huffman codes
At the moment, design is so bad. I should fix it, while complexity is not too big!
Add a macro for debug information with different levels, such as:
We have to design interfaces whose methods can be combined, i.e. a combination of small methods is better than writing one big one.
We do not take extra bits into account when decoding.
To add a decoder, we should write a Huffman Tree at the beginning of file.
When we decode the file, we will have to read and build the tree.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.