inline of array in LongQueue by creating a getting a reference to the
array of LongList
This commit is contained in:
@@ -670,6 +670,10 @@ public final class LongList implements Serializable, Cloneable {
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long[] getArrayInternal() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the list into ascending order.
|
* Sorts the list into ascending order.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -11,40 +11,43 @@ class MultiwayLongMerger {
|
|||||||
static class LongQueue {
|
static class LongQueue {
|
||||||
private static final LongQueue EMPTY = new LongQueue(LongList.of());
|
private static final LongQueue EMPTY = new LongQueue(LongList.of());
|
||||||
|
|
||||||
final LongList wrapped;
|
final long[] wrapped;
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
|
private int size;
|
||||||
|
|
||||||
public LongQueue(LongList wrapped) {
|
public LongQueue(LongList wrapped) {
|
||||||
this.wrapped = wrapped;
|
this.wrapped = wrapped.getArrayInternal();
|
||||||
|
this.size = wrapped.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isEmpty() {
|
boolean isEmpty() {
|
||||||
return offset >= wrapped.size();
|
return offset >= size;
|
||||||
}
|
}
|
||||||
|
|
||||||
long pop() {
|
long pop() {
|
||||||
assert offset < wrapped.size();
|
assert offset < size;
|
||||||
final long result = wrapped.get(offset);
|
final long result = wrapped[offset];
|
||||||
offset++;
|
offset++;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long peek() {
|
public long peek() {
|
||||||
return wrapped.get(offset);
|
return wrapped[offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
public long peekLast() {
|
public long peekLast() {
|
||||||
return wrapped.get(wrapped.size() - 1);
|
return wrapped[size - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return wrapped.sublist(offset).toString();
|
return Arrays.toString(Arrays.copyOfRange(wrapped, offset, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
return wrapped.size() - offset;
|
return size - offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user