[Git][java-team/libfastutil-java][master] 7 commits: New upstream version 8.5.11+dfsg

Pierre Gruet (@pgt) gitlab at salsa.debian.org
Mon Dec 19 21:28:59 GMT 2022



Pierre Gruet pushed to branch master at Debian Java Maintainers / libfastutil-java


Commits:
4c79c6c4 by Pierre Gruet at 2022-12-18T15:26:08+01:00
New upstream version 8.5.11+dfsg
- - - - -
89072d4e by Pierre Gruet at 2022-12-18T15:26:12+01:00
Update upstream source from tag 'upstream/8.5.11+dfsg'

Update to upstream version '8.5.11+dfsg'
with Debian dir 32f5124ae2949be6b35e49eae60edb09b2db30cb
- - - - -
2c061abc by Pierre Gruet at 2022-12-18T15:27:08+01:00
Refreshing patches

- - - - -
8992ce9e by Pierre Gruet at 2022-12-18T15:28:15+01:00
Raising Standards version to 4.6.2 (no change)

- - - - -
1a2080cd by Pierre Gruet at 2022-12-18T15:28:30+01:00
Updating changelog

- - - - -
f229b20b by Pierre Gruet at 2022-12-18T16:09:21+01:00
Correcting the syntax of the lintian override for embedded JS

- - - - -
e936a95a by Pierre Gruet at 2022-12-18T16:09:37+01:00
Upload to unstable

- - - - -


30 changed files:

- .gitignore
- CHANGES
- build.properties
- build.xml
- debian/changelog
- debian/control
- debian/libfastutil-java-doc.lintian-overrides
- debian/patches/test_classpath.patch
- drv/AbstractCollection.drv
- drv/AbstractList.drv
- drv/ArrayList.drv
- drv/ArraySet.drv
- drv/BigArraysCommon.drv
- drv/BigLists.drv
- drv/ImmutableList.drv
- drv/OpenHashBigSet.drv
- drv/OpenHashMap.drv
- drv/OpenHashSet.drv
- makefile
- src/it/unimi/dsi/fastutil/Arrays.java
- src/it/unimi/dsi/fastutil/HashCommon.java
- test/it/unimi/dsi/fastutil/ints/Int2IntLinkedOpenHashMapTest.java
- test/it/unimi/dsi/fastutil/ints/IntArrayListTest.java
- test/it/unimi/dsi/fastutil/ints/IntArraySetTest.java
- + test/it/unimi/dsi/fastutil/ints/IntBigListsTest.java
- test/it/unimi/dsi/fastutil/ints/IntImmutableListTest.java
- test/it/unimi/dsi/fastutil/ints/IntLinkedOpenHashSetTest.java
- test/it/unimi/dsi/fastutil/objects/ObjectArrayListTest.java
- test/it/unimi/dsi/fastutil/objects/ObjectArraySetTest.java
- + test/it/unimi/dsi/fastutil/objects/ObjectImmutableListTest.java


Changes:

=====================================
.gitignore
=====================================
@@ -10,3 +10,9 @@ dist
 docs
 build
 bin
+fastutil-*.jar
+fastutil*.txt
+pom-*.xml
+.classpath
+.project
+.ant-targets-build.xml


=====================================
CHANGES
=====================================
@@ -1,3 +1,21 @@
+8.5.11
+
+- Hash-based containers now expose ensureCapacity().
+
+- HashCommon.nextPowerOf2() is now faster. Thanks to Richard Startin
+  for improving this method.
+
+- A very long-standing bug in linked hash containers has been fixed.
+  Methods removing the last or first entry would not update correctly
+  the pointer to the first (or last, respectively) item, leading to
+  incorrect iteration behavior when removing the last element of a 
+  container.
+
+8.5.10
+
+- Really fixed overflow bug in BigArrays.ensureOffsetLength(). Thanks
+  to Pierre Gruet for reporting this bug.
+
 8.5.9
 
 - Using BinIO to save arrays with a memory footprint larger than 2^31


=====================================
build.properties
=====================================
@@ -3,7 +3,7 @@ javadoc.base=/usr/share/javadoc
 
 build.sysclasspath=ignore
 
-version=8.5.9
+version=8.5.11
 
 dist=dist
 src=src


=====================================
build.xml
=====================================
@@ -1,5 +1,4 @@
-<project name="fastutil" default="jar" basedir="."
-         xmlns:artifact="antlib:org.apache.maven.artifact.ant">
+<project name="fastutil" default="jar" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
 
 	<property name="build.sysclasspath" value="ignore"/>
 	<property file="build.properties"/>
@@ -114,19 +113,9 @@
 		</copy>
 	</target>
 
-	<target name="deploy-core" depends="pom-core,dist-core" description="deploy core snapshot version to Maven snapshot repository (core)">
-		<artifact:mvn>
-			<arg value="org.apache.maven.plugins:maven-deploy-plugin:2.6:deploy-file" />
-			<arg value="-Durl=${maven-snapshots-repository-url}" />
-			<arg value="-DrepositoryId=${maven-snapshots-repository-id}" />
-			<arg value="-DpomFile=${build}/pom-core.xml" />
-			<arg value="-Dfile=${maven-core-jar}" />
-		</artifact:mvn>
-	</target>
-
 	<target name="stage-core" depends="pom-core,dist-core" description="deploy core release version to Maven staging repository (core)">
 		<!-- sign and deploy the main artifact -->
-		<artifact:mvn>
+		<artifact:mvn fork="true">
 			<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
 			<arg value="-Durl=${maven-staging-repository-url}" />
 			<arg value="-DrepositoryId=${maven-staging-repository-id}" />
@@ -136,7 +125,7 @@
 		</artifact:mvn>
 
 		<!-- sign and deploy the sources artifact -->
-		<artifact:mvn>
+		<artifact:mvn fork="true">
 			<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
 			<arg value="-Durl=${maven-staging-repository-url}" />
 			<arg value="-DrepositoryId=${maven-staging-repository-id}" />
@@ -147,7 +136,7 @@
 		</artifact:mvn>
 
 		<!-- sign and deploy the javadoc artifact -->
-		<artifact:mvn>
+		<artifact:mvn fork="true">
 			<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
 			<arg value="-Durl=${maven-staging-repository-url}" />
 			<arg value="-DrepositoryId=${maven-staging-repository-id}" />
@@ -158,19 +147,9 @@
 		</artifact:mvn>
 	</target>
 
-	<target name="deploy" depends="pom,dist" description="deploy snapshot version to Maven snapshot repository">
-		<artifact:mvn>
-			<arg value="org.apache.maven.plugins:maven-deploy-plugin:2.6:deploy-file" />
-			<arg value="-Durl=${maven-snapshots-repository-url}" />
-			<arg value="-DrepositoryId=${maven-snapshots-repository-id}" />
-			<arg value="-DpomFile=${build}/pom.xml" />
-			<arg value="-Dfile=${maven-jar}" />
-		</artifact:mvn>
-	</target>
-
 	<target name="stage" depends="pom,dist" description="deploy release version to Maven staging repository">
 		<!-- sign and deploy the main artifact -->
-		<artifact:mvn>
+		<artifact:mvn fork="true">
 			<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
 			<arg value="-Durl=${maven-staging-repository-url}" />
 			<arg value="-DrepositoryId=${maven-staging-repository-id}" />
@@ -180,7 +159,7 @@
 		</artifact:mvn>
 
 		<!-- sign and deploy the sources artifact -->
-		<artifact:mvn>
+		<artifact:mvn fork="true">
 			<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
 			<arg value="-Durl=${maven-staging-repository-url}" />
 			<arg value="-DrepositoryId=${maven-staging-repository-id}" />
@@ -191,7 +170,7 @@
 		</artifact:mvn>
 
 		<!-- sign and deploy the javadoc artifact -->
-		<artifact:mvn>
+		<artifact:mvn fork="true">
 			<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
 			<arg value="-Durl=${maven-staging-repository-url}" />
 			<arg value="-DrepositoryId=${maven-staging-repository-id}" />
@@ -202,9 +181,6 @@
 		</artifact:mvn>
 	</target>
 
-	<target name="deploy-all" depends="deploy-core,deploy" description="deploy all release versions to Maven staging repository">
-	</target>
-
 	<target name="stage-all" depends="stage-core,stage" description="stage all release versions to Maven staging repository">
 	</target>
 	<!-- ************************************** END OF MAVEN SH*T ************************************** -->


=====================================
debian/changelog
=====================================
@@ -1,3 +1,12 @@
+libfastutil-java (8.5.11+dfsg-1) unstable; urgency=medium
+
+  * New upstream version 8.5.11+dfsg
+  * Refreshing patches
+  * Raising Standards version to 4.6.2 (no change)
+  * Correcting the syntax of the Lintian override for embedded JS
+
+ -- Pierre Gruet <pgt at debian.org>  Sun, 18 Dec 2022 16:09:25 +0100
+
 libfastutil-java (8.5.9+dfsg-1) unstable; urgency=medium
 
   * New upstream version 8.5.9+dfsg


=====================================
debian/control
=====================================
@@ -13,7 +13,7 @@ Build-Depends: debhelper-compat (= 13),
                junit4 <!nocheck>,
                libhamcrest-java <!nocheck>,
                maven-repo-helper
-Standards-Version: 4.6.1
+Standards-Version: 4.6.2
 Rules-Requires-Root: no
 Vcs-Browser: https://salsa.debian.org/java-team/libfastutil-java
 Vcs-Git: https://salsa.debian.org/java-team/libfastutil-java.git


=====================================
debian/libfastutil-java-doc.lintian-overrides
=====================================
@@ -1,4 +1,4 @@
 # It would be too complicated to remove the javascript that is included in
 # javadocs, see the discussion on Debian Java mailing list starting at 
 # https://lists.debian.org/debian-java/2018/06/msg00020.html.
-embedded-javascript-library please use * [usr/share/doc/libfastutil-java/jquery/*]
+embedded-javascript-library please use * [usr/share/doc/libfastutil-java/script-dir/*]


=====================================
debian/patches/test_classpath.patch
=====================================
@@ -5,7 +5,7 @@ Last-Update: 2022-09-30
 
 --- a/build.xml
 +++ b/build.xml
-@@ -241,7 +241,7 @@
+@@ -217,7 +217,7 @@
  			debug="on"
  			deprecation="on"
  			optimize="on"
@@ -14,7 +14,7 @@ Last-Update: 2022-09-30
  			destdir="${build}"
  			memoryMaximumSize="2G"
  			fork="yes"
-@@ -298,8 +298,9 @@
+@@ -274,8 +274,9 @@
  		<junit printsummary="yes" fork="yes" haltonfailure="off"  haltonerror="off">
  			<classpath location="${build}"/>
  			<classpath location="${src}"/>


=====================================
drv/AbstractCollection.drv
=====================================
@@ -122,7 +122,11 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC extends AbstractCollection
 
 	@Override
 	public KEY_TYPE[] TO_KEY_ARRAY() {
-		return toArray((KEY_TYPE[]) null);
+		final int size = size();
+		if (size == 0) return ARRAYS.EMPTY_ARRAY;
+		final KEY_TYPE a[] = new KEY_TYPE[size];
+		ITERATORS.unwrap(iterator(), a);
+		return a;
 	}
 
 	/** {@inheritDoc}


=====================================
drv/AbstractList.drv
=====================================
@@ -346,6 +346,8 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_
 	@Override
 	public Object[] toArray() {
 		final int size = size();
+		// A subtle part of the spec says the returned array must be Object[] exactly.
+		if (size == 0) return it.unimi.dsi.fastutil.objects.ObjectArrays.EMPTY_ARRAY;
 		Object[] ret = new Object[size];
 		getElements(0, ret, 0, size);
 		return ret;
@@ -484,6 +486,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_
 	@Override
 	public KEY_TYPE[] TO_KEY_ARRAY() {
 		final int size = size();
+		if (size == 0) return ARRAYS.EMPTY_ARRAY;
 		KEY_TYPE[] ret = new KEY_TYPE[size];
 		getElements(0, ret, 0, size);
 		return ret;


=====================================
drv/ArrayList.drv
=====================================
@@ -918,8 +918,10 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
 
 	@Override
 	public Object[] toArray() {
+		final int size = size();
 		// A subtle part of the spec says the returned array must be Object[] exactly.
-		return Arrays.copyOf(a, size(), Object[].class);
+		if (size == 0) return it.unimi.dsi.fastutil.objects.ObjectArrays.EMPTY_ARRAY;
+		return Arrays.copyOf(a, size, Object[].class);
 	}
 
 	SUPPRESS_WARNINGS_KEY_UNCHECKED


=====================================
drv/ArraySet.drv
=====================================
@@ -373,6 +373,7 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j
 #if KEYS_PRIMITIVE
 	@Override
 	public KEY_TYPE[] TO_KEY_ARRAY() {
+		if (size == 0) return ARRAYS.EMPTY_ARRAY;
 		return java.util.Arrays.copyOf(a, size);
 	}
 
@@ -385,7 +386,9 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j
 #else // KEYS_REFERENCE
 	@Override
 	public Object[] toArray() {
+		final int size = size();
 		// A subtle part of the spec says the returned array must be Object[] exactly.
+		if (size == 0) return it.unimi.dsi.fastutil.objects.ObjectArrays.EMPTY_ARRAY;
 		return java.util.Arrays.copyOf(a, size, Object[].class);
 	}
 


=====================================
drv/BigArraysCommon.drv
=====================================
@@ -317,7 +317,7 @@ public class BigArrays {
 	 * This method may be used whenever a big array range check is needed.
 	 *
 	 * @param bigArrayLength
-	 *            a big-array length.
+	 *            a big-array length (must be nonnegative).
 	 * @param from
 	 *            a start index (inclusive).
 	 * @param to
@@ -327,8 +327,11 @@ public class BigArrays {
 	 * @throws ArrayIndexOutOfBoundsException
 	 *             if {@code from} or {@code to} are greater than
 	 *             {@code bigArrayLength} or negative.
+	 *
+	 * @implNote An {@code assert} checks whether {@code bigArrayLength} is nonnegative.
 	 */
 	public static void ensureFromTo(final long bigArrayLength, final long from, final long to) {
+		assert bigArrayLength >= 0;
 		if (from < 0) throw new ArrayIndexOutOfBoundsException("Start index (" + from + ") is negative");
 		if (from > to) throw new IllegalArgumentException("Start index (" + from + ") is greater than end index (" + to + ")");
 		if (to > bigArrayLength) throw new ArrayIndexOutOfBoundsException("End index (" + to + ") is greater than big-array length (" + bigArrayLength + ")");
@@ -342,7 +345,7 @@ public class BigArrays {
 	 * This method may be used whenever a big array range check is needed.
 	 *
 	 * @param bigArrayLength
-	 *            a big-array length.
+	 *            a big-array length (must be nonnegative).
 	 * @param offset
 	 *            a start index for the fragment
 	 * @param length
@@ -353,11 +356,14 @@ public class BigArrays {
 	 *             if {@code offset} is negative or {@code offset} +
 	 *             {@code length} is greater than
 	 *             {@code bigArrayLength}.
+	 *
+	 * @implNote An {@code assert} checks whether {@code bigArrayLength} is nonnegative.
 	 */
 	public static void ensureOffsetLength(final long bigArrayLength, final long offset, final long length) {
+		assert bigArrayLength >= 0;
 		if (offset < 0) throw new ArrayIndexOutOfBoundsException("Offset (" + offset + ") is negative");
 		if (length < 0) throw new IllegalArgumentException("Length (" + length + ") is negative");
-		if (offset + length > bigArrayLength) throw new ArrayIndexOutOfBoundsException("Last index (" + (offset + length) + ") is greater than big-array length (" + bigArrayLength + ")");
+		if (length > bigArrayLength - offset) throw new ArrayIndexOutOfBoundsException("Last index (" + Long.toUnsignedString(offset + length) + ") is greater than big-array length (" + bigArrayLength + ")");
 	}
 
 	/**


=====================================
drv/BigLists.drv
=====================================
@@ -252,8 +252,7 @@ public final class BIG_LISTS {
 
 		@Override
 		public KEY_TYPE[] TO_KEY_ARRAY() {
-			KEY_TYPE a[] = new KEY_TYPE[1];
-			a[0] = element;
+			KEY_TYPE a[] = {element};
 			return a;
 		}
 


=====================================
drv/ImmutableList.drv
=====================================
@@ -264,6 +264,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE
 #if KEYS_PRIMITIVE
 	@Override
 	public KEY_TYPE[] TO_KEY_ARRAY() {
+		if (a.length == 0) return ARRAYS.EMPTY_ARRAY;
 		return a.clone();
 	}
 
@@ -277,9 +278,8 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE
 	@Override
 	public Object[] toArray() {
 		// A subtle part of the spec says the returned array must be Object[] exactly.
-		if (a.getClass().equals(Object[].class)) {
-			return a.clone();
-		}
+		if (a.length == 0) return it.unimi.dsi.fastutil.objects.ObjectArrays.EMPTY_ARRAY;
+		if (a.getClass() == Object[].class) return a.clone();
 		return java.util.Arrays.copyOf(a, a.length, Object[].class);
 	}
 


=====================================
drv/OpenHashBigSet.drv
=====================================
@@ -341,7 +341,12 @@ public class OPEN_HASH_BIG_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC impl
 		return containsNull ? size - 1 : size;
 	}
 
-	private void ensureCapacity(final long capacity) {
+	/** Ensures that this big set can hold a certain number of elements without rehashing.
+	 *
+	 * @param capacity a number of elements; there will be no rehashing unless
+	 * the set {@linkplain #size64() size} exceeds this number.
+	 */
+	public void ensureCapacity(final long capacity) {
 		final long needed = bigArraySize(capacity, f);
 		if (needed > n) rehash(needed);
 	}


=====================================
drv/OpenHashMap.drv
=====================================
@@ -504,7 +504,12 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE
 		return containsNullKey ? size - 1 : size;
 	}
 
-	private void ensureCapacity(final int capacity) {
+	/** Ensures that this map can hold a certain number of keys without rehashing.
+	 *
+	 * @param capacity a number of keys; there will be no rehashing unless
+	 * the map {@linkplain #size() size} exceeds this number.
+	 */
+	public void ensureCapacity(final int capacity) {
 		final int needed = arraySize(capacity, f);
 		if (needed > n) rehash(needed);
 	}
@@ -750,12 +755,17 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE
 	public VALUE_GENERIC_TYPE REMOVE_FIRST_VALUE() {
 		if (size == 0) throw new NoSuchElementException();
 		final int pos = first;
+
 		// Abbreviated version of fixPointers(pos)
-		first = GET_NEXT(link[pos]);
-		if (0 <= first) {
-			// Special case of SET_PREV(link[first], -1)
-			link[first] |= (-1 & 0xFFFFFFFFL) << 32;
+		if (size == 1) first = last = -1;
+		else {
+			first = GET_NEXT(link[pos]);
+			if (0 <= first) {
+				// Special case of SET_PREV(link[first], -1)
+				link[first] |= (-1 & 0xFFFFFFFFL) << 32;
+			}
 		}
+
 		size--;
 		final VALUE_GENERIC_TYPE v = value[pos];
 		if (pos == n) {
@@ -779,12 +789,17 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE
 	public VALUE_GENERIC_TYPE REMOVE_LAST_VALUE() {
 		if (size == 0) throw new NoSuchElementException();
 		final int pos = last;
+
 		// Abbreviated version of fixPointers(pos)
-		last = GET_PREV(link[pos]);
-		if (0 <= last) {
-			// Special case of SET_NEXT(link[last], -1)
-			link[last] |= -1 & 0xFFFFFFFFL;
+		if (size == 1) first = last = -1;
+		else {
+			last = GET_PREV(link[pos]);
+			if (0 <= last) {
+				// Special case of SET_NEXT(link[last], -1)
+				link[last] |= -1 & 0xFFFFFFFFL;
+			}
 		}
+
 		size--;
 		final VALUE_GENERIC_TYPE v = value[pos];
 		if (pos == n) {


=====================================
drv/OpenHashSet.drv
=====================================
@@ -756,7 +756,12 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen
 		return containsNull ? size - 1 : size;
 	}
 
-	private void ensureCapacity(final int capacity) {
+	/** Ensures that this set can hold a certain number of elements without rehashing.
+	 *
+	 * @param capacity a number of elements; there will be no rehashing unless
+	 * the set {@linkplain #size() size} exceeds this number.
+	 */
+	public void ensureCapacity(final int capacity) {
 		final int needed = arraySize(capacity, f);
 		if (needed > n) rehash(needed);
 	}
@@ -1011,12 +1016,17 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen
 	public KEY_GENERIC_TYPE REMOVE_FIRST_KEY() {
 		if (size == 0) throw new NoSuchElementException();
 		final int pos = first;
+
 		// Abbreviated version of fixPointers(pos)
-		first = GET_NEXT(link[pos]);
-		if (0 <= first) {
-			// Special case of SET_PREV(link[first], -1)
-			link[first] |= (-1 & 0xFFFFFFFFL) << 32;
+		if (size == 1) first = last = -1;
+		else {
+			first = GET_NEXT(link[pos]);
+			if (0 <= first) {
+				// Special case of SET_PREV(link[first], -1)
+				link[first] |= (-1 & 0xFFFFFFFFL) << 32;
+			}
 		}
+
 		final KEY_GENERIC_TYPE k = key[pos];
 		size--;
 		if (KEY_EQUALS_NULL(k)) {
@@ -1035,12 +1045,17 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen
 	public KEY_GENERIC_TYPE REMOVE_LAST_KEY() {
 		if (size == 0) throw new NoSuchElementException();
 		final int pos = last;
+
 		// Abbreviated version of fixPointers(pos)
-		last = GET_PREV(link[pos]);
-		if (0 <= last) {
-			// Special case of SET_NEXT(link[last], -1)
-			link[last] |= -1 & 0xFFFFFFFFL;
+		if (size == 1) first = last = -1;
+		else {
+			last = GET_PREV(link[pos]);
+			if (0 <= last) {
+				// Special case of SET_NEXT(link[last], -1)
+				link[last] |= -1 & 0xFFFFFFFFL;
+			}
 		}
+
 		final KEY_GENERIC_TYPE k = key[pos];
 		size--;
 		if (KEY_EQUALS_NULL(k)) {


=====================================
makefile
=====================================
@@ -101,6 +101,7 @@ source:
 
 binary:
 	make -s clean sources format
+	ant clean junit
 	ant clean osgi javadoc
 	-rm -f fastutil-$(version)
 	ln -s . fastutil-$(version)


=====================================
src/it/unimi/dsi/fastutil/Arrays.java
=====================================
@@ -49,25 +49,28 @@ public class Arrays {
 	public static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
 
 	/**
-	 * Ensures that a range given by its first (inclusive) and last (exclusive) elements fits an
-	 * array of given length.
+	 * Ensures that a range given by its first (inclusive) and last (exclusive) elements fits an array
+	 * of given length.
 	 *
 	 * <p>
 	 * This method may be used whenever an array range check is needed.
 	 *
 	 * <p>
 	 * In Java 9 and up, this method should be considered deprecated in favor of the
-	 * {@link java.util.Objects#checkFromToIndex(int, int, int)} method, which may be intrinsified
-	 * in recent JVMs.
+	 * {@link java.util.Objects#checkFromToIndex(int, int, int)} method, which may be intrinsified in
+	 * recent JVMs.
 	 *
-	 * @param arrayLength an array length.
+	 * @param arrayLength an array length (must be nonnegative).
 	 * @param from a start index (inclusive).
 	 * @param to an end index (inclusive).
 	 * @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.
+	 *
+	 * @implNote An {@code assert} checks whether {@code arrayLength} is nonnegative.
 	 */
 	public static void ensureFromTo(final int arrayLength, final int from, final int to) {
+		assert arrayLength >= 0;
 		// When Java 9 becomes the minimum, use Objects#checkFromToIndex​​, as that can be an intrinsic
 		if (from < 0) throw new ArrayIndexOutOfBoundsException("Start index (" + from + ") is negative");
 		if (from > to) throw new IllegalArgumentException("Start index (" + from + ") is greater than end index (" + to + ")");
@@ -82,17 +85,20 @@ public class Arrays {
 	 *
 	 * <p>
 	 * In Java 9 and up, this method should be considered deprecated in favor of the
-	 * {@link java.util.Objects#checkFromIndexSize(int, int, int)} method, which may be intrinsified
-	 * in recent JVMs.
+	 * {@link java.util.Objects#checkFromIndexSize(int, int, int)} method, which may be intrinsified in
+	 * recent JVMs.
 	 *
-	 * @param arrayLength an array length.
+	 * @param arrayLength an array length (must be nonnegative).
 	 * @param offset a start index for the fragment
 	 * @param length a length (the number of elements in the fragment).
 	 * @throws IllegalArgumentException if {@code length} is negative.
 	 * @throws ArrayIndexOutOfBoundsException if {@code offset} is negative or
 	 *             {@code offset}+{@code length} is greater than {@code arrayLength}.
+	 *
+	 * @implNote An {@code assert} checks whether {@code arrayLength} is nonnegative.
 	 */
 	public static void ensureOffsetLength(final int arrayLength, final int offset, final int length) {
+		assert arrayLength >= 0;
 		// When Java 9 becomes the minimum, use Objects#checkFromIndexSize​, as that can be an intrinsic
 		if (offset < 0) throw new ArrayIndexOutOfBoundsException("Offset (" + offset + ") is negative");
 		if (length < 0) throw new IllegalArgumentException("Length (" + length + ") is negative");


=====================================
src/it/unimi/dsi/fastutil/HashCommon.java
=====================================
@@ -157,13 +157,7 @@ public class HashCommon {
 	 * @return the least power of two greater than or equal to the specified value.
 	 */
 	public static int nextPowerOfTwo(int x) {
-		if (x == 0) return 1;
-		x--;
-		x |= x >> 1;
-		x |= x >> 2;
-		x |= x >> 4;
-		x |= x >> 8;
-		return (x | x >> 16) + 1;
+		return 1 << (32 - Integer.numberOfLeadingZeros(x - 1));
 	}
 
 	/** Returns the least power of two greater than or equal to the specified value.
@@ -174,14 +168,7 @@ public class HashCommon {
 	 * @return the least power of two greater than or equal to the specified value.
 	 */
 	public static long nextPowerOfTwo(long x) {
-		if (x == 0) return 1;
-		x--;
-		x |= x >> 1;
-		x |= x >> 2;
-		x |= x >> 4;
-		x |= x >> 8;
-		x |= x >> 16;
-		return (x | x >> 32) + 1;
+		return 1L << (64 - Long.numberOfLeadingZeros(x - 1));
 	}
 
 


=====================================
test/it/unimi/dsi/fastutil/ints/Int2IntLinkedOpenHashMapTest.java
=====================================
@@ -32,7 +32,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntMap.Entry;
 public class Int2IntLinkedOpenHashMapTest {
 	@Test
 	public void testContainsValue() {
-		Int2IntLinkedOpenHashMap m = new Int2IntLinkedOpenHashMap(Hash.DEFAULT_INITIAL_SIZE);
+		final Int2IntLinkedOpenHashMap m = new Int2IntLinkedOpenHashMap(Hash.DEFAULT_INITIAL_SIZE);
 		assertEquals(0, m.put(0, 2));
 		assertEquals(0, m.put(1, 3));
 		assertTrue(m.containsValue(2));
@@ -86,7 +86,7 @@ public class Int2IntLinkedOpenHashMapTest {
 
 	@Test
 	public void testWrapAround() {
-		Int2IntLinkedOpenHashMap m = new Int2IntLinkedOpenHashMap(4, .5f);
+		final Int2IntLinkedOpenHashMap m = new Int2IntLinkedOpenHashMap(4, .5f);
 		assertEquals(8, m.n);
 		// The following code inverts HashCommon.phiMix() and places strategically keys in slots 6, 7 and 0
 		m.put(HashCommon.invMix(6), 0);
@@ -95,9 +95,9 @@ public class Int2IntLinkedOpenHashMapTest {
 		assertNotEquals(0, m.key[0]);
 		assertNotEquals(0, m.key[6]);
 		assertNotEquals(0, m.key[7]);
-		IntOpenHashSet keys = new IntOpenHashSet(m.keySet());
-		IntIterator iterator = m.keySet().iterator();
-		IntOpenHashSet t = new IntOpenHashSet();
+		final IntOpenHashSet keys = new IntOpenHashSet(m.keySet());
+		final IntIterator iterator = m.keySet().iterator();
+		final IntOpenHashSet t = new IntOpenHashSet();
 		t.add(iterator.nextInt());
 		t.add(iterator.nextInt());
 		// Originally, this remove would move the entry in slot 0 in slot 6 and we would return the entry in 0 twice
@@ -108,7 +108,7 @@ public class Int2IntLinkedOpenHashMapTest {
 
 	@Test
 	public void testWrapAround2() {
-		Int2IntLinkedOpenHashMap m = new Int2IntLinkedOpenHashMap(4, .75f);
+		final Int2IntLinkedOpenHashMap m = new Int2IntLinkedOpenHashMap(4, .75f);
 		assertEquals(8, m.n);
 		// The following code inverts HashCommon.phiMix() and places strategically keys in slots 4, 5, 6, 7 and 0
 		m.put(HashCommon.invMix(4), 0);
@@ -122,9 +122,9 @@ public class Int2IntLinkedOpenHashMapTest {
 		assertNotEquals(0, m.key[6]);
 		assertNotEquals(0, m.key[7]);
 		//System.err.println(Arraym.toString(m.key));
-		IntOpenHashSet keys = new IntOpenHashSet(m.keySet());
-		IntIterator iterator = m.keySet().iterator();
-		IntOpenHashSet t = new IntOpenHashSet();
+		final IntOpenHashSet keys = new IntOpenHashSet(m.keySet());
+		final IntIterator iterator = m.keySet().iterator();
+		final IntOpenHashSet t = new IntOpenHashSet();
 		assertTrue(t.add(iterator.nextInt()));
 		iterator.remove();
 		//System.err.println(Arraym.toString(m.key));
@@ -143,7 +143,7 @@ public class Int2IntLinkedOpenHashMapTest {
 
 	@Test
 	public void testWrapAround3() {
-		Int2IntLinkedOpenHashMap m = new Int2IntLinkedOpenHashMap(4, .75f);
+		final Int2IntLinkedOpenHashMap m = new Int2IntLinkedOpenHashMap(4, .75f);
 		assertEquals(8, m.n);
 		// The following code inverts HashCommon.phiMix() and places strategically keys in slots 5, 6, 7, 0 and 1
 		m.put(HashCommon.invMix(5), 0);
@@ -157,9 +157,9 @@ public class Int2IntLinkedOpenHashMapTest {
 		assertNotEquals(0, m.key[0]);
 		assertNotEquals(0, m.key[1]);
 		//System.err.println(Arraym.toString(m.key));
-		IntOpenHashSet keys = new IntOpenHashSet(m.keySet());
-		IntIterator iterator = m.keySet().iterator();
-		IntOpenHashSet t = new IntOpenHashSet();
+		final IntOpenHashSet keys = new IntOpenHashSet(m.keySet());
+		final IntIterator iterator = m.keySet().iterator();
+		final IntOpenHashSet t = new IntOpenHashSet();
 		assertTrue(t.add(iterator.nextInt()));
 		iterator.remove();
 		//System.err.println(Arraym.toString(m.key));
@@ -187,16 +187,24 @@ public class Int2IntLinkedOpenHashMapTest {
 		m.int2IntEntrySet().forEach(new Consumer<Int2IntMap.Entry>() {
 			int i = a.length;
 			@Override
-			public void accept(Entry t) {
+			public void accept(final Entry t) {
 				assertEquals(--i, t.getIntKey());
 			}
 		});
 		m.int2IntEntrySet().fastForEach(new Consumer<Int2IntMap.Entry>() {
 			int i = a.length;
 			@Override
-			public void accept(Entry t) {
+			public void accept(final Entry t) {
 				assertEquals(--i, t.getIntKey());
 			}
 		});
 	}
+
+	@Test
+	public void testRemoveLast() {
+		final Int2IntLinkedOpenHashMap s = new Int2IntLinkedOpenHashMap();
+		s.put(0, 0);
+		s.removeLastInt();
+		assertFalse(s.int2IntEntrySet().iterator().hasNext());
+	}
 }


=====================================
test/it/unimi/dsi/fastutil/ints/IntArrayListTest.java
=====================================
@@ -600,4 +600,9 @@ public class IntArrayListTest {
 	public void testLegacyMainMethodTests() throws Exception {
 		MainRunner.callMainIfExists(IntArrayList.class, "test", /*num=*/"500", /*seed=*/"939384");
 	}
+
+	@Test
+	public void testZeroLengthToArray() {
+		assertSame(IntArrays.EMPTY_ARRAY, new IntArrayList().toIntArray());
+	}
 }


=====================================
test/it/unimi/dsi/fastutil/ints/IntArraySetTest.java
=====================================
@@ -19,6 +19,7 @@ package it.unimi.dsi.fastutil.ints;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
@@ -65,8 +66,8 @@ public class IntArraySetTest {
 			assertTrue(s.contains(1));
 			assertTrue(s.contains(2));
 			assertTrue(s.contains(3));
-			int[] expectedArray = i == 0 ? new int[] { 1, 2, 3 } : new int[] { 0, 1, 2, 3 };
-			IntSet expected = new IntOpenHashSet(expectedArray);
+			final int[] expectedArray = i == 0 ? new int[] { 1, 2, 3 } : new int[] { 0, 1, 2, 3 };
+			final IntSet expected = new IntOpenHashSet(expectedArray);
 			assertEquals(expected, s);
 			assertEquals(s, expected);
 			assertEquals(expected, new IntOpenHashSet(s.iterator()));
@@ -191,4 +192,9 @@ public class IntArraySetTest {
 		final IntArraySet s = IntArraySet.ofUnchecked(0, 0);
 		assertEquals(new IntArraySet(new int[] { 0 , 0 }), s);
 	}
+
+	@Test
+	public void testZeroLengthToArray() {
+		assertSame(IntArrays.EMPTY_ARRAY, new IntArraySet().toIntArray());
+	}
 }


=====================================
test/it/unimi/dsi/fastutil/ints/IntBigListsTest.java
=====================================
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2017-2022 Sebastiano Vigna
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package it.unimi.dsi.fastutil.ints;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+
+public class IntBigListsTest {
+
+	@Test
+	public void testSingletonToArray() {
+		assertArrayEquals(new int[] { 1 }, IntBigLists.singleton(1).toIntArray());
+	}
+
+}
\ No newline at end of file


=====================================
test/it/unimi/dsi/fastutil/ints/IntImmutableListTest.java
=====================================
@@ -16,10 +16,11 @@
 
 package it.unimi.dsi.fastutil.ints;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
@@ -313,4 +314,9 @@ public class IntImmutableListTest {
 		assertTrue(baseList.compareTo(greaterBecauseItIsLarger) < 0);
 		assertTrue(baseList.compareTo(equalList) == 0);
 	}
+
+	@Test
+	public void testZeroLengthToArray() {
+		assertSame(IntArrays.EMPTY_ARRAY, IntImmutableList.of().toIntArray());
+	}
 }


=====================================
test/it/unimi/dsi/fastutil/ints/IntLinkedOpenHashSetTest.java
=====================================
@@ -35,7 +35,7 @@ public class IntLinkedOpenHashSetTest {
 	@Test
 	public void testStrangeRetainAllCase() {
 
-		IntArrayList initialElements = IntArrayList.wrap(new int[] { 586, 940,
+		final IntArrayList initialElements = IntArrayList.wrap(new int[] { 586, 940,
 				1086, 1110, 1168, 1184, 1185, 1191, 1196, 1229, 1237, 1241,
 				1277, 1282, 1284, 1299, 1308, 1309, 1310, 1314, 1328, 1360,
 				1366, 1370, 1378, 1388, 1392, 1402, 1406, 1411, 1426, 1437,
@@ -57,11 +57,11 @@ public class IntLinkedOpenHashSetTest {
 				7094, 7379, 7384, 7388, 7394, 7414, 7419, 7458, 7459, 7466,
 				7467 });
 
-		IntArrayList retainElements = IntArrayList.wrap(new int[] { 586 });
+		final IntArrayList retainElements = IntArrayList.wrap(new int[] { 586 });
 
 		// Initialize both implementations with the same data
-		IntLinkedOpenHashSet instance = new IntLinkedOpenHashSet(initialElements);
-		IntRBTreeSet referenceInstance = new IntRBTreeSet(initialElements);
+		final IntLinkedOpenHashSet instance = new IntLinkedOpenHashSet(initialElements);
+		final IntRBTreeSet referenceInstance = new IntRBTreeSet(initialElements);
 
 		instance.retainAll(retainElements);
 		referenceInstance.retainAll(retainElements);
@@ -83,10 +83,10 @@ public class IntLinkedOpenHashSetTest {
 	}
 
 	@SuppressWarnings({ "unchecked", "deprecation" })
-	private static void test(int n, float f) throws IOException, ClassNotFoundException {
+	private static void test(final int n, final float f) throws IOException, ClassNotFoundException {
 		int c;
 		IntLinkedOpenHashSet s = new IntLinkedOpenHashSet(Hash.DEFAULT_INITIAL_SIZE, f);
-		java.util.Set<Integer> t = new java.util.LinkedHashSet<>();
+		final java.util.Set<Integer> t = new java.util.LinkedHashSet<>();
 		/* First of all, we fill t with random data. */
 		for (int i = 0; i < f * n; i++)
 			t.add((Integer.valueOf(genKey())));
@@ -95,14 +95,13 @@ public class IntLinkedOpenHashSetTest {
 		assertTrue("Error: !m.equals(t) after insertion", s.equals(t));
 		assertTrue("Error: !t.equals(m) after insertion", t.equals(s));
 		/* Now we check that m actually holds that data. */
-		for (java.util.Iterator i = t.iterator(); i.hasNext();) {
-			Object e = i.next();
+		for (final Object e : t) {
 			assertTrue("Error: m and t differ on a key (" + e + ") after insertion (iterating on t)", s.contains(e));
 		}
 		/* Now we check that m actually holds that data, but iterating on m. */
 		c = 0;
-		for (java.util.Iterator i = s.iterator(); i.hasNext();) {
-			Object e = i.next();
+		for (final java.util.Iterator i = s.iterator(); i.hasNext();) {
+			final Object e = i.next();
 			c++;
 			assertTrue("Error: m and t differ on a key (" + e + ") after insertion (iterating on m)", t.contains(e));
 		}
@@ -112,7 +111,7 @@ public class IntLinkedOpenHashSetTest {
 		 * use the polymorphic method.
 		 */
 		for (int i = 0; i < n; i++) {
-			int T = genKey();
+			final int T = genKey();
 			assertTrue("Error: divergence in keys between t and m (polymorphic method)", s.contains(T) == t.contains((Integer.valueOf(T))));
 		}
 		/*
@@ -120,7 +119,7 @@ public class IntLinkedOpenHashSetTest {
 		 * m we use the standard method.
 		 */
 		for (int i = 0; i < n; i++) {
-			int T = genKey();
+			final int T = genKey();
 			assertTrue("Error: divergence between t and m (standard method)", s.contains((Integer.valueOf(T))) == t.contains((Integer.valueOf(T))));
 		}
 		/* Now we put and remove random data in m and t, checking that the result is the same. */
@@ -133,30 +132,29 @@ public class IntLinkedOpenHashSetTest {
 		assertTrue("Error: !m.equals(t) after removal", s.equals(t));
 		assertTrue("Error: !t.equals(m) after removal", t.equals(s));
 		/* Now we check that m actually holds that data. */
-		for (java.util.Iterator i = t.iterator(); i.hasNext();) {
-			Object e = i.next();
+		for (final Object e : t) {
 			assertTrue("Error: m and t differ on a key (" + e + ") after removal (iterating on t)", s.contains(e));
 		}
 		/* Now we check that m actually holds that data, but iterating on m. */
-		for (java.util.Iterator i = s.iterator(); i.hasNext();) {
-			Object e = i.next();
+		for (final java.util.Iterator i = s.iterator(); i.hasNext();) {
+			final Object e = i.next();
 			assertTrue("Error: m and t differ on a key (" + e + ") after removal (iterating on m)", t.contains(e));
 		}
 		/* Now we make m into an array, make it again a set and check it is OK. */
-		int a[] = s.toIntArray();
+		final int a[] = s.toIntArray();
 		assertEquals("Error: toArray() output (or array-based constructor) is not OK", new IntLinkedOpenHashSet(a), s);
 		/* Now we check cloning. */
 		assertTrue("Error: m does not equal m.clone()", s.equals(s.clone()));
 		assertTrue("Error: m.clone() does not equal m", s.clone().equals(s));
-		int h = s.hashCode();
+		final int h = s.hashCode();
 		/* Now we save and read m. */
-		java.io.File ff = new java.io.File("it.unimi.dsi.fastutil.test.junit." + s.getClass().getSimpleName() + "." + n);
-		java.io.OutputStream os = new java.io.FileOutputStream(ff);
-		java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream(os);
+		final java.io.File ff = new java.io.File("it.unimi.dsi.fastutil.test.junit." + s.getClass().getSimpleName() + "." + n);
+		final java.io.OutputStream os = new java.io.FileOutputStream(ff);
+		final java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream(os);
 		oos.writeObject(s);
 		oos.close();
-		java.io.InputStream is = new java.io.FileInputStream(ff);
-		java.io.ObjectInputStream ois = new java.io.ObjectInputStream(is);
+		final java.io.InputStream is = new java.io.FileInputStream(ff);
+		final java.io.ObjectInputStream ois = new java.io.ObjectInputStream(is);
 		s = (IntLinkedOpenHashSet)ois.readObject();
 		ois.close();
 		ff.delete();
@@ -164,8 +162,8 @@ public class IntLinkedOpenHashSetTest {
 
 		assertEquals("Error: clone()", s, s.clone());
 		/* Now we check that m actually holds that data, but iterating on m. */
-		for (java.util.Iterator i = s.iterator(); i.hasNext();) {
-			Object e = i.next();
+		for (final java.util.Iterator i = s.iterator(); i.hasNext();) {
+			final Object e = i.next();
 			assertTrue("Error: m and t differ on a key (" + e + ") after save/read", t.contains(e));
 		}
 		/* Now we put and remove random data in m and t, checking that the result is the same. */
@@ -243,7 +241,7 @@ public class IntLinkedOpenHashSetTest {
 		assertTrue("Error: ! m.equals(t) after iteration", s.equals(t));
 		assertTrue("Error: ! t.equals(m) after iteration", t.equals(s));
 		/* Now we take out of m everything, and check that it is empty. */
-		for (java.util.Iterator i = s.iterator(); i.hasNext();) {
+		for (final java.util.Iterator i = s.iterator(); i.hasNext();) {
 			i.next();
 			i.remove();
 		}
@@ -291,7 +289,7 @@ public class IntLinkedOpenHashSetTest {
 	@SuppressWarnings("deprecation")
 	@Test
 	public void testAdd() {
-		IntLinkedOpenHashSet s = new IntLinkedOpenHashSet(Hash.DEFAULT_INITIAL_SIZE);
+		final IntLinkedOpenHashSet s = new IntLinkedOpenHashSet(Hash.DEFAULT_INITIAL_SIZE);
 		assertTrue(s.add(0));
 		assertTrue(s.contains(0));
 		assertFalse(s.contains(1));
@@ -302,7 +300,7 @@ public class IntLinkedOpenHashSetTest {
 
 	@Test
 	public void testRemove() {
-		IntLinkedOpenHashSet s = new IntLinkedOpenHashSet(Hash.DEFAULT_INITIAL_SIZE);
+		final IntLinkedOpenHashSet s = new IntLinkedOpenHashSet(Hash.DEFAULT_INITIAL_SIZE);
 		for(int i = 0; i < 100; i++) assertTrue(s.add(i));
 		for(int i = 0; i < 100; i++) assertFalse(s.remove(100 + i));
 		assertEquals(0, s.firstInt());
@@ -316,7 +314,7 @@ public class IntLinkedOpenHashSetTest {
 		for(int i = -1; i <= 1; i++) assertTrue(s.add(i));
 		assertTrue(s.remove(0));
 		IntListIterator iterator = s.iterator();
-		IntOpenHashSet z = new IntOpenHashSet();
+		final IntOpenHashSet z = new IntOpenHashSet();
 		z.add(iterator.nextInt());
 		z.add(iterator.nextInt());
 		assertFalse(iterator.hasNext());
@@ -367,7 +365,7 @@ public class IntLinkedOpenHashSetTest {
 
 	@Test
 	public void testIterator() {
-		IntLinkedOpenHashSet s = new IntLinkedOpenHashSet(Hash.DEFAULT_INITIAL_SIZE);
+		final IntLinkedOpenHashSet s = new IntLinkedOpenHashSet(Hash.DEFAULT_INITIAL_SIZE);
 		for(int i = 0; i < 100; i++) assertTrue(s.add(i));
 		assertEquals(0, s.firstInt());
 
@@ -424,14 +422,14 @@ public class IntLinkedOpenHashSetTest {
 
 	@Test(expected=NoSuchElementException.class)
 	public void testIteratorMissingElement() {
-		IntLinkedOpenHashSet s = new IntLinkedOpenHashSet(Hash.DEFAULT_INITIAL_SIZE);
+		final IntLinkedOpenHashSet s = new IntLinkedOpenHashSet(Hash.DEFAULT_INITIAL_SIZE);
 		for(int i = 0; i < 100; i++) assertTrue(s.add(i));
 		s.iterator(1000);
 	}
 
 	@Test
 	public void testPutAndMove() {
-		IntLinkedOpenHashSet s = new IntLinkedOpenHashSet(Hash.DEFAULT_INITIAL_SIZE);
+		final IntLinkedOpenHashSet s = new IntLinkedOpenHashSet(Hash.DEFAULT_INITIAL_SIZE);
 		for(int i = 0; i < 100; i++) assertTrue(s.addAndMoveToFirst(i));
 		s.clear();
 		for(int i = 0; i < 100; i++) assertTrue(s.addAndMoveToLast(i));
@@ -459,7 +457,7 @@ public class IntLinkedOpenHashSetTest {
 
 	@Test
 	public void testRemoveFirstLast() {
-		IntLinkedOpenHashSet s = new IntLinkedOpenHashSet(Hash.DEFAULT_INITIAL_SIZE);
+		final IntLinkedOpenHashSet s = new IntLinkedOpenHashSet(Hash.DEFAULT_INITIAL_SIZE);
 		for(int i = 0; i < 100; i++) assertTrue(s.add(i));
 		assertEquals(0, s.removeFirstInt());
 		assertEquals(1, s.removeFirstInt());
@@ -502,19 +500,19 @@ public class IntLinkedOpenHashSetTest {
 	@Test
 	public void testToSet() {
 		final IntLinkedOpenHashSet baseSet = IntLinkedOpenHashSet.of(2, 380, 1297);
-		IntLinkedOpenHashSet transformed = IntLinkedOpenHashSet.toSet(baseSet.intStream().map(i -> i + 40));
+		final IntLinkedOpenHashSet transformed = IntLinkedOpenHashSet.toSet(baseSet.intStream().map(i -> i + 40));
 		assertEquals(IntLinkedOpenHashSet.of(42, 420, 1337), transformed);
 	}
 
 	@Test
 	public void testSpliteratorTrySplit() {
 		final IntLinkedOpenHashSet baseSet = IntLinkedOpenHashSet.of(0, 1, 2, 3, 72, 5, 6);
-		IntSpliterator spliterator1 = baseSet.spliterator();
+		final IntSpliterator spliterator1 = baseSet.spliterator();
 		assertEquals(baseSet.size(), spliterator1.getExactSizeIfKnown());
-		IntSpliterator spliterator2 = spliterator1.trySplit();
+		final IntSpliterator spliterator2 = spliterator1.trySplit();
 		// No assurance of where we split, but where ever it is it should be a perfect split.
-		java.util.stream.IntStream stream1 = java.util.stream.StreamSupport.intStream(spliterator1, false);
-		java.util.stream.IntStream stream2 = java.util.stream.StreamSupport.intStream(spliterator2, false);
+		final java.util.stream.IntStream stream1 = java.util.stream.StreamSupport.intStream(spliterator1, false);
+		final java.util.stream.IntStream stream2 = java.util.stream.StreamSupport.intStream(spliterator2, false);
 
 		final IntLinkedOpenHashSet subSet1 = IntLinkedOpenHashSet.toSet(stream1);
 		// Intentionally collecting to a list for this second one.
@@ -530,4 +528,12 @@ public class IntLinkedOpenHashSetTest {
 	public void testLegacyMainMethodTests() throws Exception {
 		MainRunner.callMainIfExists(IntLinkedOpenHashSet.class, "test", /*num=*/"500", /*loadFactor=*/"0.75", /*seed=*/"3832474");
 	}
+
+	@Test
+	public void testRemoveLast() {
+		final IntLinkedOpenHashSet s = new IntLinkedOpenHashSet();
+		s.add(0);
+		s.removeLastInt();
+		assertFalse(s.iterator().hasNext());
+	}
 }


=====================================
test/it/unimi/dsi/fastutil/objects/ObjectArrayListTest.java
=====================================
@@ -225,4 +225,22 @@ public class ObjectArrayListTest {
 	public void testLegacyMainMethodTests() throws Exception {
 		MainRunner.callMainIfExists(ObjectArrayList.class, "test", /*num=*/"500", /*seed=*/"939384");
 	}
+
+	@Test
+	public void testZeroLengthToArray() {
+		assertSame(ObjectArrays.EMPTY_ARRAY, new ObjectArrayList<Integer>().toArray());
+		assertSame(ObjectArrays.EMPTY_ARRAY, new AbstractObjectList<Integer>() {
+
+			@Override
+			public Integer get(final int index) {
+				throw new ArrayIndexOutOfBoundsException();
+			}
+
+			@Override
+			public int size() {
+				// TODO Auto-generated method stub
+				return 0;
+			}
+		}.toArray());
+	}
 }


=====================================
test/it/unimi/dsi/fastutil/objects/ObjectArraySetTest.java
=====================================
@@ -234,4 +234,9 @@ public class ObjectArraySetTest {
 		final ObjectArraySet<String> l = ObjectArraySet.ofUnchecked("0", "0");
 		assertEquals(new ObjectArraySet<>(new String[] { "0" , "0" }), l);
 	}
+
+	@Test
+	public void testZeroLengthToArray() {
+		assertSame(ObjectArrays.EMPTY_ARRAY, new ObjectArraySet<Integer>().toArray());
+	}
 }


=====================================
test/it/unimi/dsi/fastutil/objects/ObjectImmutableListTest.java
=====================================
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2017-2022 Sebastiano Vigna
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package it.unimi.dsi.fastutil.objects;
+
+import static org.junit.Assert.assertSame;
+
+import org.junit.Test;
+
+public class ObjectImmutableListTest {
+	@Test
+	public void testZeroLengthToArray() {
+		assertSame(ObjectArrays.EMPTY_ARRAY, ObjectImmutableList.of().toArray());
+	}
+}



View it on GitLab: https://salsa.debian.org/java-team/libfastutil-java/-/compare/eeb00301b05924ba3361596cff7ea8d92e97af6e...e936a95a9d7c3163d1a79aa56e7e98e5894603fd

-- 
View it on GitLab: https://salsa.debian.org/java-team/libfastutil-java/-/compare/eeb00301b05924ba3361596cff7ea8d92e97af6e...e936a95a9d7c3163d1a79aa56e7e98e5894603fd
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/20221219/f0c60412/attachment.htm>


More information about the pkg-java-commits mailing list