@Test public void testReduceEdges2() { REPOSITORY.setGraph(g -> { g.add(0, 1, add(1)); g.add(0, 2, add(-1)); g.add(1, 3, add(1)); g.add(1, 4, add(-1)); g.add(2, 4, add(1)); g.add(2, 5, add(-1)); }); Map<Integer, List<TestOp>> result = await(reduceEdges(REPOSITORY, TEST_OP, set(3, 4, 5), 0, DiffsReducer.toList())); assertEquals(2, applyToState(result.get(3))); assertEquals(0, applyToState(result.get(4))); assertEquals(-2, applyToState(result.get(5))); }
public static <K, D, A> Promise<Map<K, A>> reduceEdges(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads, K parentNode, DiffsReducer<A, D> diffAccumulator) { return reduce(repository, system, heads, new AbstractGraphReducer<K, D, A, Map<K, A>>(diffAccumulator) { @NotNull @Override protected Promise<Optional<Map<K, A>>> tryGetResult(OTCommit<K, D> commit, Map<K, Map<K, A>> accumulators, Map<K, OTCommit<K, D>> headCommits) { if (accumulators.containsKey(parentNode)) { Map<K, A> toHeads = accumulators.get(parentNode); if (Objects.equals(heads, toHeads.keySet())) { return Promise.of(Optional.of(toHeads)); } } return Promise.of(Optional.empty()); } }); }
OTAlgorithms { public static <K, D, A> Promise<Map<K, A>> reduceEdges(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads, K parentNode, DiffsReducer<A, D> diffAccumulator) { return reduce(repository, system, heads, new AbstractGraphReducer<K, D, A, Map<K, A>>(diffAccumulator) { @NotNull @Override protected Promise<Optional<Map<K, A>>> tryGetResult(OTCommit<K, D> commit, Map<K, Map<K, A>> accumulators, Map<K, OTCommit<K, D>> headCommits) { if (accumulators.containsKey(parentNode)) { Map<K, A> toHeads = accumulators.get(parentNode); if (Objects.equals(heads, toHeads.keySet())) { return Promise.of(Optional.of(toHeads)); } } return Promise.of(Optional.empty()); } }); } }
OTAlgorithms { public static <K, D, A> Promise<Map<K, A>> reduceEdges(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads, K parentNode, DiffsReducer<A, D> diffAccumulator) { return reduce(repository, system, heads, new AbstractGraphReducer<K, D, A, Map<K, A>>(diffAccumulator) { @NotNull @Override protected Promise<Optional<Map<K, A>>> tryGetResult(OTCommit<K, D> commit, Map<K, Map<K, A>> accumulators, Map<K, OTCommit<K, D>> headCommits) { if (accumulators.containsKey(parentNode)) { Map<K, A> toHeads = accumulators.get(parentNode); if (Objects.equals(heads, toHeads.keySet())) { return Promise.of(Optional.of(toHeads)); } } return Promise.of(Optional.empty()); } }); }  }
OTAlgorithms { public static <K, D, A> Promise<Map<K, A>> reduceEdges(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads, K parentNode, DiffsReducer<A, D> diffAccumulator) { return reduce(repository, system, heads, new AbstractGraphReducer<K, D, A, Map<K, A>>(diffAccumulator) { @NotNull @Override protected Promise<Optional<Map<K, A>>> tryGetResult(OTCommit<K, D> commit, Map<K, Map<K, A>> accumulators, Map<K, OTCommit<K, D>> headCommits) { if (accumulators.containsKey(parentNode)) { Map<K, A> toHeads = accumulators.get(parentNode); if (Objects.equals(heads, toHeads.keySet())) { return Promise.of(Optional.of(toHeads)); } } return Promise.of(Optional.empty()); } }); }  static Promise<R> reduce(OTRepository<K, D> repository, OTSystem<D> system,
			Set<K> heads, GraphReducer<K, D, R> reducer); static Promise<FindResult<K, A>> findParent(OTRepository<K, D> repository, OTSystem<D> system,
			Set<K> startNodes, DiffsReducer<A, D> diffsReducer, AsyncPredicate<OTCommit<K, D>> matchPredicate); static Promise<K> mergeAndPush(OTRepository<K, D> repository, OTSystem<D> system); static Promise<K> mergeAndPush(OTRepository<K, D> repository, OTSystem<D> system, @NotNull Set<K> heads); static Promise<K> mergeAndUpdateHeads(OTRepository<K, D> repository, OTSystem<D> system); static Promise<K> mergeAndUpdateHeads(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads); @NotNull static Promise<OTCommit<K, D>> merge(OTRepository<K, D> repository, OTSystem<D> system, @NotNull Set<K> heads); static Promise<Set<K>> findCut(OTRepository<K, D> repository, OTSystem<D> system, Set<K> startNodes,
			Predicate<Collection<OTCommit<K, D>>> matchPredicate); static Promise<K> findAnyCommonParent(OTRepository<K, D> repository, OTSystem<D> system, Set<K> startCut); static Promise<Set<K>> findAllCommonParents(OTRepository<K, D> repository, OTSystem<D> system, Set<K> startCut); static Promise<List<D>> diff(OTRepository<K, D> repository, OTSystem<D> system, K node1, K node2); static Promise<Set<K>> excludeParents(OTRepository<K, D> repository, OTSystem<D> system, Set<K> startNodes); static Promise<Map<K, A>> reduceEdges(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads, K parentNode,
			DiffsReducer<A, D> diffAccumulator); static Promise<List<D>> checkout(OTRepository<K, D> repository, OTSystem<D> system); static Promise<List<D>> checkout(OTRepository<K, D> repository, OTSystem<D> system, K commitId); static Promise<Void> saveSnapshot(OTRepository<K, D> repository, OTSystem<D> system, K revisionId); static Promise<OTLoadedGraph<K, D>> loadForMerge(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads); static Promise<OTLoadedGraph<K, D>> loadGraph(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads, OTLoadedGraph<K, D> graph); static Promise<OTLoadedGraph<K, D>> loadGraph(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads); static Promise<OTLoadedGraph<K, D>> loadGraph(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads, Function<K, String> idToString, Function<D, String> diffToString); static Promise<Void> copy(OTRepository<K, D> from, OTRepository<K, D> to); }
OTAlgorithms { public static <K, D, A> Promise<Map<K, A>> reduceEdges(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads, K parentNode, DiffsReducer<A, D> diffAccumulator) { return reduce(repository, system, heads, new AbstractGraphReducer<K, D, A, Map<K, A>>(diffAccumulator) { @NotNull @Override protected Promise<Optional<Map<K, A>>> tryGetResult(OTCommit<K, D> commit, Map<K, Map<K, A>> accumulators, Map<K, OTCommit<K, D>> headCommits) { if (accumulators.containsKey(parentNode)) { Map<K, A> toHeads = accumulators.get(parentNode); if (Objects.equals(heads, toHeads.keySet())) { return Promise.of(Optional.of(toHeads)); } } return Promise.of(Optional.empty()); } }); }  static Promise<R> reduce(OTRepository<K, D> repository, OTSystem<D> system,
			Set<K> heads, GraphReducer<K, D, R> reducer); static Promise<FindResult<K, A>> findParent(OTRepository<K, D> repository, OTSystem<D> system,
			Set<K> startNodes, DiffsReducer<A, D> diffsReducer, AsyncPredicate<OTCommit<K, D>> matchPredicate); static Promise<K> mergeAndPush(OTRepository<K, D> repository, OTSystem<D> system); static Promise<K> mergeAndPush(OTRepository<K, D> repository, OTSystem<D> system, @NotNull Set<K> heads); static Promise<K> mergeAndUpdateHeads(OTRepository<K, D> repository, OTSystem<D> system); static Promise<K> mergeAndUpdateHeads(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads); @NotNull static Promise<OTCommit<K, D>> merge(OTRepository<K, D> repository, OTSystem<D> system, @NotNull Set<K> heads); static Promise<Set<K>> findCut(OTRepository<K, D> repository, OTSystem<D> system, Set<K> startNodes,
			Predicate<Collection<OTCommit<K, D>>> matchPredicate); static Promise<K> findAnyCommonParent(OTRepository<K, D> repository, OTSystem<D> system, Set<K> startCut); static Promise<Set<K>> findAllCommonParents(OTRepository<K, D> repository, OTSystem<D> system, Set<K> startCut); static Promise<List<D>> diff(OTRepository<K, D> repository, OTSystem<D> system, K node1, K node2); static Promise<Set<K>> excludeParents(OTRepository<K, D> repository, OTSystem<D> system, Set<K> startNodes); static Promise<Map<K, A>> reduceEdges(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads, K parentNode,
			DiffsReducer<A, D> diffAccumulator); static Promise<List<D>> checkout(OTRepository<K, D> repository, OTSystem<D> system); static Promise<List<D>> checkout(OTRepository<K, D> repository, OTSystem<D> system, K commitId); static Promise<Void> saveSnapshot(OTRepository<K, D> repository, OTSystem<D> system, K revisionId); static Promise<OTLoadedGraph<K, D>> loadForMerge(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads); static Promise<OTLoadedGraph<K, D>> loadGraph(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads, OTLoadedGraph<K, D> graph); static Promise<OTLoadedGraph<K, D>> loadGraph(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads); static Promise<OTLoadedGraph<K, D>> loadGraph(OTRepository<K, D> repository, OTSystem<D> system, Set<K> heads, Function<K, String> idToString, Function<D, String> diffToString); static Promise<Void> copy(OTRepository<K, D> from, OTRepository<K, D> to); static final StacklessException GRAPH_EXHAUSTED; }