-
Notifications
You must be signed in to change notification settings - Fork 0
/
manual.dart
40 lines (34 loc) · 1.15 KB
/
manual.dart
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
import 'src/huffman.dart';
void main() {
String message = "Hello World";
/*
Map<String,int> chars = {
'a' : 2,
'z' : 2,
}
Map<String,double> pd = {
'a' : 0.5,
'z' : 0.5
}
*/
bool m = true; //Set this to false, if you want to provide chars or pd as input
Map<String, int> chars = char_frequency(message);
Map<String, double> pd = d_sort_map(prob_dist(chars));
List<Node> nodes = generateNodeFromMap(pd);
Node root = generateHuffmanTree(nodes);
Map<String, String> table = generateHuffmanTable(node: root);
if (m) {
Map<String, dynamic> encoded_message = compressor(table, message);
String original_message = decompressor(encoded_message);
print("table: ${encoded_message['table']}");
print("encoded message: ${encoded_message['message']}");
print("Retrived Message: ${original_message}");
var len_enc = encoded_message['message'].length;
var len_mess = message.length * 8; // Assume each char takes 8 bits
var comp_perctange = ((len_mess - len_enc) / len_mess) * 100;
print("-" * 30);
print("${dp(comp_perctange, places: 2)} % compressed ");
} else {
print("table: ${table}");
}
}