sclass SynchronizedFloatBufferPresentingAsDoubles is IDoubleBuffer { float[] data; int size; *() {} *(int size) { if (size != 0) data = new float[size]; } *(Iterable l) { addAll(l); } *(Cl l) { this(l(l)); addAll(l); } *(double... data) { this.data = doubleArrayToFloatArray(data); size = l(data); } public synchronized void add(double i) { if (size >= lFloatArray(data)) { data = resizeFloatArray(data, Math.max(1, toInt(Math.min(maximumSafeArraySize(), lFloatArray(data)*2L)))); if (size >= data.length) fail(shortClassName(this) + " too large: " + size); } data[size++] = (float) i; } public synchronized void addAll(Iterable l) { if (l != null) for (double i : l) add(i); } public synchronized double[] toArray() { ret size == 0 ? null : takeFirstFromFloatArrayAsDoubleArray(data, size); } double[] toArrayNonNull() { ret unnull(toArray()); } synchronized L toList() { ret floatArrayToDoubleList(data, 0, size); } synchronized L asVirtualList() { ret new RandomAccessAbstractList { public int size() { ret SynchronizedFloatBufferPresentingAsDoubles.this.size(); } public Double get(int i) { ret SynchronizedFloatBufferPresentingAsDoubles.this.get(i); } public Double set(int i, Double val) { synchronized(SynchronizedFloatBufferPresentingAsDoubles.this) { Double a = get(i); data[i] = val.floatValue(); ret a; } } }; } synchronized void reset { size = 0; } void clear { reset(); } public synchronized int size() { ret size; } public synchronized bool isEmpty() { ret size == 0; } public synchronized double get(int idx) { if (idx >= size) fail("Index out of range: " + idx + "/" + size); ret data[idx]; } synchronized void set(int idx, double value) { if (idx >= size) fail("Index out of range: " + idx + "/" + size); data[idx] = (float) value; } public synchronized double popLast() { if (size == 0) fail("empty buffer"); ret data[--size]; } public synchronized double first() { ret data[0]; } public synchronized double last() { ret data[size-1]; } synchronized double 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 Double next() { synchronized(SynchronizedFloatBufferPresentingAsDoubles.this) { //if (!hasNext()) fail("Index out of bounds: " + i); ret (double) data[i++]; } } }; } /*public DoubleIterator doubleIterator() { ret new DoubleIterator { int i = 0; public bool hasNext() { ret i < size; } public int next() { //if (!hasNext()) fail("Index out of bounds: " + i); ret data[i++]; } toString { ret "Iterator@" + i + " over " + DoubleBuffer.this; } }; }*/ public synchronized void trimToSize { data = resizeFloatArray(data, size); } public synchronized int indexOf(double b) { for i to size: if (data[i] == (float) b) ret i; ret -1; } synchronized double[] subArray(int start, int end) { ret subFloatArrayAsDoubleArray(data, start, min(end, size)); } public synchronized void insertAt(int idx, double[] l) { int n = l(l); if (n == 0) ret; float[] newData = new[size+n]; arraycopy(data, 0, newData, 0, idx); for i to n: newData[idx+i] = (float) l[i]; arraycopy(data, idx, newData, idx+n, size-idx); data = newData; size = newData.length; } public void integrityCheck { assertTrue("Size positive", size >= 0); assertTrue("Data length", l(data) >= size); } }