Skip to content

Commit 576f735

Browse files
committed
Fixes stream collector dropping elements in some cases.
1 parent 3dbf663 commit 576f735

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/main/java/org/javimmutable/collections/btree_list/BtreeNodeBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
package org.javimmutable.collections.btree_list;
3737

3838
import org.javimmutable.collections.indexed.IndexedArray;
39+
import org.javimmutable.collections.iterators.SingleValueIterator;
3940

4041
import javax.annotation.Nonnull;
4142
import java.util.Iterator;
@@ -73,7 +74,7 @@ synchronized void rebuild(@Nonnull BtreeNode<T> root)
7374
{
7475
leafBuilder.clear();
7576
size = 0;
76-
Iterator<BtreeNode<T>> nodes = root.childIterator();
77+
Iterator<BtreeNode<T>> nodes = root.depth() > 1 ? root.childIterator() : SingleValueIterator.of(root);
7778
while (nodes.hasNext()) {
7879
final BtreeNode<T> node = nodes.next();
7980
if (nodes.hasNext()) {
@@ -88,6 +89,7 @@ synchronized void rebuild(@Nonnull BtreeNode<T> root)
8889
size += node.valueCount();
8990
}
9091
}
92+
assert size == root.valueCount();
9193
}
9294

9395
synchronized BtreeNode<T> build()

0 commit comments

Comments
 (0)