Skip to content

Commit

Permalink
javafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Sep 27, 2023
1 parent 7e56752 commit 4459569
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public StorageType inferPreciseTypeShrunk() {
return AnyObjectType.INSTANCE;
}

// If we are able to get a more specialized storage for more specific type - we delegate to its own shrinking logic.
// If we are able to get a more specialized storage for more specific type - we delegate to its
// own shrinking logic.
return specialized.inferPreciseTypeShrunk();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public StorageType inferPreciseType() {
}

/**
* Returns the smallest type (according to Column.auto_value_type rules) that may still fit all values in this
* column.
* <p>
* It is a sibling of `inferPreciseType` that allows some further shrinking. It is kept separate, because
* `inferPreciseType` should be quick to compute (cached if needed) as it is used in typechecking of lots of
* operations. This one however, is only used in a specific `auto_value_type` use-case and rarely will need to be
* computed more than once.
* Returns the smallest type (according to Column.auto_value_type rules) that may still fit all
* values in this column.
*
* <p>It is a sibling of `inferPreciseType` that allows some further shrinking. It is kept
* separate, because `inferPreciseType` should be quick to compute (cached if needed) as it is
* used in typechecking of lots of operations. This one however, is only used in a specific
* `auto_value_type` use-case and rarely will need to be computed more than once.
*/
public StorageType inferPreciseTypeShrunk() {
return getType();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.enso.table.data.column.storage.numeric;

import java.util.BitSet;
import org.enso.table.data.column.builder.Builder;
import org.enso.table.data.column.builder.NumericBuilder;
import org.enso.table.data.column.operation.map.MapOperationProblemBuilder;
Expand All @@ -25,8 +26,6 @@
import org.enso.table.data.column.storage.type.StorageType;
import org.graalvm.polyglot.Context;

import java.util.BitSet;

public abstract class AbstractLongStorage extends NumericStorage<Long> {
public abstract long getItem(int idx);

Expand Down Expand Up @@ -87,17 +86,15 @@ public StorageType inferPreciseType() {

@Override
public StorageType inferPreciseTypeShrunk() {
// If the type is already smallest possible, we return it unchanged (we will return 8-bit columns as-is, although
// If the type is already smallest possible, we return it unchanged (we will return 8-bit
// columns as-is, although
// we will not shrink 16-bit columns to 8-bits even if it were possible).
if (getType().bits().toInteger() <= 16) {
return getType();
}

IntegerType[] possibleTypes = new IntegerType[] {
IntegerType.INT_16,
IntegerType.INT_32,
IntegerType.INT_64
};
IntegerType[] possibleTypes =
new IntegerType[] {IntegerType.INT_16, IntegerType.INT_32, IntegerType.INT_64};

int currentTypeIdx = 0;
int n = size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public StorageType inferPreciseType() {
}
}

inferredType = (allFitInLong && visitedCount > 0) ? IntegerType.INT_64 : BigIntegerType.INSTANCE;
inferredType =
(allFitInLong && visitedCount > 0) ? IntegerType.INT_64 : BigIntegerType.INSTANCE;
}

return inferredType;
Expand All @@ -143,17 +144,18 @@ private StorageType findSmallestIntegerTypeThatFits() {
final BigIntegerStorage parent = this;

// We create a Long storage that gets values by converting our storage.
ComputedNullableLongStorage longAdapter = new ComputedNullableLongStorage(size) {
@Override
protected Long computeItem(int idx) {
BigInteger bigInteger = parent.getItem(idx);
if (bigInteger == null) {
return null;
}

return bigInteger.longValueExact();
}
};
ComputedNullableLongStorage longAdapter =
new ComputedNullableLongStorage(size) {
@Override
protected Long computeItem(int idx) {
BigInteger bigInteger = parent.getItem(idx);
if (bigInteger == null) {
return null;
}

return bigInteger.longValueExact();
}
};

// And rely on its shrinking logic.
return longAdapter.inferPreciseTypeShrunk();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package org.enso.table.data.column.storage.numeric;

import java.util.BitSet;
import java.util.List;
import org.enso.table.data.column.storage.Storage;
import org.enso.table.data.column.storage.type.IntegerType;
import org.enso.table.data.index.Index;
import org.enso.table.data.mask.OrderMask;
import org.enso.table.data.mask.SliceRange;
import org.graalvm.polyglot.Context;

import java.util.BitSet;
import java.util.List;

/**
* Implements a storage that computes the ith stored value using some function.
*
* <p>This storage allows for missing values. Prefer {@link ComputedLongStorage} for non-nullable case.
* <p>This storage allows for missing values. Prefer {@link ComputedLongStorage} for non-nullable
* case.
*/
public abstract class ComputedNullableLongStorage extends AbstractLongStorage {
protected final int size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,18 +435,20 @@ private StorageType findSmallestIntegerTypeThatFits() {
final DoubleStorage parent = this;

// We create a Long storage that gets values by converting our storage.
ComputedNullableLongStorage longAdapter = new ComputedNullableLongStorage(size) {
@Override
protected Long computeItem(int idx) {
if (parent.isNa(idx)) {
return null;
}

double value = parent.getItem(idx);
assert value % 1.0 == 0.0 : "The value " + value + " should be a whole number (guaranteed by checks).";
return (long) value;
}
};
ComputedNullableLongStorage longAdapter =
new ComputedNullableLongStorage(size) {
@Override
protected Long computeItem(int idx) {
if (parent.isNa(idx)) {
return null;
}

double value = parent.getItem(idx);
assert value % 1.0 == 0.0
: "The value " + value + " should be a whole number (guaranteed by checks).";
return (long) value;
}
};

// And rely on its shrinking logic.
return longAdapter.inferPreciseTypeShrunk();
Expand Down

0 comments on commit 4459569

Please sign in to comment.