[Git][java-team/libfastutil-java][master] 3 commits: New upstream version 8.5.15+dfsg
Pierre Gruet (@pgt)
gitlab at salsa.debian.org
Sun Nov 3 21:07:43 GMT 2024
Pierre Gruet pushed to branch master at Debian Java Maintainers / libfastutil-java
Commits:
f1ff8669 by Pierre Gruet at 2024-11-03T20:51:57+01:00
New upstream version 8.5.15+dfsg
- - - - -
fe994e00 by Pierre Gruet at 2024-11-03T20:52:00+01:00
Update upstream source from tag 'upstream/8.5.15+dfsg'
Update to upstream version '8.5.15+dfsg'
with Debian dir 91acadb5da4566daf90369f9dd1e050e4d703fbd
- - - - -
774cc093 by Pierre Gruet at 2024-11-03T20:53:08+01:00
Upload to unstable
- - - - -
6 changed files:
- CHANGES
- build.properties
- debian/changelog
- src/it/unimi/dsi/fastutil/Arrays.java
- src/it/unimi/dsi/fastutil/HashCommon.java
- test/it/unimi/dsi/fastutil/ints/IntImmutableListTest.java
Changes:
=====================================
CHANGES
=====================================
@@ -1,3 +1,11 @@
+8.5.15
+
+- Fixed a very long-standing subtle bug that was causing unnecessary
+ rehashings on large tables. Maximum fills and backing-array sizes
+ were computed using float precision, rather than double precision,
+ making it impossible to represent all possible sizes exactly. Thanks
+ to Captain-S0L0 for reporting this bug.
+
8.5.14
- Potential improvements by array caching thanks to mouse0w0 at github.com.
=====================================
build.properties
=====================================
@@ -3,7 +3,7 @@ javadoc.base=/usr/share/javadoc
build.sysclasspath=ignore
-version=8.5.14
+version=8.5.15
dist=dist
src=src
=====================================
debian/changelog
=====================================
@@ -1,3 +1,9 @@
+libfastutil-java (8.5.15+dfsg-1) unstable; urgency=medium
+
+ * New upstream version 8.5.15+dfsg
+
+ -- Pierre Gruet <pgt at debian.org> Sun, 03 Nov 2024 20:52:57 +0100
+
libfastutil-java (8.5.14+dfsg-1) unstable; urgency=medium
* Team upload.
=====================================
src/it/unimi/dsi/fastutil/Arrays.java
=====================================
@@ -62,7 +62,7 @@ public class Arrays {
*
* @param arrayLength an array length (must be nonnegative).
* @param from a start index (inclusive).
- * @param to an end index (inclusive).
+ * @param to an end index (exclusive).
* @throws IllegalArgumentException if {@code from} is greater than {@code to}.
* @throws ArrayIndexOutOfBoundsException if {@code from} or {@code to} are greater than
* {@code arrayLength} or negative.
=====================================
src/it/unimi/dsi/fastutil/HashCommon.java
=====================================
@@ -156,7 +156,7 @@ public class HashCommon {
* @param x an integer smaller than or equal to 2<sup>30</sup>.
* @return the least power of two greater than or equal to the specified value.
*/
- public static int nextPowerOfTwo(int x) {
+ public static int nextPowerOfTwo(final int x) {
return 1 << (32 - Integer.numberOfLeadingZeros(x - 1));
}
@@ -167,7 +167,7 @@ public class HashCommon {
* @param x a long integer smaller than or equal to 2<sup>62</sup>.
* @return the least power of two greater than or equal to the specified value.
*/
- public static long nextPowerOfTwo(long x) {
+ public static long nextPowerOfTwo(final long x) {
return 1L << (64 - Long.numberOfLeadingZeros(x - 1));
}
@@ -180,8 +180,12 @@ public class HashCommon {
*/
public static int maxFill(final int n, final float f) {
/* We must guarantee that there is always at least
- * one free entry (even with pathological load factors). */
- return Math.min((int)Math.ceil(n * f), n - 1);
+ * one free entry (even with pathological load factors).
+ *
+ * The cast to double is essential to avoid a precision
+ * loss due to a cast to float before the call to Math.ceil.
+ */
+ return Math.min((int)Math.ceil(n * (double)f), n - 1);
}
/** Returns the maximum number of entries that can be filled before rehashing.
@@ -192,8 +196,12 @@ public class HashCommon {
*/
public static long maxFill(final long n, final float f) {
/* We must guarantee that there is always at least
- * one free entry (even with pathological load factors). */
- return Math.min((long)Math.ceil(n * f), n - 1);
+ * one free entry (even with pathological load factors).
+ *
+ * The cast to double is essential to avoid a precision
+ * loss due to a cast to float before the call to Math.ceil.
+ */
+ return Math.min((long)Math.ceil(n * (double)f), n - 1);
}
/** Returns the least power of two smaller than or equal to 2<sup>30</sup> and larger than or equal to {@code Math.ceil(expected / f)}.
@@ -204,7 +212,11 @@ public class HashCommon {
* @throws IllegalArgumentException if the necessary size is larger than 2<sup>30</sup>.
*/
public static int arraySize(final int expected, final float f) {
- final long s = Math.max(2, nextPowerOfTwo((long)Math.ceil(expected / f)));
+ /*
+ * The cast to double is essential to avoid a precision
+ * loss due to a cast to float before the call to Math.ceil.
+ */
+ final long s = Math.max(2, nextPowerOfTwo((long)Math.ceil(expected / (double)f)));
if (s > (1 << 30)) throw new IllegalArgumentException("Too large (" + expected + " expected elements with load factor " + f + ")");
return (int)s;
}
@@ -216,6 +228,10 @@ public class HashCommon {
* @return the minimum possible size for a backing big array.
*/
public static long bigArraySize(final long expected, final float f) {
- return nextPowerOfTwo((long)Math.ceil(expected / f));
+ /*
+ * The cast to double is essential to avoid a precision
+ * loss due to a cast to float before the call to Math.ceil.
+ */
+ return nextPowerOfTwo((long)Math.ceil(expected / (double)f));
}
}
=====================================
test/it/unimi/dsi/fastutil/ints/IntImmutableListTest.java
=====================================
@@ -111,7 +111,7 @@ public class IntImmutableListTest {
transformed = IntImmutableList.toListWithExpectedSize(baseList.intParallelStream().map(i -> i + 40), 50000);
assertEquals(expectedList, transformed);
}
-
+
@Test
public void testListIterator_testIteration() {
final IntImmutableList l = IntImmutableList.of(0, 1, 2, 3);
@@ -353,7 +353,7 @@ public class IntImmutableListTest {
final IntImmutableList l = IntImmutableList.of(0, 1, 2, 3, 4, 5);
final IntList sl = l.subList(1, 4);
final IntListIterator li = sl.listIterator(1);
- IntList consumer = new IntArrayList();
+ final IntList consumer = new IntArrayList();
li.forEachRemaining(consumer::add);
assertEquals(consumer, IntList.of(2, 3));
}
View it on GitLab: https://salsa.debian.org/java-team/libfastutil-java/-/compare/94a6fdfbdb3a747d23616a1964586b06baf23813...774cc093b02246c973db7f7ae8fa14d316858277
--
View it on GitLab: https://salsa.debian.org/java-team/libfastutil-java/-/compare/94a6fdfbdb3a747d23616a1964586b06baf23813...774cc093b02246c973db7f7ae8fa14d316858277
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/20241103/16a56daf/attachment.htm>
More information about the pkg-java-commits
mailing list