[Git][java-team/libdsiutils-java][upstream] New upstream version 2.7.4+dfsg
Pierre Gruet (@pgt)
gitlab at salsa.debian.org
Tue Aug 19 11:13:04 BST 2025
Pierre Gruet pushed to branch upstream at Debian Java Maintainers / libdsiutils-java
Commits:
84510553 by Pierre Gruet at 2025-08-19T09:19:52+02:00
New upstream version 2.7.4+dfsg
- - - - -
4 changed files:
- CHANGES
- build.properties
- src/it/unimi/dsi/bits/Fast.java
- src/it/unimi/dsi/test/InputBitStreamSpeedTest.java
Changes:
=====================================
CHANGES
=====================================
@@ -1,3 +1,11 @@
+2.7.4
+
+- Fast.nat2int() methods have a possibly slightly faster implementation
+ taken from Google's protobuf, whose ZigZag encoding is exactly
+ Fast.int2nat()/Fast.nat2int(). In Rust the compiler generates exactly
+ the same assembly for the old and the new implementation, but it
+ is not guaranteed that all JVMs will do the same.
+
2.7.3
- Mapping an empty file with ByteBufferInputStream would have caused
=====================================
build.properties
=====================================
@@ -1,4 +1,4 @@
-version=2.7.3
+version=2.7.4
build.sysclasspath=ignore
=====================================
src/it/unimi/dsi/bits/Fast.java
=====================================
@@ -124,7 +124,7 @@ public final class Fast {
*/
public static int nat2int(final int x) {
- return (x >> 1) ^ ~((x & 1) - 1);
+ return (x >> 1) ^ -(x & 1);
}
/** Maps longs bijectively into long natural numbers.
@@ -157,7 +157,7 @@ public final class Fast {
*/
public static long nat2int(final long x) {
- return (x >> 1) ^ ~((x & 1) - 1);
+ return (x >> 1) ^ -(x & 1);
}
/** Returns the base-two logarithm of the argument.
=====================================
src/it/unimi/dsi/test/InputBitStreamSpeedTest.java
=====================================
@@ -19,81 +19,124 @@
package it.unimi.dsi.test;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
+import org.apache.commons.math3.distribution.ZipfDistribution;
+
+import it.unimi.dsi.bits.Fast;
+import it.unimi.dsi.fastutil.doubles.DoubleArrays;
+import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream;
import it.unimi.dsi.io.InputBitStream;
import it.unimi.dsi.io.OutputBitStream;
import it.unimi.dsi.logging.ProgressLogger;
+import it.unimi.dsi.util.XoShiRo256PlusRandomGenerator;
public class InputBitStreamSpeedTest {
private InputBitStreamSpeedTest() {}
- public static void main(final String[] arg) throws IOException {
- int k;
- final int n = Integer.parseInt(arg[0]);
- int i;
- final java.util.Random r = new java.util.Random();
- final ProgressLogger pl = new ProgressLogger();
- final int data1[] = new int[1000000];
- final int data2[] = new int[1000000];
- i = 1000000;
- while(i-- != 0) data2[i] = (data1[i] = r.nextInt(100)) + 1;
-
-
- k = 10;
- while(k-- != 0) {
+ private static final int DELTA_DISTR_SIZE = 1000000;
- i = n;
- pl.start();
- final OutputBitStream bos = new OutputBitStream(new FileOutputStream("test "), 16*1024);
- while(i-- != 0) bos.writeGamma(data1[i % 1000000]);
- bos.close();
- pl.done();
+ private static double[] delta_distr = new double[DELTA_DISTR_SIZE];
+ static {
+ double s = 0;
+ for (int i = 1; i < DELTA_DISTR_SIZE; i++) {
+ s += 1 / (2 * (i + 3) * (Fast.log2(i) + 2) * (Fast.log2(i) + 2));
+ delta_distr[i] = s;
+ }
- System.err.println("Written " + n + " integers on OutputBitStream in " + pl.millis() + " ms (" + (1000.0 * n) / pl.millis() + " int/s)");
+ for (int i = 1; i < DELTA_DISTR_SIZE; i++) delta_distr[i] /= s;
+ }
+ @SuppressWarnings("resource")
+ public static void main(final String[] arg) throws IOException {
+ final int n = Integer.parseInt(arg[0]);
+ final XoShiRo256PlusRandomGenerator r = new XoShiRo256PlusRandomGenerator(0);
+ final ProgressLogger pl = new ProgressLogger();
- pl.start();
- final InputBitStream bis = new InputBitStream(new FileInputStream("test "), 16*1024);
- i = n;
- while(i-- != 0) bis.readGamma();
- bis.close();
- pl.stop();
-
- System.err.println("Read " + n + " integers from InputBitStream in " + pl.millis() + " ms (" + (1000.0 * n) / pl.millis() + " int/s)");
-
+ final ZipfDistribution zipf2 = new ZipfDistribution(r, 1_000_000_000, 2);
+ final int data2[] = new int[n];
+ for(int i = 0; i < n; i++)
+ data2[i] = zipf2.sample() - 1;
+
+ final ZipfDistribution zipf12 = new ZipfDistribution(r, 1_000_000_000, 1.2);
+ final int data12[] = new int[n];
+ for (int i = 0; i < n; i++)
+ data12[i] = zipf12.sample() - 1;
+
+ final int dataDelta[] = new int[n];
+ for (int i = 0; i < n; i++) {
+ int p = DoubleArrays.binarySearch(delta_distr, r.nextDouble());
+ if (p < 0) p = -p - 2;
+ dataDelta[i] = p;
}
-/* k = 10;
- while(k-- != 0) {
-
- i = n;
- pl.reset();
- pl.start();
- BitOutputStream bos = new BitOutputStream(new FileOutputStream("test "));
- while(i-- != 0) bos.writeGamma(data2[i % 1000000]);
- bos.close();
- pl.stop();
-
- System.err.println("Written " + n + " integers on BitOutputStream in " + pl.millis() + " ms (" + (1000.0 * n) / pl.millis() + " int/s)");
-
-
- pl.reset();
- pl.start();
- BitInputStream bis = new BitInputStream(new FileInputStream("test "));
- i = n;
- while(i-- != 0) bis.readGamma();
- bis.close();
- pl.stop();
-
- System.err.println("Read " + n + " integers from BitInputStream in " + pl.millis() + " ms (" + (1000.0 * n) / pl.millis() + " int/s)");
-
- }*/
- }
+ final int dataUnary[] = new int[n];
+ for (int i = 0; i < n; i++) dataUnary[i] = Long.numberOfTrailingZeros(r.nextLong());
+
+ final FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream();
+ InputBitStream ibs;
+ OutputBitStream obs;
+ long u = 0;
+
+ for (int k = 10; k-- != 0;) {
+ fbaos.reset();
+ obs = new OutputBitStream(fbaos);
+ pl.start("Writing unary...");
+ for (final int x : dataUnary) obs.writeLongUnary(x);
+ pl.done(n);
+ obs.flush();
+
+ ibs = new InputBitStream(fbaos.array);
+ pl.start("Reading unary...");
+ for (int i = n; i-- != 0;) u += ibs.readLongUnary();
+ pl.done(n);
+
+ fbaos.reset();
+ obs = new OutputBitStream(fbaos);
+ pl.start("Writing ɣ...");
+ for (final int x : data2)
+ obs.writeLongGamma(x);
+ pl.done(n);
+ obs.flush();
+
+ ibs = new InputBitStream(fbaos.array);
+ pl.start("Reading ɣ...");
+ for (int i = n; i-- != 0;)
+ u += ibs.readLongGamma();
+ pl.done(n);
+
+ fbaos.reset();
+ obs = new OutputBitStream(fbaos);
+ pl.start("Writing δ..");
+ for (final int x : dataDelta)
+ obs.writeLongDelta(x);
+ pl.done(n);
+ obs.flush();
+
+ ibs = new InputBitStream(fbaos.array);
+ pl.start("Reading δ...");
+ for (int i = n; i-- != 0;)
+ u += ibs.readLongDelta();
+ pl.done(n);
+
+ fbaos.reset();
+ obs = new OutputBitStream(fbaos);
+ pl.start("Writing ζ..");
+ for (final int x : data12)
+ obs.writeLongZeta(x, 3);
+ pl.done(n);
+ obs.flush();
+
+ ibs = new InputBitStream(fbaos.array);
+ pl.start("Reading ζ...");
+ for (int i = n; i-- != 0;)
+ u += ibs.readLongZeta(3);
+ pl.done(n);
+ }
+ if (u == 0)
+ System.err.println();
+ }
}
-
View it on GitLab: https://salsa.debian.org/java-team/libdsiutils-java/-/commit/84510553b5b8210f8321428a96e90413b04bef43
--
View it on GitLab: https://salsa.debian.org/java-team/libdsiutils-java/-/commit/84510553b5b8210f8321428a96e90413b04bef43
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20250819/0d307e11/attachment.htm>
More information about the pkg-java-commits
mailing list