Java Code Examples for it.unimi.dsi.fastutil.objects.ObjectArrayList#set()

The following examples show how to use it.unimi.dsi.fastutil.objects.ObjectArrayList#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PagesIndex.java    From presto with Apache License 2.0 6 votes vote down vote up
public void compact()
{
    if (eagerCompact) {
        return;
    }
    for (int channel = 0; channel < types.size(); channel++) {
        ObjectArrayList<Block> blocks = channels[channel];
        for (int i = nextBlockToCompact; i < blocks.size(); i++) {
            Block block = blocks.get(i);

            // Copy the block to compact its size
            Block compactedBlock = block.copyRegion(0, block.getPositionCount());
            blocks.set(i, compactedBlock);
            pagesMemorySize -= block.getRetainedSizeInBytes();
            pagesMemorySize += compactedBlock.getRetainedSizeInBytes();
        }
    }
    nextBlockToCompact = channels[0].size();
    estimatedSize = calculateEstimatedSize();
}
 
Example 2
Source File: OptimizedExplosion.java    From fabric-carpet with MIT License 6 votes vote down vote up
private static void method_24023(ObjectArrayList<Pair<ItemStack, BlockPos>> objectArrayList, ItemStack itemStack, BlockPos blockPos) {
    int i = objectArrayList.size();

    for(int j = 0; j < i; ++j) {
        Pair<ItemStack, BlockPos> pair = (Pair)objectArrayList.get(j);
        ItemStack itemStack2 = pair.getLeft();
        if (ItemEntity.canMerge(itemStack2, itemStack)) {
            ItemStack itemStack3 = ItemEntity.merge(itemStack2, itemStack, 16);
            objectArrayList.set(j, Pair.of(itemStack3, pair.getRight()));
            if (itemStack.isEmpty()) {
                return;
            }
        }
    }

    objectArrayList.add(Pair.of(itemStack, blockPos));
}
 
Example 3
Source File: MathParser.java    From WarpPI with Apache License 2.0 6 votes vote down vote up
/**
 * Make powers [12][^[15]] => [[12]^[15]]
 *
 * @param context
 * @param features
 * @return
 * @throws Error
 */
private static ObjectArrayList<Feature> makePowers(final MathContext context,
		final ObjectArrayList<Feature> features) throws Error {
	final ObjectArrayList<Feature> process = new ObjectArrayList<>();

	Feature lastFeature = null;
	for (final Feature f : features) {
		if (f instanceof FeaturePowerChar) {
			if (lastFeature != null) {
				process.set(process.size() - 1, new FeaturePower(lastFeature.toFunction(context), ((FeaturePowerChar) f).getChild()));
			} else {
				process.add(f);
			}
		} else {
			process.add(f);
		}
		lastFeature = f;
	}

	return process;
}
 
Example 4
Source File: AddImplicitMultiplications.java    From WarpPI with Apache License 2.0 6 votes vote down vote up
@Override
public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction,
		final ObjectArrayList<Function> functionsList) {
	if (currentFunction instanceof Function) {
		if (lastFunction instanceof Function) {
			functionsList.set(curIndex.i, new Multiplication(context, currentFunction, lastFunction));
			functionsList.remove(curIndex.i + 1);
			return true;
		}
	} else if (currentFunction instanceof Function) {
		if (lastFunction instanceof Function) {
			functionsList.set(curIndex.i, new Multiplication(context, currentFunction, lastFunction));
			functionsList.remove(curIndex.i + 1);
			return true;
		}
	}
	return false;
}
 
Example 5
Source File: FixMultiplicationsAndDivisions.java    From WarpPI with Apache License 2.0 6 votes vote down vote up
@Override
public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction,
		final ObjectArrayList<Function> functionsList) throws Error {
	if (currentFunction instanceof Multiplication || currentFunction instanceof Division) {
		if (currentFunction.getParameter(0) == null && currentFunction.getParameter(1) == null) {
			if (curIndex.i - 1 >= 0 && curIndex.i + 1 < functionsList.size()) {
				final Function next = functionsList.get(curIndex.i + 1);
				final Function prev = functionsList.get(curIndex.i - 1);
				functionsList.set(curIndex.i, currentFunction.setParameter(0, prev).setParameter(1, next));
				functionsList.remove(curIndex.i + 1);
				functionsList.remove(curIndex.i - 1);
				curIndex.i--;
				return true;
			} else if (currentFunction.getParameter(0) == null || currentFunction.getParameter(1) == null) {
				throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified.");
			}
		}
	}
	return false;
}
 
Example 6
Source File: FixSumsAndSubtractions.java    From WarpPI with Apache License 2.0 6 votes vote down vote up
@Override
public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction,
		final ObjectArrayList<Function> functionsList) throws Error {
	if (currentFunction instanceof Sum || currentFunction instanceof Subtraction || currentFunction instanceof SumSubtraction) {
		if (currentFunction.getParameter(0) == null && currentFunction.getParameter(1) == null) {
			if (curIndex.i - 1 >= 0 && curIndex.i + 1 < functionsList.size()) {
				final Function next = functionsList.get(curIndex.i + 1);
				final Function prev = functionsList.get(curIndex.i - 1);
				functionsList.set(curIndex.i, currentFunction.setParameter(0, prev).setParameter(1, next));
				functionsList.remove(curIndex.i + 1);
				functionsList.remove(curIndex.i - 1);
				curIndex.i--;
				return true;
			} else if (currentFunction.getParameter(0) == null || currentFunction.getParameter(1) == null) {
				throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified.");
			}
		}
	}
	return false;
}
 
Example 7
Source File: JoinNumberAndVariables.java    From WarpPI with Apache License 2.0 5 votes vote down vote up
@Override
public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction,
		final ObjectArrayList<Function> functionsList) {
	if (currentFunction instanceof Number | currentFunction instanceof Variable | currentFunction instanceof Division) {
		if (lastFunction instanceof Variable | lastFunction instanceof Number | (lastFunction instanceof Multiplication && ((Multiplication) lastFunction).getParameter2() != null)) {
			final Function a = currentFunction;
			final Function b = lastFunction;
			functionsList.set(curIndex.i, new Multiplication(context, a, b));
			functionsList.remove(curIndex.i + 1);
			return true;
		}
	}
	return false;
}
 
Example 8
Source File: RemoveParentheses.java    From WarpPI with Apache License 2.0 5 votes vote down vote up
@Override
public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction,
		final ObjectArrayList<Function> functionsList) {
	if (currentFunction instanceof Expression) {
		if (((Expression) currentFunction).getParameter() == null) {
			functionsList.remove(curIndex.i);
		} else {
			functionsList.set(curIndex.i, ((Expression) currentFunction).getParameter());
		}
		return true;
	}
	return false;
}