sclass SimpleCircularBuffer { A[] buffer; long base; int size; *(int capacity) { buffer = new A[capacity]; } void add(A a) { if (size == buffer.length) { --size; ++base; } buffer[(int) ((base+size) % buffer.length)] = a; ++size; } A get(long pos) { if (pos < base || pos >= base+size) null; ret buffer[(int) ((pos-base) % buffer.length)]; } }