RunTree

class RunTree<Value> : Iterable<Triple<Long, Long, Value>>

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
fun RunTree()

Functions

Link copied to clipboard
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
open fun spliterator(): Spliterator<Triple<Long, Long, Value>>

Properties

Link copied to clipboard
val tree: TreeMap<Long, Pair<Long, Value>>

The basic representation is a TreeMap from each run's start to a Pair containing the position just past the run's end and the value associated with that run. This is maintained in such a way that no runs overlap, no runs are empty, and there are no contiguous runs with equal values (they are automatically merged).