Skip to content

Commit 73f164b

Browse files
authored
Revise README with Java example for compression
Updated usage section with a complete Java example demonstrating the compression and uncompression process using FastPFOR128.
1 parent bc44781 commit 73f164b

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

README.md

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,50 @@ as well as in GMAP and GSNAP (http://research-pub.gene.com/gmap/).
4848
Usage
4949
------
5050

51-
Really simple usage:
5251

5352
```java
54-
IntegratedIntCompressor iic = new IntegratedIntCompressor();
55-
int[] data = ... ; // to be compressed
56-
int[] compressed = iic.compress(data); // compressed array
57-
int[] recov = iic.uncompress(compressed); // equals to data
53+
package org.example;
54+
55+
import me.lemire.integercompression.FastPFOR128;
56+
import me.lemire.integercompression.IntWrapper;
57+
58+
import java.util.Arrays;
59+
60+
public class Main {
61+
public static void main(String[] args) {
62+
FastPFOR128 fastpfor = new FastPFOR128();
63+
64+
int N = 9984;
65+
int[] data = new int[N];
66+
for (var i = 0; i < N; i += 150) {
67+
data[i] = i;
68+
}
69+
70+
int[] compressedoutput1 = new int[N + 1024];
71+
72+
IntWrapper inputoffset1 = new IntWrapper(0);
73+
IntWrapper outputoffset1 = new IntWrapper(0);
74+
75+
fastpfor.compress(data, inputoffset1, N, compressedoutput1, outputoffset1);
76+
int compressedsize1 = outputoffset1.get();
77+
78+
int[] recovered1 = new int[N];
79+
inputoffset1 = new IntWrapper(0);
80+
outputoffset1 = new IntWrapper(0);
81+
fastpfor.uncompress(compressedoutput1, outputoffset1, compressedsize1, recovered1, inputoffset1);
82+
83+
// quick verification: count mismatches
84+
int mismatches = 0;
85+
for (int i = 0; i < N; i++) {
86+
if (data[i] != recovered1[i]) mismatches++;
87+
}
88+
89+
System.out.println("N=" + N + " compressedSizeWords=" + compressedsize1 + " mismatches=" + mismatches);
90+
System.out.println("first 20 original: " + Arrays.toString(Arrays.copyOf(data, 20)));
91+
System.out.println("first 20 recovered: " + Arrays.toString(Arrays.copyOf(recovered1, 20)));
92+
}
93+
}
94+
5895
```
5996

6097
For more examples, see example.java or the examples folder.

0 commit comments

Comments
 (0)