30 lines
722 B
Java
30 lines
722 B
Java
package puzzle;
|
|
|
|
import java.util.Arrays;
|
|
public final class LongArrayList {
|
|
|
|
private long[] a;
|
|
private int size;
|
|
|
|
public LongArrayList() { this(16); }
|
|
|
|
public LongArrayList(int initialCapacity) {
|
|
if (initialCapacity < 0) throw new IllegalArgumentException();
|
|
a = new long[initialCapacity];
|
|
}
|
|
|
|
public int size() { return size; }
|
|
|
|
public void add(long v) {
|
|
if (size == a.length) grow();
|
|
a[size++] = v;
|
|
}
|
|
|
|
private void grow() {
|
|
int newCap = a.length == 0 ? 1 : a.length * 2;
|
|
long[] n = new long[newCap];
|
|
System.arraycopy(a, 0, n, 0, size);
|
|
a = n;
|
|
}
|
|
public long[] toArray() { return Arrays.copyOf(a, this.size); }
|
|
} |