WIP
This commit is contained in:
102
main.cpp
102
main.cpp
@ -194,76 +194,76 @@ using namespace std;
|
||||
//// Huffman coding algorithm
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// // buildHuffmanTree(cin);
|
||||
// // 10111010 11110101
|
||||
// stringstream ss("\xba\xf5");
|
||||
// ibitstream ibs(ss);
|
||||
// buildHuffmanTree(cin);
|
||||
// 10111010 11110101
|
||||
stringstream ss("\xba\xf5");
|
||||
ibitstream ibs(ss);
|
||||
|
||||
// // 10111010 11110101
|
||||
// // ^^
|
||||
// int a = ibs.getbits(2);
|
||||
// cout << bitset<2>(a) << endl; // 01
|
||||
// 10111010 11110101
|
||||
// ^^
|
||||
int a = ibs.getbits(2);
|
||||
cout << bitset<2>(a) << endl; // 01
|
||||
|
||||
// // 10111010 11110101
|
||||
// // ^^^^
|
||||
// int b = ibs.getbits(4);
|
||||
// cout << bitset<4>(b) << endl; // 0111
|
||||
// 10111010 11110101
|
||||
// ^^^^
|
||||
int b = ibs.getbits(4);
|
||||
cout << bitset<4>(b) << endl; // 0111
|
||||
|
||||
|
||||
// // 10111010 11110101
|
||||
// // ^^ ^^^^^^^
|
||||
// b = ibs.getbits(9);
|
||||
// cout << bitset<9>(b) << endl; // 011010111
|
||||
// 10111010 11110101
|
||||
// ^^ ^^^^^^^
|
||||
b = ibs.getbits(9);
|
||||
cout << bitset<9>(b) << endl; // 011010111
|
||||
|
||||
// // 10111010 11110101
|
||||
// // ^ + overflow
|
||||
// try {
|
||||
// b = ibs.getbits(10);
|
||||
// cout << b << endl;
|
||||
// } catch (std::runtime_error &e) {
|
||||
// cout << "Got runtime error: " << e.what() << endl;
|
||||
// }
|
||||
// 10111010 11110101
|
||||
// ^ + overflow
|
||||
try {
|
||||
b = ibs.getbits(10);
|
||||
cout << b << endl;
|
||||
} catch (std::runtime_error &e) {
|
||||
cout << "Got runtime error: " << e.what() << endl;
|
||||
}
|
||||
|
||||
// ostringstream so("bits: ");
|
||||
// obitstream obs(so);
|
||||
ostringstream so("bits: ");
|
||||
obitstream obs(so);
|
||||
|
||||
// obs.writebits(0xf, 3);
|
||||
// cout << "After 3 bits: " << so.str() << endl;
|
||||
// // cache here: 00000111
|
||||
obs.writebits(0xf, 3);
|
||||
cout << "After 3 bits: " << so.str() << endl;
|
||||
// cache here: 00000111
|
||||
|
||||
|
||||
// // de = 11011110
|
||||
// obs.writebits(0xde, 7);
|
||||
// // here: Flush: 11101111
|
||||
// cout << "After 7 bits: " << so.str() << endl;
|
||||
// obs.flush();
|
||||
// // here: Flush: 00000001
|
||||
// cout << "After flush: " << so.str() << endl;
|
||||
// de = 11011110
|
||||
obs.writebits(0xde, 7);
|
||||
// here: Flush: 11101111
|
||||
cout << "After 7 bits: " << so.str() << endl;
|
||||
obs.flush();
|
||||
// here: Flush: 00000001
|
||||
cout << "After flush: " << so.str() << endl;
|
||||
|
||||
|
||||
// obs.writebits(0xbeef, 16);
|
||||
// cout << "After 0xbeef: " << so.str() << endl;
|
||||
// obs.flush();
|
||||
// // here: Flush: 0xEFBE - reversed!
|
||||
// cout << "After flush: " << so.str() << endl;
|
||||
obs.writebits(0xbeef, 16);
|
||||
cout << "After 0xbeef: " << so.str() << endl;
|
||||
obs.flush();
|
||||
cout << "After flush: " << so.str() << endl;
|
||||
|
||||
|
||||
// string s = ;
|
||||
// // string s = ;
|
||||
|
||||
stringstream ss1("Some long text!!!!\x01\x02\x03\x04\n123123456789 privet, masha!");
|
||||
stringstream ss2("Some long text!!!!\x01\x02\x03\x04\n123123456789 privet, masha!");
|
||||
stringstream so1;
|
||||
stringstream so2;
|
||||
// stringstream ss1("Some long text!!!!\x01\x02\x03\x04\n123123456789 privet, masha!");
|
||||
// stringstream ss2("Some long text!!!!\x01\x02\x03\x04\n123123456789 privet, masha!");
|
||||
// stringstream so1;
|
||||
// stringstream so2;
|
||||
|
||||
MashZip mz;
|
||||
// MashZip mz;
|
||||
|
||||
mz.mashzip_file(ss1, ss2, so1);
|
||||
// mz.mashzip_file(ss1, ss2, so1);
|
||||
|
||||
std::cout << "After mashzip: " << so1.str();
|
||||
// // std::cout << "After mashzip: " << so1.str();
|
||||
// std::cout << so1.str();
|
||||
|
||||
mz.unmashzip_stream(so1, so2);
|
||||
// mz.unmashzip_stream(so1, so2);
|
||||
|
||||
std::cout << "After unmashzip: " << so2.str();
|
||||
// std::cout << "After unmashzip: " << so2.str();
|
||||
|
||||
// HuffmanTable ht(ss1);
|
||||
|
||||
|
Reference in New Issue
Block a user