-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiagnostics.java
More file actions
29 lines (23 loc) · 948 Bytes
/
Diagnostics.java
File metadata and controls
29 lines (23 loc) · 948 Bytes
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
/**
* Calculate the compress rate. Assuming that the original code is 8-bit ASCII code.
* @param text
* @param code
* @return
*/
import java.util.Collections;
import java.util.ArrayList;
public class Diagnostics {
public static double calCompRate(String text, ArrayList<String> code){
double compRate = 0;
double preNum = 8*text.length();
double postNum = 0;
for ( String s: code) {
postNum += s.length();
}
compRate = preNum/postNum;
System.out.println("If simply using ASCII code, there are in total " + (int)preNum + " bits.");
System.out.println("If using huffman coding, there are in total " + (int)postNum + " bits.");
System.out.println("The compress rate is: " + compRate);
return compRate;
}
}