Run Tree
A RunTree maintains a mapping from Long to some value which is expected to be the same for runs of consecutive Longs. This is not thread-safe, and should be protected with an external ReadWriteLock to allow readers and writers to coordinate safely.
The null value is treated as the absence of a run. The edit method takes two Longs representing the affected range (degenerate ranges have no effect) and a function taking a Value or null, and returning a Value or null to use in its place. The function is evaluated zero or more times to produce edits of existing runs, which will then be subject to the RunTree`s normalization rules:
No empty ranges,
No
nullvalues in ranges,No overlapping ranges,
Two contiguous ranges will not have the same Value, by equality.
Ranges are not allowed to include Long.MAX_VALUE.
In addition, the RunTree is Iterable, allowing traversal over the
Author
Mark van Gulik
Functions
Transform each (non-null) range of the receiver via a transform function, yielding another RunTree with the same ranges and corresponding transformed values. If the transform produces a null, that range is dropped in the output. If two or more contiguous ranges transform into non-null ResultValues that are equal, they will be collapsed into a single range in the output.
Given the receiver, which is a RunTree<Value>, and the otherTree, which is a RunTree<OtherValue>, produce an aggregate RunTree<OutputValue>. The OutputValue for each range will be computed from a transform function taking a nullable Value and a nullable OtherValue (but both won't be null), and producing a nullable OutputValue. The resulting RunTree respects the normalization rules of the class.
Given the receiver, which is a RunTree<Value>, and the otherTree, which is a RunTree<OtherValue>, produce an aggregate RunTree<Pair<Value?, OtherValue?>. The ranges will be split as needed to ensure that the spans in the output have: