Report the size of the underlying tree structure.
Report the size of the underlying tree structure.
This is an O(1) operation -- each subtree knows how big it is.
Sum all the T
values in this batch using the given semigroup.
Add more values to a batched value.
Add more values to a batched value.
This method will grow the tree to the left.
Combine two batched values.
Combine two batched values.
As mentioned above, this just creates a new tree structure
containing this
and that
.
Compact this batch if it exceeds batchSize
.
Compact this batch if it exceeds batchSize
.
Compacting a branch means summing it, and then storing the summed value in a new single-item batch.
Provide an iterator over the underlying tree structure.
Provide an iterator over the underlying tree structure.
This is the order used by .sum
.
This iterator traverses the tree from left-to-right. If the original expression was (w + x + y + z), this iterator returns w, x, y, and then z.
Provide a reversed iterator over the underlying tree structure.
Provide a reversed iterator over the underlying tree structure.
This iterator traverses the tree from right-to-left. If the original expression was (w + x + y + z), this iterator returns z, y, x, and then w.
Convert the batch to a List[T]
.
Batched: the free semigroup.
For any type
T
,Batched[T]
represents a way to lazily combine T values as a semigroup would (i.e. associatively). ASemigroup[T]
instance can be used to recover aT
value from aBatched[T]
.Like other free structures, Batched trades space for time. A sum of batched values defers the underlying semigroup action, instead storing all values in memory (in a tree structure). If an underlying semigroup is available,
Batched.semigroup
andBatch.monoid
can be configured to periodically sum the tree to keep the overall size belowbatchSize
.Batched[T]
values are guaranteed not to be empty -- that is, they will contain at least oneT
value.