/** * Construct the array with the given length and capacity for non-zero elements * @param length the length * @param capacity the capacity */ public SparseHashedByteArray(int length, int capacity) { if (length < 0) throw new IllegalArgumentException("length must be >= 0"); if (capacity <= 0) throw new IllegalArgumentException("capacity must be > 0"); this.length = length; this.data = new TIntByteHashMap(capacity); }
/** * Construct the array with the given length and expected density * @param length the length * @param density the density */ public SparseHashedByteArray(int length, float density) { if (length < 0) throw new IllegalArgumentException("length must be >= 0"); if (density <= 0 || density > 1) throw new IllegalArgumentException("density must be > 0 and < 1"); this.length = length; int capacity = (int) (density * length); this.data = new TIntByteHashMap(capacity); }
@Override public SparseByteArray copy() { SparseHashedByteArray copy = new SparseHashedByteArray(length); copy.data = new TIntByteHashMap(data); return copy; }
@Override public SparseByteArray reverse() { //TODO: this could be more efficient and avoid the copy TIntByteHashMap tmp = new TIntByteHashMap(data.size()); for (Entry e : entries()) tmp.put(length - e.index, e.value); this.data = tmp; return this; } }
row = new TIntByteHashMap(); matrix.put(i, row);