From 46674f5133dabef43bf58d98bb5edbdb61f43262 Mon Sep 17 00:00:00 2001 From: Tomas Mikula Date: Thu, 21 Apr 2016 13:38:57 -0400 Subject: [PATCH] Add method FingerTree.mkTree(List) to create a tree without additional summary kept in the nodes. --- .../main/java/org/reactfx/util/FingerTree.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/reactfx/src/main/java/org/reactfx/util/FingerTree.java b/reactfx/src/main/java/org/reactfx/util/FingerTree.java index 598e5a7..a5d3cb5 100644 --- a/reactfx/src/main/java/org/reactfx/util/FingerTree.java +++ b/reactfx/src/main/java/org/reactfx/util/FingerTree.java @@ -814,20 +814,27 @@ public static FingerTree empty( return new Empty<>(statisticsProvider); } + public static FingerTree mkTree(List items) { + return mkTree(items, new ToSemigroup() { + @Override public Void apply(T t) { return null; } + @Override public Void reduce(Void left, Void right) { return null; } + }); + } + public static FingerTree mkTree( List initialItems, - ToSemigroup statisticsProvider) { + ToSemigroup summaryProvider) { if(initialItems.isEmpty()) { - return new Empty<>(statisticsProvider); + return new Empty<>(summaryProvider); } List> leafs = new ArrayList<>(initialItems.size()); for(T item: initialItems) { - leafs.add(new Leaf(statisticsProvider, item)); + leafs.add(new Leaf(summaryProvider, item)); } - return mkTree(leafs); + return mkTree0(leafs); } - private static FingerTree mkTree(List> trees) { + private static FingerTree mkTree0(List> trees) { while(trees.size() > 1) { for(int i = 0; i < trees.size(); ++i) { if(trees.size() - i >= 5 || trees.size() - i == 3) {