-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompressor.java
More file actions
67 lines (57 loc) · 1.58 KB
/
Copy pathCompressor.java
File metadata and controls
67 lines (57 loc) · 1.58 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package compresseur;
import java.io.IOException;
import java.util.Iterator;
import java.util.Vector;
public abstract class Compressor {
Vector<Integer> source;
Vector<Integer> compression;
Vector<Sequence> sequencesMemoisation;
public Compressor(Vector<Integer> vector) {
this.source = vector;
this.sequencesMemoisation = new Vector<Sequence>();
for (int i = 0; i < vector.size(); i++) {
sequencesMemoisation.add(new Sequence(-1));
}
}
public abstract Vector<Integer> compress() throws TooLongSequenceException, IOException;
public void readSequencesToBinaryVector (VectorOfSequence bestCompression) {
int index = 0;
int numberOfElements, numberOfBits;
for(Iterator<Sequence> i = bestCompression.iterator(); i.hasNext(); ) {
Sequence item = i.next();
// Writing header
numberOfElements = item.getNumberOfElements();
numberOfBits = item.getNumberOfBitsPerByte();
for(float l = 128; l >= 1; l /= 2) {
if(numberOfElements / l >= 1) {
compression.add(1);
numberOfElements -= l;
}
else {
compression.add(0);
}
}
for(float l = 4; l >= 1; l/=2) {
if(numberOfBits / l >= 1) {
compression.add(1);
numberOfBits -= l;
}
else {
compression.add(0);
}
}
// Writing data
for(int j = 0; j < item.numberOfElements; j++) {
for(int k = 0; k < (8 - item.numberOfBitsPerByte); k++) {
// Skipping useless zeros
index++;
}
for(int k = 0; k < item.numberOfBitsPerByte; k++) {
compression.add(source.get(index));
System.out.println(source.get(index));
index++;
}
}
}
}
}