Macaw.Data.Source.Demand (macaw_data v0.21.1)
View SourceThe union of a source's subscribed windows, as a value (dco-tek/macaw/macaw#108, spec/01 §6.4.1): sorted, disjoint ranges of chunk slots, each with the set of readers covering it, whose size is its reference count.
A range is {lo, hi}: the slots from lo up to but not including hi, integers, either
nil for unbounded. The segments are held in a balanced tree keyed by their start, so
add/3 and remove/3 find the segments a range touches in O(log n), split only those
at the range's ends, change their readers, and join neighbors left with the same
readers. Each answers only the change in demand: the slots no reader covered before, or
covers now. Nothing sorts or merges every window.
iex> alias Macaw.Data.Source.Demand
iex> {d, needed} = Demand.add(Demand.new(), :a, {0, 10})
iex> needed
[{0, 10}]
iex> {d, needed} = Demand.add(d, :b, {5, 15})
iex> needed
[{10, 15}]
iex> Demand.ranges(d)
[{0, 15}]
iex> {_d, released} = Demand.remove(d, :a, {0, 10})
iex> released
[{0, 5}]
Summary
Functions
reader covering range too: {demand, needed}, the ranges no reader covered before,
in order. A reader added twice over the same slots is held once.
No demand.
The demanded ranges: sorted, disjoint, merged where they meet.
The readers covering slot slot, in no set order.
reader no longer covering range: {demand, released}, the ranges no reader covers
now, merged where they meet, in order.
How many segments the demand holds: at most twice the readers' ranges.
Types
Functions
reader covering range too: {demand, needed}, the ranges no reader covered before,
in order. A reader added twice over the same slots is held once.
@spec new() :: t()
No demand.
The demanded ranges: sorted, disjoint, merged where they meet.
The readers covering slot slot, in no set order.
reader no longer covering range: {demand, released}, the ranges no reader covers
now, merged where they meet, in order.
@spec segments(t()) :: non_neg_integer()
How many segments the demand holds: at most twice the readers' ranges.