introduce bitloops
This commit is contained in:
30
src/main/java/puzzle/LongArrayList.java
Normal file
30
src/main/java/puzzle/LongArrayList.java
Normal file
@@ -0,0 +1,30 @@
|
||||
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); }
|
||||
}
|
||||
Reference in New Issue
Block a user