public int increment(T element) { return this.add(element, 1); }
public void addAll(Counter<T> that) { this.addAll(that.counts); }
public List<Map> toJsonList() { Counter<ExecutionStage> stageActivationCounter = new Counter<>(); Queue<ExecutionStage> activatedStages = new LinkedList<>(this.startingStages); Set<ExecutionStage> seenStages = new HashSet<>(); ArrayList<Map> allStages = new ArrayList<>(); while (!activatedStages.isEmpty()) { final ExecutionStage stage = activatedStages.poll(); if (!seenStages.add(stage)) continue; Map stageMap = stage.toJsonMap(); // Better way to put sequence number ? stageMap.put("sequence_number", allStages.size()); allStages.add(stageMap); for (ExecutionStage successor : stage.getSuccessors()) { final int count = stageActivationCounter.add(successor, 1); if (count == successor.getPredecessors().size() || successor.isLoopHead()) { activatedStages.add(successor); } } } return allStages; }
/** * Counts the given {@code delta} for the given {@code element}. * @return the new count */ public int add(T element, int delta) { final int currentCount = this.get(element); final int newCount = currentCount + delta; if (newCount == 0) { this.counts.remove(element); } else { this.counts.put(element, newCount); } return newCount; }
/** * Creates a {@link String} representation of this instance. * * @param isStriclyOrdering whether {@link ExecutionStage}s should be listed only after <i>all</i> their predecessors * @return the {@link String} representation */ public String toExtensiveString(boolean isStriclyOrdering) { StringBuilder sb = new StringBuilder(); Counter<ExecutionStage> stageActivationCounter = new Counter<>(); Queue<ExecutionStage> activatedStages = new LinkedList<>(this.startingStages); Set<ExecutionStage> seenStages = new HashSet<>(); while (!activatedStages.isEmpty()) { while (!activatedStages.isEmpty()) { final ExecutionStage stage = activatedStages.poll(); if (!seenStages.add(stage)) continue; sb.append(">>> ").append(stage).append(":\n"); stage.getPlanAsString(sb, "> "); sb.append("\n"); for (ExecutionStage successor : stage.getSuccessors()) { final int count = stageActivationCounter.add(successor, 1); if (!isStriclyOrdering || count == successor.getPredecessors().size() || successor.isLoopHead()) { activatedStages.add(successor); } } } } return sb.toString(); }
public int decrement(T element) { return this.add(element, -1); }
private void addAll(Map<T, Integer> counts) { counts.entrySet().forEach(count -> this.add(count.getKey(), count.getValue())); }