inline of array in LongQueue by creating a getting a reference to the

array of LongList
This commit is contained in:
2020-11-07 08:45:51 +01:00
parent c9dcbdbe97
commit 88f7abfc91
2 changed files with 16 additions and 9 deletions

View File

@@ -669,6 +669,10 @@ public final class LongList implements Serializable, Cloneable {
System.arraycopy(data, 0, input, 0, size);
return input;
}
long[] getArrayInternal() {
return data;
}
/**
* Sorts the list into ascending order.

View File

@@ -11,40 +11,43 @@ class MultiwayLongMerger {
static class LongQueue {
private static final LongQueue EMPTY = new LongQueue(LongList.of());
final LongList wrapped;
final long[] wrapped;
int offset = 0;
private int size;
public LongQueue(LongList wrapped) {
this.wrapped = wrapped;
this.wrapped = wrapped.getArrayInternal();
this.size = wrapped.size();
}
boolean isEmpty() {
return offset >= wrapped.size();
return offset >= size;
}
long pop() {
assert offset < wrapped.size();
final long result = wrapped.get(offset);
assert offset < size;
final long result = wrapped[offset];
offset++;
return result;
}
public long peek() {
return wrapped.get(offset);
return wrapped[offset];
}
public long peekLast() {
return wrapped.get(wrapped.size() - 1);
return wrapped[size - 1];
}
@Override
public String toString() {
return wrapped.sublist(offset).toString();
return Arrays.toString(Arrays.copyOfRange(wrapped, offset, size));
}
public int size() {
return wrapped.size() - offset;
return size - offset;
}
}