forked from fast-pack/JavaFastPFOR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKamikaze.java
More file actions
72 lines (62 loc) · 2.18 KB
/
Kamikaze.java
File metadata and controls
72 lines (62 loc) · 2.18 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
69
70
71
72
package me.lemire.integercompression;
import com.kamikaze.pfordelta.PForDelta;
/**
* IntegerCODEC wrapper for Kamikaze's PForDelta.
*
* Note: this class is only included for speed benchmarks.
* It is not recommended. Use at your own risks.
*
* @author Matteo Catena
*
*/
public class Kamikaze implements SkippableIntegerCODEC, IntegerCODEC {
private int BLOCK_SIZE = 128;
@Override
public void headlessCompress(int[] in, IntWrapper inpos, int inlength, int[] out,
IntWrapper outpos) {
inlength = Util.greatestMultiple(inlength, BLOCK_SIZE);
if (inlength > 0) {
int[] out2 = PForDelta.compressOneBlockOpt(in, inlength);
inpos.add(inlength);
System.arraycopy(out2, 0, out, outpos.get(), out2.length);
outpos.add(out2.length);
}
}
@Override
public void headlessUncompress(int[] in, IntWrapper inpos, int inlength, int[] out,
IntWrapper outpos, int num) {
num = Util.greatestMultiple(num, BLOCK_SIZE);
if (num > 0) {
int d = PForDelta.decompressOneBlock(out, in, num);
inpos.add(d / 32);
outpos.add(num);
}
}
@Override
public int maxHeadlessCompressedLength(IntWrapper compressedPositions, int inlength) {
throw new UnsupportedOperationException("Calculating the max compressed length is not supported yet.");
}
@Override
public String toString() {
return "Kamikaze's PForDelta";
}
@Override
public void compress(int[] in, IntWrapper inpos, int inlength, int[] out,
IntWrapper outpos) {
inlength = Util.greatestMultiple(inlength, BLOCK_SIZE);
if (inlength == 0)
return;
out[outpos.get()] = inlength;
outpos.increment();
headlessCompress(in, inpos, inlength, out, outpos);
}
@Override
public void uncompress(int[] in, IntWrapper inpos, int inlength, int[] out,
IntWrapper outpos) {
if (inlength == 0)
return;
final int outlength = in[inpos.get()];
inpos.increment();
headlessUncompress(in, inpos, inlength, out, outpos, outlength);
}
}