-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.cpp
More file actions
40 lines (32 loc) · 1.26 KB
/
output.cpp
File metadata and controls
40 lines (32 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include "output.hpp"
using namespace std;
void outputOriginal(uint8_t * data_ptr, int data_size) {
cout << "Original Message:" << endl;
for(int i = 0; i < data_size; i++) {
cout << hex << (unsigned) data_ptr[i] << " ";
}
cout << endl << endl;
}
void outputEncoded(uint8_t * data_ptr, int data_size, unordered_map<uint8_t, string> &encodings) {
cout << "Encoded Message:" << endl;
int encoded_size = 0;
for(int i = 0; i < data_size; i++) {
cout << encodings[data_ptr[i]] << " ";
encoded_size += (encodings[data_ptr[i]]).size();
}
cout << endl << endl;
cout << "Original Size: " << dec << data_size * 8 << " bits" << endl;
cout << "Encoded Size: " << dec << encoded_size << " bits" << endl;
cout << "Compressions Ratio: " << fixed << static_cast<double>(data_size * 8)/(encoded_size) << endl;
double space_savings = 1 - static_cast<double>(encoded_size)/(data_size * 8);
int percent = (space_savings * 100);
cout << "Space Savings: " << dec << percent << "%" << endl;
}
void outputEncodingTable(unordered_map<uint8_t, string> &encodings) {
cout << "Encoding Table:" << endl;
for(auto it = encodings.begin(); it != encodings.end(); it++) {
cout << hex << (unsigned) it->first << " " << dec << it->second << endl;
}
cout << endl;
}