Skip to content

Commit

Permalink
Add method FingerTree.mkTree(List<T>) to create a tree without additi…
Browse files Browse the repository at this point in the history
…onal summary kept in the nodes.
  • Loading branch information
TomasMikula committed Apr 21, 2016
1 parent 98bddff commit 46674f5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions reactfx/src/main/java/org/reactfx/util/FingerTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -814,20 +814,27 @@ public static <T, S> FingerTree<T, S> empty(
return new Empty<>(statisticsProvider);
}

public static <T> FingerTree<T, Void> mkTree(List<? extends T> items) {
return mkTree(items, new ToSemigroup<T, Void>() {
@Override public Void apply(T t) { return null; }
@Override public Void reduce(Void left, Void right) { return null; }
});
}

public static <T, S> FingerTree<T, S> mkTree(
List<? extends T> initialItems,
ToSemigroup<? super T, S> statisticsProvider) {
ToSemigroup<? super T, S> summaryProvider) {
if(initialItems.isEmpty()) {
return new Empty<>(statisticsProvider);
return new Empty<>(summaryProvider);
}
List<NonEmptyFingerTree<T, S>> leafs = new ArrayList<>(initialItems.size());
for(T item: initialItems) {
leafs.add(new Leaf<T, S>(statisticsProvider, item));
leafs.add(new Leaf<T, S>(summaryProvider, item));
}
return mkTree(leafs);
return mkTree0(leafs);
}

private static <T, S> FingerTree<T, S> mkTree(List<NonEmptyFingerTree<T, S>> trees) {
private static <T, S> FingerTree<T, S> mkTree0(List<NonEmptyFingerTree<T, S>> trees) {
while(trees.size() > 1) {
for(int i = 0; i < trees.size(); ++i) {
if(trees.size() - i >= 5 || trees.size() - i == 3) {
Expand Down

0 comments on commit 46674f5

Please sign in to comment.