diff options
author | Anthony Wang | 2020-05-30 19:58:56 +0000 |
---|---|---|
committer | repl.it user | 2020-05-30 19:58:56 +0000 |
commit | 751020125832686c4f38c59e29b2b94393f28cd2 (patch) | |
tree | d3a1458d1ac19cebb0f8d5fdcef51450fce3e6e0 | |
parent | f4d13fb7bb72e6959f9929c0ffb568ccaeffb44f (diff) |
Trying to get things to work
-rw-r--r-- | .replit | 2 | ||||
-rw-r--r-- | src/decode.cpp | 4 | ||||
-rw-r--r-- | src/encode.cpp | 14 | ||||
-rw-r--r-- | test | 2 |
4 files changed, 14 insertions, 8 deletions
@@ -1,2 +1,2 @@ language = "cpp"
-run = "g++ src/*.cpp -o compress -std=c++1y; echo Compilation done; ./compress soc1.txt 30" +run = "g++ src/*.cpp -o compress -std=c++1y; echo Compilation done; ./compress soc1.txt 0" diff --git a/src/decode.cpp b/src/decode.cpp index 5917d96..0d54dab 100644 --- a/src/decode.cpp +++ b/src/decode.cpp @@ -1,7 +1,7 @@ #include "common.h" #include "huffman.h" -int main() { +/*int main() { ifstream enc("test"); stringstream ss; ss << enc.rdbuf(); @@ -12,4 +12,4 @@ int main() { //for (int i = 0; i < 8; ++i) v.push_back(1 & (c >> i)); } cout << huffman::decode(v); -}
\ No newline at end of file +}*/
\ No newline at end of file diff --git a/src/encode.cpp b/src/encode.cpp index d7f3d8d..e0d5199 100644 --- a/src/encode.cpp +++ b/src/encode.cpp @@ -368,11 +368,17 @@ string huffmancompress(string s) return ans; } +int huffmancompresslength(string s) +{ + vector<bool> enc = huffman::encode(s); + return (enc.size() + 7) / 8; +} + int initsize=0; int compressrate; int targetsize; -/*int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) { getlists(); string input=""; @@ -392,7 +398,7 @@ int targetsize; initsize=input.length()-1;//remove last newline for(char& x:input) - if(x=='\r') + if(x=='\r' || x == '\n') x=' '; file orig; @@ -417,7 +423,7 @@ int targetsize; tmp.calcweight(); tmp.preprocess(-1); string s = tmp.gettextstring(-100000); - int sz= (s == "" ? 0 : huffmancompress(s).length()); + int sz= (s == "" ? 0 : huffmancompresslength(s)); if(sz>targetsize) { a=c; @@ -469,4 +475,4 @@ int targetsize; cout << "Compressed length: " << (enc.size() + 7) / 8 << '\n'; cout << "Percent compression: " << 100.0 - (double)100.0 * (enc.size() + 7) / 8 / orig.size() << "%\n"; }*/ -//} +} @@ -1 +1 @@ -01010111100111101011111011111000011111010011110110111011101011101111011001101011001101110101100000101011110001110101101000111011101101011011110110101101101111110000111011111101111101011010101011011101010101110100111110011111100111101010101101100111111100111100001101011010011010110101011111001110101100101111010101110010111110110111110001101100100111110001100111011000111100111110000000110110100010010111001111110110101111011101111110001101000110111010010110010111010011010100010001100110010010010100101110010010110100110001010000011100111011100010000111011110001000110111011011001101100010110011011001111011101011011011101111111000111100000101111010010100101110010000100010110001101010001000101111110101110100110010011110010010111101100101100000111001110111000011011111010001000101111110101110100101010100010111111100000111001110111000110001111101100110110
\ No newline at end of file +
傾燩═牾z=徢鉸杠顆;漀в閠狠n穂-嬇鈗杠n7嵠泷~縚疻陁狠铟~窟飛籡k第韛籡甒玌牾z絕雞狠顆籡k礪膈z=炏g迟靨;澪鐂筡甒玌j第眦{睫飛;漀вi碯k5嵠鉸杠n穂膈鷠具飛惠n穂k礪-査e操l6岶Q鑤篯甒玌猆陁狠n粉眦{=炏g砓膈鷠具秣鹽具飛惠顆籡甒玌j第m钝眦~?熛珞?熛珞y<濷'撋鋜管n穂-査弪~?嚸醦竆k5歁τ轸z絕k5
喢a癤雞:幥c盭雞篯膈z絕雞:幥泷鴟>熛珞y嫁飛惠铟{睫飛籡.椝錼管铟{=炏珞y糬k5
喢狃鴟具o7浲骟y<炏g迟靨惠顆;澪g3橪τi碯k5歁τi蹿眦鹽>烵'撋鋜管顆;嶨#慔┰牾z睫飛籡.匓(擩%壞b盭,匓═陁狠顆惠n穂璙+暿錼筡膈z=嘋⌒梏鷠具秣~?嘋⌒h蹿m钝韛籡.椝錼筡k礪-朘%捝d2屍c1屍鉸杠铟{=濷вi碯璙玌*旿ヒ轸z=伬`癤,査e瞃,朘%塂"埬b盭,嬇怦x<廏#埬b必l钝眦~縚k5嵠c盭琕陁:澪珞y糬疻牾z=廏ㄔ陁:幥c1楲τi碯璙+娕b1樚f砓,朘%捝d2屍c1屍c1楲τ閠狠顆籡.椝e操l6汳τ轸~?廏#侫犘梏z=炏g砓,婨"懭潋y<濷вi4歁&撋d2橪&撋潋y<廏Q梏~?徢泷x<炏鐂管顆;漀вi蹿眦鹽>熛g3屍c1屍泷x<濷вi蹿m6岶#懭d2兞囵x糬疻陁:嚸狃~窟飛惠n穂璙玌*暿弪y嫁o粉m6浲f砓,@ 惾潋鵿綺疻+暿e2橪&揑ひ閠:澪珞y糬疻牾z=廏Qh碯膈z睫o穂-朘%塂ㄔ陁:嶨Q鑤:澪珞鵿具o穂-査e瞃,朘%扞$捝d操l禰k礪-婨"圖⒀h蹿眦~縚k5毻f砓,朘%塂"慔$捝鋜9淣'撋d2櫶f砓,朘%扞$扞$捝鋜管n7浲骟?嘋═*旿%扞ひ閠:漀вi4毻f砓,嬇b1咰⌒鑤狠铟~縚雞狠顆籡膈鷠>熛鐂筡雞狠顆籡膈~縚疻j礪-嬇鈗杠n7
喢醦竆甒+暿錼9溛鐂9溛g砓,偭`柏l6嵠c必祧{絕/椝e |