Skip to content

Commit

Permalink
Most of size gone and most of constructor use replaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdunkerley committed Jan 24, 2025
1 parent 18d4713 commit be0e32d
Show file tree
Hide file tree
Showing 23 changed files with 147 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public Storage<?> runZip(
}

private BoolStorage run(BoolStorage storage, boolean hadNull, boolean hadTrue, boolean hadFalse) {
int size = storage.size();
// ToDo: BoolStorage works on ints, so casting to an int here.
int size = (int)storage.getSize();
ImmutableBitSet values = new ImmutableBitSet(storage.getValues(), size);
ImmutableBitSet isNothing = new ImmutableBitSet(storage.getIsNothingMap(), size);
boolean negated = storage.isNegated();

ImmutableBitSet newValues;
ImmutableBitSet newIsNothing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,27 +159,22 @@ protected Storage<Boolean> runDoubleMap(
return builder.seal();
}

protected BoolStorage runBigIntegerMap(
protected Storage<Boolean> runBigIntegerMap(
BigIntegerArrayAdapter lhs, BigInteger rhs, MapOperationProblemAggregator problemAggregator) {
int n = lhs.size();
BitSet comparisonResults = new BitSet();
BitSet isNothing = new BitSet();
var builder = Builder.getForBoolean(n);
Context context = Context.getCurrent();
for (int i = 0; i < n; ++i) {
BigInteger item = lhs.getItem(i);
if (item == null) {
isNothing.set(i);
builder.appendNulls(1);
} else {
boolean r = doBigInteger(item, rhs);
if (r) {
comparisonResults.set(i);
}
builder.appendBoolean(r);
}

context.safepoint();
}

return new BoolStorage(comparisonResults, isNothing, n, false);
return builder.seal();
}

protected Storage<Boolean> runBigDecimalMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,48 +61,40 @@ public Storage<Boolean> runBinaryMap(
}

@Override
public BoolStorage runZip(
public Storage<Boolean> runZip(
SpecializedStorage<String> storage,
Storage<?> arg,
MapOperationProblemAggregator problemAggregator) {
Context context = Context.getCurrent();
if (arg instanceof StringStorage v) {
BitSet newVals = new BitSet();
BitSet newIsNothing = new BitSet();
for (int i = 0; i < storage.size(); i++) {
if (!storage.isNothing(i) && i < v.size() && !v.isNothing(i)) {
if (doString(storage.getBoxed(i), v.getBoxed(i))) {
newVals.set(i);
}
long size = storage.getSize();
var builder = Builder.getForBoolean(size);
for (long i = 0; i < size; i++) {
if (!storage.isNothing(i) && i < v.getSize() && !v.isNothing(i)) {
builder.appendBoolean(doString(storage.getBoxed(i), v.getBoxed(i)));
} else {
newIsNothing.set(i);
builder.appendNulls(1);
}

context.safepoint();
}
return new BoolStorage(newVals, newIsNothing, storage.size(), false);
return builder.seal();
} else {
BitSet newVals = new BitSet();
BitSet newIsNothing = new BitSet();
for (int i = 0; i < storage.size(); i++) {
if (!storage.isNothing(i) && i < arg.size() && !arg.isNothing(i)) {
long size = storage.getSize();
var builder = Builder.getForBoolean(size);
for (long i = 0; i < size; i++) {
if (!storage.isNothing(i) && i < arg.getSize() && !arg.isNothing(i)) {
Object x = arg.getBoxed(i);
if (x instanceof String str) {
if (doString(storage.getBoxed(i), str)) {
newVals.set(i);
}
builder.appendBoolean(doString(storage.getBoxed(i), str));
} else {
if (doObject(storage.getBoxed(i), x)) {
newVals.set(i);
}
builder.appendBoolean(doObject(storage.getBoxed(i), x));
}
} else {
newIsNothing.set(i);
builder.appendNulls(1);
}

context.safepoint();
}
return new BoolStorage(newVals, newIsNothing, storage.size(), false);
return builder.seal();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.enso.table.data.column.builder.Builder;
import org.enso.table.data.column.operation.map.BinaryMapOperation;
import org.enso.table.data.column.operation.map.MapOperationProblemAggregator;
import org.enso.table.data.column.storage.BoolStorage;
import org.enso.table.data.column.storage.SpecializedStorage;
import org.enso.table.data.column.storage.Storage;
import org.enso.table.data.column.storage.StringStorage;
import org.enso.table.data.column.storage.numeric.LongStorage;
import org.enso.table.data.column.storage.type.TextType;
import org.enso.table.error.UnexpectedTypeException;
Expand All @@ -19,52 +21,47 @@ public StringLongToStringOp(String name) {
protected abstract String doOperation(String a, long b);

@Override
public Storage<?> runBinaryMap(
public Storage<String> runBinaryMap(
SpecializedStorage<String> storage,
Object arg,
MapOperationProblemAggregator problemAggregator) {
int size = storage.size();
var builder = Builder.getForText(size, TextType.VARIABLE_LENGTH);
long size = storage.getSize();
if (arg == null) {
builder.appendNulls(size);
return builder.seal();
return StringStorage.makeEmpty(size, TextType.VARIABLE_LENGTH);
} else if (arg instanceof Long argLong) {
var builder = Builder.getForText(size, TextType.VARIABLE_LENGTH);
Context context = Context.getCurrent();
for (int i = 0; i < size; i++) {
for (long i = 0; i < size; i++) {
if (storage.isNothing(i)) {
builder.appendNulls(1);
} else {
builder.append(doOperation(storage.getBoxed(i), argLong));
}

context.safepoint();
}

return builder.seal();
} else {
throw new UnexpectedTypeException("a Text");
}
}

@Override
public Storage<?> runZip(
public Storage<String> runZip(
SpecializedStorage<String> storage,
Storage<?> arg,
MapOperationProblemAggregator problemAggregator) {
if (arg instanceof LongStorage v) {
int size = storage.size();
long size = storage.getSize();
var builder = Builder.getForText(size, TextType.VARIABLE_LENGTH);
Context context = Context.getCurrent();
for (int i = 0; i < size; i++) {
for (long i = 0; i < size; i++) {
if (storage.isNothing(i) || v.isNothing(i)) {
builder.appendNulls(1);
} else {
builder.append(doOperation(storage.getBoxed(i), v.getBoxed(i)));
}

context.safepoint();
}

return builder.seal();
} else {
throw new UnexpectedTypeException("a Text column");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,25 @@ public StringStringOp(String name) {
protected abstract TextType computeResultType(TextType a, TextType b);

@Override
public Storage<?> runBinaryMap(
public Storage<String> runBinaryMap(
SpecializedStorage<String> storage,
Object arg,
MapOperationProblemAggregator problemAggregator) {
int size = storage.size();
long size = storage.getSize();
if (arg == null) {
var builder = Builder.getForText(size, TextType.VARIABLE_LENGTH);
builder.appendNulls(size);
return builder.seal();
return StringStorage.makeEmpty(size, TextType.VARIABLE_LENGTH);
} else if (arg instanceof String argString) {
TextType argumentType = TextType.preciseTypeForValue(argString);
TextType newType = computeResultType((TextType) storage.getType(), argumentType);

var builder = Builder.getForText(size, newType);
Context context = Context.getCurrent();
for (int i = 0; i < size; i++) {
for (long i = 0; i < size; i++) {
if (storage.isNothing(i)) {
builder.appendNulls(1);
} else {
builder.append(doString(storage.getBoxed(i), argString));
}

context.safepoint();
}

Expand All @@ -53,25 +50,23 @@ public Storage<?> runBinaryMap(
}

@Override
public Storage<?> runZip(
public Storage<String> runZip(
SpecializedStorage<String> storage,
Storage<?> arg,
MapOperationProblemAggregator problemAggregator) {
if (arg instanceof StringStorage v) {
TextType newType = computeResultType((TextType) storage.getType(), v.getType());
int size = storage.size();
long size = storage.getSize();
var builder = Builder.getForText(size, newType);
Context context = Context.getCurrent();
for (int i = 0; i < size; i++) {
for (long i = 0; i < size; i++) {
if (storage.isNothing(i) || v.isNothing(i)) {
builder.appendNulls(1);
} else {
builder.append(doString(storage.getBoxed(i), v.getBoxed(i)));
}

context.safepoint();
}

return builder.seal();
} else {
throw new UnexpectedTypeException("a Text column");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,53 +152,46 @@ public Storage<?> fillMissingFromPrevious(BoolStorage missingIndicator) {

boolean previousValue = false;
boolean hasPrevious = false;
BitSet newIsNothing = new BitSet();
BitSet newValues = new BitSet();
long size = getSize();
var builder = Builder.getForBoolean(size);

Context context = Context.getCurrent();
for (int i = 0; i < size; i++) {
boolean isCurrentValueMissing = isNothing.get(i);
for (long i = 0; i < size; i++) {
boolean isCurrentValueMissing = isNothing(i);
if (isCurrentValueMissing) {
if (hasPrevious) {
newValues.set(i, previousValue);
builder.appendBoolean(previousValue);
} else {
newIsNothing.set(i);
builder.appendNulls(1);
}
} else {
boolean currentValue = getPrimitive(i);
newValues.set(i, currentValue);
builder.appendBoolean(currentValue);
previousValue = currentValue;
hasPrevious = true;
}

context.safepoint();
}

return new BoolStorage(newValues, newIsNothing, size, false);
return builder.seal();
}

@Override
public BoolStorage applyFilter(BitSet filterMask, int newLength) {
public Storage<Boolean> applyFilter(BitSet filterMask, int newLength) {
Context context = Context.getCurrent();
BitSet newIsNothing = new BitSet();
BitSet newValues = new BitSet();
int resultIx = 0;
var builder = Builder.getForBoolean(newLength);
for (int i = 0; i < size; i++) {
if (filterMask.get(i)) {
if (isNothing.get(i)) {
newIsNothing.set(resultIx++);
} else if (values.get(i)) {
newValues.set(resultIx++);
builder.appendNulls(1);
} else {
// We don't set any bits, but still increment the counter to indicate that we have just
// 'inserted' a false value.
resultIx++;
builder.appendBoolean(getPrimitive(i));
}
}

context.safepoint();
}
return new BoolStorage(newValues, newIsNothing, newLength, negated);
return builder.seal();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public StorageType inferPreciseType() {
StorageType currentType = null;

Context context = Context.getCurrent();
for (int i = 0; i < size(); i++) {
for (long i = 0; i < getSize(); i++) {
var item = getBoxed(i);
if (item == null) {
continue;
Expand Down Expand Up @@ -131,8 +131,8 @@ public Storage<?> getInferredStorage() {
// for purposes of a
// computation.
Builder builder =
Builder.getForType(inferredType, size(), BlackholeProblemAggregator.INSTANCE);
for (int i = 0; i < size(); i++) {
Builder.getForType(inferredType, getSize(), BlackholeProblemAggregator.INSTANCE);
for (long i = 0; i < getSize(); i++) {
builder.append(getBoxed(i));
}
cachedInferredStorage = builder.seal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ public abstract class Storage<T> implements ColumnStorage<T> {
/** A constant representing the index of a missing value in a column. */
public static final int NOT_FOUND_INDEX = -1;

/**
* @return the number of elements in this column (including NAs)
*/
public final int size() {
return Math.toIntExact(getSize());
public int size() { return -1;
}

@Override
Expand Down
Loading

0 comments on commit be0e32d

Please sign in to comment.