Refine search
/** Convert an arbitrary-dimensional rectangular double array to flat vector.<br> * Can pass double[], double[][], double[][][], etc. */ public static double[] flattenDoubleArray(Object doubleArray) { if (doubleArray instanceof double[]) return (double[]) doubleArray; LinkedList<Object> stack = new LinkedList<>(); stack.push(doubleArray); int[] shape = arrayShape(doubleArray); int length = ArrayUtil.prod(shape); double[] flat = new double[length]; int count = 0; while (!stack.isEmpty()) { Object current = stack.pop(); if (current instanceof double[]) { double[] arr = (double[]) current; for (int i = 0; i < arr.length; i++) flat[count++] = arr[i]; } else if (current instanceof Object[]) { Object[] o = (Object[]) current; for (int i = o.length - 1; i >= 0; i--) stack.push(o[i]); } else throw new IllegalArgumentException("Base array is not double[]"); } if (count != flat.length) throw new IllegalArgumentException("Fewer elements than expected. Array is ragged?"); return flat; }
char operand = list.pop(); if (operand != '0' && operand != '1') { syntaxError(); while (!list.isEmpty()) { char curr = list.pop(); if (curr == '!') { operand = operand == '0' ? '1' : '0'; operand = list.pop(); while (!list.isEmpty()) { char curr = list.pop(); if (curr == '&') { char c = list.pop(); operand = (operand == '1' && c == '1') ? '1' : '0'; } else if (curr == '#') { while (!list.isEmpty() && (operand = list.pop()) != '1'); return operand;
/** Convert an arbitrary-dimensional rectangular float array to flat vector.<br> * Can pass float[], float[][], float[][][], etc. */ public static float[] flattenFloatArray(Object floatArray) { if (floatArray instanceof float[]) return (float[]) floatArray; LinkedList<Object> stack = new LinkedList<>(); stack.push(floatArray); int[] shape = arrayShape(floatArray); int length = ArrayUtil.prod(shape); float[] flat = new float[length]; int count = 0; while (!stack.isEmpty()) { Object current = stack.pop(); if (current instanceof float[]) { float[] arr = (float[]) current; for (int i = 0; i < arr.length; i++) flat[count++] = arr[i]; } else if (current instanceof Object[]) { Object[] o = (Object[]) current; for (int i = o.length - 1; i >= 0; i--) stack.push(o[i]); } else throw new IllegalArgumentException("Base array is not float[]"); } if (count != flat.length) throw new IllegalArgumentException("Fewer elements than expected. Array is ragged?"); return flat; }
protected void flattenTree() { flattenedList = new LinkedList<ExecutionTreeNode>(); LinkedList<ExecutionTreeNode> nodesToHandle = new LinkedList<ExecutionTreeNode>(); nodesToHandle.add(rootNode); while (!nodesToHandle.isEmpty()) { ExecutionTreeNode currentNode = nodesToHandle.pop(); if (reverseOrder) { flattenedList.addFirst(currentNode); } else { flattenedList.add(currentNode); } if (currentNode.getChildren() != null && currentNode.getChildren().size() > 0) { for (ExecutionTreeNode childNode : currentNode.getChildren()) { nodesToHandle.add(childNode); } } } flattenedListIterator = flattenedList.iterator(); }
LinkedList<Long> currentQueue = new LinkedList<Long>(); long baseCuboid = Cuboid.getBaseCuboidId(cube); currentQueue.push(baseCuboid); while (!currentQueue.isEmpty()) { long cuboid = currentQueue.pop(); Collection<Long> spnanningCuboids = scheduler.getSpanningCuboid(cuboid); if (!currentQueue.isEmpty()) { throw new IllegalStateException();
private boolean inParentResult() { FieldRef thisField = stack.pop(); try { FieldRef parentField = stack.pop(); boolean inResult = parentField.haveSeenSeparate(); // restore stack stack.push(parentField); stack.push(thisField); return inResult; } catch (NoSuchElementException e) { // No parent // restore stack stack.push(thisField); return false; } }
private static void bulk( final LinkedList<Log> remaining, final ArrayList<Log> bulkLogs, final Consumer<Log> finalConsumer ) { if ( !remaining.isEmpty() ) { Log log = remaining.pop(); log.bulk( bulkLog -> { bulkLogs.add( bulkLog ); bulk( remaining, bulkLogs, finalConsumer ); } ); } else { Log log = new DuplicatingLog( bulkLogs ); finalConsumer.accept( log ); } }
cuboidSet.add(baseCuboid); LinkedList<Long> cuboidQueue = new LinkedList<Long>(); cuboidQueue.push(baseCuboid); while (!cuboidQueue.isEmpty()) { long cuboid = cuboidQueue.pop(); Collection<Long> spnanningCuboids = scheduler.getSpanningCuboid(cuboid); for (Long sc : spnanningCuboids) { cuboidQueue.push(sc);
private static FieldNode buildTreeByExpr(String expr) { int index = 0; LinkedList<FieldNode> fieldStack = new LinkedList<>(); while (index < expr.length()) { int i = index; if (isSpecialChar(expr.charAt(i))) { if ((expr.charAt(index) == ',') || (expr.charAt(index) == ']')) { FieldNode node = fieldStack.pop(); FieldNode pre = fieldStack.peek(); pre.addFieldNodes(node); } index++; } else { while (i < expr.length() && !isSpecialChar(expr.charAt(i))) { i++; } FieldNode current = new FieldNode(expr.substring(index, i)); fieldStack.push(current); index = i; } } return fieldStack.pop(); } }
private static void bulk( final LinkedList<Logger> remaining, final ArrayList<Logger> bulkLoggers, final Consumer<Logger> finalConsumer ) { if ( !remaining.isEmpty() ) { Logger logger = remaining.pop(); logger.bulk( bulkLogger -> { bulkLoggers.add( bulkLogger ); bulk( remaining, bulkLoggers, finalConsumer ); } ); } else { Logger logger = new DuplicatingLogger( bulkLoggers ); finalConsumer.accept( logger ); } } }
public static int[] calculateAllLevelCount(CubeDesc cube) { int levels = cube.getRowkey().getNCuboidBuildLevels(); int[] allLevelCounts = new int[levels + 1]; CuboidScheduler scheduler = new CuboidScheduler(cube); LinkedList<Long> nextQueue = new LinkedList<Long>(); LinkedList<Long> currentQueue = new LinkedList<Long>(); long baseCuboid = Cuboid.getBaseCuboidId(cube); currentQueue.push(baseCuboid); for (int i = 0; i <= levels; i++) { allLevelCounts[i] = currentQueue.size(); while (!currentQueue.isEmpty()) { long cuboid = currentQueue.pop(); Collection<Long> spnanningCuboids = scheduler.getSpanningCuboid(cuboid); nextQueue.addAll(spnanningCuboids); } currentQueue = nextQueue; nextQueue = new LinkedList<Long>(); } return allLevelCounts; }
public static int simulateCuboidGeneration(CubeDesc cube) { CuboidScheduler scheduler = new CuboidScheduler(cube); long baseCuboid = Cuboid.getBaseCuboidId(cube); Collection<Long> cuboidSet = new TreeSet<Long>(); cuboidSet.add(baseCuboid); LinkedList<Long> cuboidQueue = new LinkedList<Long>(); cuboidQueue.push(baseCuboid); while (!cuboidQueue.isEmpty()) { long cuboid = cuboidQueue.pop(); Collection<Long> spnanningCuboids = scheduler.getSpanningCuboid(cuboid); for (Long sc : spnanningCuboids) { boolean notfound = cuboidSet.add(sc); if (!notfound) { throw new IllegalStateException("Find duplicate spanning cuboid " + sc + " from cuboid " + cuboid); } cuboidQueue.push(sc); } } TreeSet<Long> enumCuboids = enumCalcCuboidCount(cube); if (enumCuboids.equals(cuboidSet) == false) { throw new IllegalStateException("Expected cuboid set " + enumCuboids + "; but actual cuboid set " + cuboidSet); } int mathCount = mathCalcCuboidCount(cube); if (mathCount != enumCuboids.size()) { throw new IllegalStateException("Math cuboid count " + mathCount + ", but actual cuboid count " + enumCuboids.size()); } return mathCount; }