Skip to content

Commit

Permalink
Merge branch 'upstream' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
SupremeMortal committed Nov 9, 2024
2 parents 8b544a2 + 355d8eb commit e601fd7
Show file tree
Hide file tree
Showing 27 changed files with 755 additions and 86 deletions.
29 changes: 29 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
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 [email protected].

- Fixed a bug in sublist iterators of immutable lists. Thanks to Barak
Ugav for finding and fixing this bug.

- Implemented missing skip() and forEachRemaining() methods in array-based
containers.

- Fixed a bug in array-based containers that would have thrown the wrong
exception and leave the iterator in an inconsistent state when removing
before iterating. Thanks to Michal Frajt for reporting this bug.

- Entry.setValue() now works correctly in all iterators and iterator-like
methods of array-based maps. It was previously throwing an
UnsupportedOperationException.

- New methods to obtain comparators from key extractors. Thanks to Barak
Ugav for implementing this feature.

8.5.13

- Thanks to Chanoch Goldfeder for fixing a number of bugs in ImmutableList.
Expand Down
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ javadoc.base=/usr/share/javadoc

build.sysclasspath=ignore

version=8.5.13
version=8.5.15

dist=dist
src=src
Expand Down
3 changes: 2 additions & 1 deletion drv/ArrayFIFOQueue.drv
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC implements PRIORITY_QUEUE KEY_GENERIC,
s.defaultWriteObject();
int size = size();
s.writeInt(size);
final KEY_GENERIC_TYPE[] array = this.array;
for(int i = start; size-- != 0;) {
s.WRITE_KEY(array[i++]);
if (i == length) i = 0;
Expand All @@ -219,7 +220,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC implements PRIORITY_QUEUE KEY_GENERIC,
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
s.defaultReadObject();
end = s.readInt();
array = KEY_GENERIC_ARRAY_CAST new KEY_TYPE[length = HashCommon.nextPowerOfTwo(end + 1)];
final KEY_GENERIC_TYPE[] array = this.array = KEY_GENERIC_ARRAY_CAST new KEY_TYPE[length = HashCommon.nextPowerOfTwo(end + 1)];
for(int i = 0; i < end; i++) array[i] = KEY_GENERIC_CAST s.READ_KEY();
}
}
47 changes: 28 additions & 19 deletions drv/ArrayList.drv
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
#endif

/** The backing array. */
protected transient KEY_GENERIC_TYPE a[];
protected transient KEY_GENERIC_TYPE[] a;

/** The current actual size of the list (never greater than the backing-array length). */
protected int size;
Expand Down Expand Up @@ -137,7 +137,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
* @param a the array that will be used to back this array list.
*/

protected ARRAY_LIST(final KEY_GENERIC_TYPE a[], @SuppressWarnings("unused") boolean wrapped) {
protected ARRAY_LIST(final KEY_GENERIC_TYPE[] a, @SuppressWarnings("unused") boolean wrapped) {
this.a = a;
#if ! KEYS_PRIMITIVE
this.wrapped = wrapped;
Expand Down Expand Up @@ -243,7 +243,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
* @param a an array whose elements will be used to fill the array list.
*/

public ARRAY_LIST(final KEY_GENERIC_TYPE a[]) {
public ARRAY_LIST(final KEY_GENERIC_TYPE[] a) {
this(a, 0, a.length);
}

Expand All @@ -254,7 +254,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
* @param length the number of elements to use.
*/

public ARRAY_LIST(final KEY_GENERIC_TYPE a[], final int offset, final int length) {
public ARRAY_LIST(final KEY_GENERIC_TYPE[] a, final int offset, final int length) {
this(length);
System.arraycopy(a, offset, this.a, 0, length);
size = length;
Expand Down Expand Up @@ -320,7 +320,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
* @return a new array list of the given size, wrapping the given array.
*/

public static KEY_GENERIC ARRAY_LIST KEY_GENERIC wrap(final KEY_GENERIC_TYPE a[], final int length) {
public static KEY_GENERIC ARRAY_LIST KEY_GENERIC wrap(final KEY_GENERIC_TYPE[] a, final int length) {
if (length > a.length) throw new IllegalArgumentException("The specified length (" + length + ") is greater than the array size (" + a.length + ")");
final ARRAY_LIST KEY_GENERIC l = new ARRAY_LIST KEY_GENERIC_DIAMOND(a, true);
l.size = length;
Expand All @@ -337,7 +337,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
* @return a new array list wrapping the given array.
*/

public static KEY_GENERIC ARRAY_LIST KEY_GENERIC wrap(final KEY_GENERIC_TYPE a[]) {
public static KEY_GENERIC ARRAY_LIST KEY_GENERIC wrap(final KEY_GENERIC_TYPE[] a) {
return wrap(a, a.length);
}

Expand Down Expand Up @@ -451,7 +451,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
if (wrapped) a = ARRAYS.ensureCapacity(a, capacity, size);
else {
if (capacity > a.length) {
final Object t[] = new Object[capacity];
final Object[] t = new Object[capacity];
System.arraycopy(a, 0, t, 0, size);
a = (KEY_GENERIC_TYPE[])t;
}
Expand All @@ -476,7 +476,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
#else
if (wrapped) a = ARRAYS.forceCapacity(a, capacity, size);
else {
final Object t[] = new Object[capacity];
final Object[] t = new Object[capacity];
System.arraycopy(a, 0, t, 0, size);
a = (KEY_GENERIC_TYPE[])t;
}
Expand Down Expand Up @@ -510,20 +510,23 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements

@Override
public int indexOf(final KEY_TYPE k) {
final KEY_TYPE[] a = this.a;
for(int i = 0; i < size; i++) if (KEY_EQUALS(k, a[i])) return i;
return -1;
}


@Override
public int lastIndexOf(final KEY_TYPE k) {
final KEY_TYPE[] a = this.a;
for(int i = size; i-- != 0;) if (KEY_EQUALS(k, a[i])) return i;
return -1;
}

@Override
public KEY_GENERIC_TYPE REMOVE_KEY(final int index) {
if (index >= size) throw new IndexOutOfBoundsException("Index (" + index + ") is greater than or equal to list size (" + size + ")");
final KEY_GENERIC_TYPE[] a = this.a;
final KEY_GENERIC_TYPE old = a[index];
size--;
if (index != size) System.arraycopy(a, index + 1, a, index, size - index);
Expand Down Expand Up @@ -658,6 +661,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements

@Override
public void forEachRemaining(final METHOD_ARG_KEY_CONSUMER action) {
final KEY_GENERIC_TYPE[] a = ARRAY_LIST.this.a;
final int max = to - from;
while(pos < max) {
action.accept(a[from + (lastReturned = pos++)]);
Expand Down Expand Up @@ -698,6 +702,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
}
@Override
public void forEachRemaining(final METHOD_ARG_KEY_CONSUMER action) {
final KEY_GENERIC_TYPE[] a = ARRAY_LIST.this.a;
final int max = getMaxPos();
while(pos < max) {
action.accept(a[pos++]);
Expand Down Expand Up @@ -831,7 +836,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
* @param length the number of elements to add.
*/
@Override
public void addElements(final int index, final KEY_GENERIC_TYPE a[], final int offset, final int length) {
public void addElements(final int index, final KEY_GENERIC_TYPE[] a, final int offset, final int length) {
ensureIndex(index);
ARRAYS.ensureOffsetLength(a, offset, length);
grow(size + length);
Expand All @@ -848,7 +853,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
* @param length the number of elements to add.
*/
@Override
public void setElements(final int index, final KEY_GENERIC_TYPE a[], final int offset, final int length) {
public void setElements(final int index, final KEY_GENERIC_TYPE[] a, final int offset, final int length) {
ensureIndex(index);
ARRAYS.ensureOffsetLength(a, offset, length);
if (index + length > size) throw new IndexOutOfBoundsException("End index (" + (index + length) + ") is greater than list size (" + size + ")");
Expand All @@ -857,6 +862,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements

@Override
public void forEach(final METHOD_ARG_KEY_CONSUMER action) {
final KEY_GENERIC_TYPE[] a = this.a;
for (int i = 0; i < size; ++i) {
action.accept(a[i]);
}
Expand Down Expand Up @@ -994,6 +1000,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
}
@Override
public void forEachRemaining(final METHOD_ARG_KEY_CONSUMER action) {
final KEY_GENERIC_TYPE[] a = ARRAY_LIST.this.a;
while (pos < size) {
action.accept(a[last = pos++]);
}
Expand Down Expand Up @@ -1071,6 +1078,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements

@Override
public void forEachRemaining(final METHOD_ARG_KEY_CONSUMER action) {
final KEY_GENERIC_TYPE[] a = ARRAY_LIST.this.a;
for (final int max = getWorkingMax(); pos < max; ++pos) {
action.accept(a[pos]);
}
Expand Down Expand Up @@ -1229,7 +1237,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
SUPPRESS_WARNINGS_KEY_UNCHECKED
public int compareTo(final ARRAY_LIST KEY_EXTENDS_GENERIC l) {
final int s1 = size(), s2 = l.size();
final KEY_GENERIC_TYPE a1[] = a, a2[] = l.a;
final KEY_GENERIC_TYPE[] a1 = a, a2 = l.a;
#if KEYS_PRIMITIVE // Can't make this assumption for reference types in case we have a goofy Comparable that doesn't compare itself equal
if (a1 == a2 && s1 == s2) return 0;
#endif
Expand Down Expand Up @@ -1263,13 +1271,14 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements

private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
s.defaultWriteObject();
final KEY_GENERIC_TYPE[] a = this.a;
for(int i = 0; i < size; i++) s.WRITE_KEY(a[i]);
}

SUPPRESS_WARNINGS_KEY_UNCHECKED
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
s.defaultReadObject();
a = KEY_GENERIC_ARRAY_CAST new KEY_TYPE[size];
final KEY_GENERIC_TYPE[] a = this.a = KEY_GENERIC_ARRAY_CAST new KEY_TYPE[size];
for(int i = 0; i < size; i++) a[i] = KEY_GENERIC_CAST s.READ_KEY();
}

Expand Down Expand Up @@ -1321,9 +1330,9 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements

int i;
int j;
KEY_TYPE k[] = new KEY_TYPE[n];
KEY_TYPE nk[] = new KEY_TYPE[n];
int randIndexes[] = new int[n];
KEY_TYPE[] k = new KEY_TYPE[n];
KEY_TYPE[] nk = new KEY_TYPE[n];
int[] randIndexes = new int[n];
long ns;

for(i = 0; i < n; i++) {
Expand Down Expand Up @@ -1514,8 +1523,8 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
}

private static Object[] k, v, nk;
private static KEY_TYPE kt[];
private static KEY_TYPE nkt[];
private static KEY_TYPE[] kt;
private static KEY_TYPE[] nkt;
private static ARRAY_LIST topList;

protected static void testLists(LIST m, java.util.List t, int n, int level) throws Exception {
Expand Down Expand Up @@ -1786,7 +1795,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
int p = r.nextInt() % (2 * n + 1);
Collection t1 = new java.util.ArrayList();
int s = r.nextInt(n / 2 + 1);
KEY_TYPE a[] = new KEY_TYPE [s];
KEY_TYPE[] a = new KEY_TYPE [s];
for(int j = 0; j < s; j++) {
KEY_TYPE x = genKey();
t1.add(KEY2OBJ(x));
Expand Down Expand Up @@ -2131,7 +2140,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements
}


public static void main(String args[]) throws Exception {
public static void main(String[] args) throws Exception {
int n = Integer.parseInt(args[1]);
if (args.length > 2) r = new java.util.Random(seed = Long.parseLong(args[2]));

Expand Down
Loading

0 comments on commit e601fd7

Please sign in to comment.