aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2020-05-30 19:58:56 +0000
committerrepl.it user2020-05-30 19:58:56 +0000
commit751020125832686c4f38c59e29b2b94393f28cd2 (patch)
treed3a1458d1ac19cebb0f8d5fdcef51450fce3e6e0
parentf4d13fb7bb72e6959f9929c0ffb568ccaeffb44f (diff)
Trying to get things to work
-rw-r--r--.replit2
-rw-r--r--src/decode.cpp4
-rw-r--r--src/encode.cpp14
-rw-r--r--test2
4 files changed, 14 insertions, 8 deletions
diff --git a/.replit b/.replit
index 6ba928f..413ed52 100644
--- a/.replit
+++ b/.replit
@@ -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";
}*/
-//}
+}
diff --git a/test b/test
index d7028ce..3f802fb 100644
--- a/test
+++ b/test
@@ -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