sclass LongBuffer implements Iterable { long[] data; int size; *() {} *(int size) { if (size != 0) data = new long[size]; } void add(long i) { if (size >= lLongArray(data)) data = resizeLongArray(data, Math.max(1, lLongArray(data)*2)); data[size++] = i; } long[] toArray() { ret size == 0 ? null : resizeLongArray(data, size); } L toList() { ret longArrayToList(data, 0, size); } L asVirtualList() { ret listFromFunction(size, lambda1 get); } void reset { size = 0; } void clear { reset(); } int size() { ret size; } bool isEmpty() { ret size == 0; } long get(int idx) { if (idx >= size) fail("Index out of range: " + idx + "/" + size); ret data[idx]; } void set(int idx, long value) { if (idx >= size) fail("Index out of range: " + idx + "/" + size); data[idx] = value; } long popLast() { if (size == 0) fail("empty buffer"); ret data[--size]; } long last() { ret data[size-1]; } long nextToLast() { ret data[size-2]; } toString { ret squareBracket(joinWithSpace(toList())); } public Iterator iterator() { ret new ItIt { int i = 0; public bool hasNext() { ret i < size; } public Long next() { if (!hasNext()) fail("Index out of bounds: " + i); ret data[i++]; } }; } }