@Test public void testResize() { LongMatrix<String> m = new LongMatrix<>(2); for (int i = 0; i < 1000; i++) { int r = m.addRow(); m.set(r, 0, i); m.set(r, 1, i); m.set(r, "s" + i); } Assert.assertEquals(1000, m.size()); for (int i = 0, n = m.size(); i < n; i++) { Assert.assertEquals(i, m.get(i, 0)); Assert.assertEquals(i, m.get(i, 1)); Assert.assertEquals("s" + i, m.get(i)); } }
@SuppressWarnings("unchecked") private int resize() { long[] _data = new long[rows << (bits + 1)]; T[] _payload = (T[]) new Object[rows << 1]; System.arraycopy(data, 0, _data, 0, rows << bits); System.arraycopy(payload, 0, _payload, 0, rows); this.data = _data; this.payload = _payload; this.rows <<= 1; return pos++; }
LongMatrix { @SuppressWarnings("unchecked") private int resize() { long[] _data = new long[rows << (bits + 1)]; T[] _payload = (T[]) new Object[rows << 1]; System.arraycopy(data, 0, _data, 0, rows << bits); System.arraycopy(payload, 0, _payload, 0, rows); this.data = _data; this.payload = _payload; this.rows <<= 1; return pos++; } }
LongMatrix { @SuppressWarnings("unchecked") private int resize() { long[] _data = new long[rows << (bits + 1)]; T[] _payload = (T[]) new Object[rows << 1]; System.arraycopy(data, 0, _data, 0, rows << bits); System.arraycopy(payload, 0, _payload, 0, rows); this.data = _data; this.payload = _payload; this.rows <<= 1; return pos++; } @SuppressWarnings("unchecked")  LongMatrix(int columnCount); }
LongMatrix { @SuppressWarnings("unchecked") private int resize() { long[] _data = new long[rows << (bits + 1)]; T[] _payload = (T[]) new Object[rows << 1]; System.arraycopy(data, 0, _data, 0, rows << bits); System.arraycopy(payload, 0, _payload, 0, rows); this.data = _data; this.payload = _payload; this.rows <<= 1; return pos++; } @SuppressWarnings("unchecked")  LongMatrix(int columnCount); int addRow(); int binarySearch(long v, int index); void deleteRow(int r); long get(int r, int c); T get(int r); void set(int r, T obj); void set(int r, int c, long value); int size(); void zapTop(int count); }
LongMatrix { @SuppressWarnings("unchecked") private int resize() { long[] _data = new long[rows << (bits + 1)]; T[] _payload = (T[]) new Object[rows << 1]; System.arraycopy(data, 0, _data, 0, rows << bits); System.arraycopy(payload, 0, _payload, 0, rows); this.data = _data; this.payload = _payload; this.rows <<= 1; return pos++; } @SuppressWarnings("unchecked")  LongMatrix(int columnCount); int addRow(); int binarySearch(long v, int index); void deleteRow(int r); long get(int r, int c); T get(int r); void set(int r, T obj); void set(int r, int c, long value); int size(); void zapTop(int count);  }