RunTree

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 null values 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 triples in ascending order.

Author

Mark van Gulik

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun edit(start: Int, pastEnd: Int, edit: (Value?) -> Value?)

Run the edit action for each Value or null within the given range, to produce an alternative Value. This form takes Int arguments as a convenience.

fun edit(start: Long, pastEnd: Long, edit: (Value?) -> Value?)

Run the edit action for each Value or null within the given range, to produce an alternative Value.

Link copied to clipboard
open fun forEach(p0: Consumer<in Triple<Long, Long, Value>>)
Link copied to clipboard
open operator override fun iterator(): Iterator<Triple<Long, Long, Value>>

Produce an iterator over the (non-null) ranges, in ascending order. The ranges are Triples of the form .

Link copied to clipboard

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.

Link copied to clipboard
inline fun <T, R> Iterable<T>.mapToSet(destination: MutableSet<R> = mutableSetOf(), transform: (T) -> R): MutableSet<R>

Transform the receiver via the supplied function and collect the results into an optionally provided set. Answer the result set.

Link copied to clipboard
Link copied to clipboard

Given text of a quoted method name and the starting offset that the text occurs at, update the receiver, a RunTree, to contain the symbolic style names that should color the text.

Link copied to clipboard

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.

Link copied to clipboard

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: