introduce bitloops

This commit is contained in:
mike
2026-01-12 09:23:38 +01:00
parent fdd1c76bae
commit 84e832df40
7 changed files with 96 additions and 80 deletions

View 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); }
}