-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursiveCompressor.java
More file actions
68 lines (55 loc) · 1.88 KB
/
Copy pathRecursiveCompressor.java
File metadata and controls
68 lines (55 loc) · 1.88 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
68
package compresseur;
import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Vector;
public class RecursiveCompressor extends Compressor {
public RecursiveCompressor(Vector<Integer> vector) {
super(vector);
}
@Override
public Vector<Integer> compress() throws TooLongSequenceException, IOException {
VectorOfSequence bestCompression = new VectorOfSequence();
bestCompression = findTheLightestSequence(0, bestCompression);
readSequencesToBinaryVector(bestCompression);
return compression;
}
public VectorOfSequence findTheLightestSequence(int index, VectorOfSequence inputSequence) throws TooLongSequenceException, IOException {
if(index == this.source.size())
return inputSequence;
int currentByteSize = Reader.getMinimumSizeOfAByte(this.source, index);
VectorOfSequence firstSequence = null;
try {
if(inputSequence.lastElement().numberOfElements < 256) {
firstSequence = new VectorOfSequence(inputSequence);
firstSequence.addAByteToTheLastSequence(currentByteSize);
firstSequence = findTheLightestSequence(index + 8, firstSequence);
}
}
catch (NoSuchElementException e) {}
VectorOfSequence secondSequence = new VectorOfSequence(inputSequence);
System.out.println("1");
secondSequence.add(new Sequence(currentByteSize));
System.out.println("2");
if(sequencesMemoisation.get(index).getNumberOfBitsPerByte() == -1) {
secondSequence = findTheLightestSequence(index + 8, secondSequence);
sequencesMemoisation.add(index, secondSequence.lastElement());
}
else {
System.out.println("3");
secondSequence.add(sequencesMemoisation.get(index));
System.out.println("4");
}
if(firstSequence == null) {
return secondSequence;
}
else {
if(firstSequence.getSize() <= secondSequence.getSize()) {
return firstSequence;
}
else {
return secondSequence;
}
}
}
}