Warning: session_start(): open(/var/lib/php/sessions/sess_5dcsmcc1249apr5qdp998vrkef, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
persistable sclass SynchronizedLongBufferStoredAsLinearInts is ILongBuffer {
int[] data;
int size;
// affine conversion to long (long = int*factor+base)
long base, factor;
*(long *base, long *factor) {}
*(long *base, long *factor, int size) { if (size != 0) data = new int[size]; }
*(long *base, long *factor, Iterable l) {
if (l cast Cl) allocate(l.size());
addAll(l);
}
public synchronized void addRaw(int i) {
if (size >= lIntArray(data)) {
data = resizeIntArray(data, Math.max(1, toInt(Math.min(maximumSafeArraySize(), lIntArray(data)*2L))));
if (size >= data.length) fail(shortClassName(this) + " too large: " + size);
}
data[size++] = i;
}
public synchronized void add(long i) {
addRaw(compress(i));
}
synchronized void allocate(int n) {
data = resizeIntArray(data, max(n, size()));
}
public synchronized void addAll(Iterable l) {
if (l != null) for (long i : l) add(i);
}
public synchronized long[] toArray() {
if (size == 0) null;
long[] out = new[size];
for i to size:
out[i] = expand(data[i]);
ret out;
}
/*synchronized L toList() {
ret longArrayToList(data, 0, size);
}*/
public synchronized L asVirtualList() {
ret listFromFunction get(size);
}
synchronized void reset { size = 0; }
void clear { reset(); }
synchronized public int size() { ret size; }
public synchronized bool isEmpty() { ret size == 0; }
public synchronized int getRaw(int idx) {
if (idx >= size) fail("Index out of range: " + idx + "/" + size);
ret data[idx];
}
public synchronized long get(int idx) {
if (idx >= size) fail("Index out of range: " + idx + "/" + size);
ret expand(data[idx]);
}
synchronized void set(int idx, long value) {
if (idx >= size) fail("Index out of range: " + idx + "/" + size);
data[idx] = compress(value);
}
public synchronized long popLast() {
if (size == 0) fail("empty buffer");
ret expand(data[--size]);
}
public synchronized long last() { ret expand(data[size-1]); }
synchronized long nextToLast() { ret expand(data[size-2]); }
toString { ret squareBracket(joinWithSpace(asVirtualList())); }
public synchronized Iterator iterator() {
ret new ItIt {
int i = 0;
public bool hasNext() { ret i < size(); }
public Long next() {
synchronized(SynchronizedLongBufferStoredAsLinearInts.this) {
if (!hasNext()) fail("Index out of bounds: " + i);
ret expand(data[i++]);
}
}
};
}
public synchronized void trimToSize {
data = resizeIntArray(data, size);
}
synchronized void remove(int idx) {
arraycopy(data, idx+1, data, idx, size-1-idx);
--size;
}
// don't rely on return value if buffer is empty
public synchronized long poll() {
ret size == 0 ? -1 : expand(data[--size]);
}
long expand(int value) { ret base+value*factor; }
int compress(long value) { ret toInt(ldiv_round(value-base, factor); }
}