ShareLine
What every group is owed of the whole pool while one waiting set holds still, and how far each stands from it: one read of the tree, answered group by group with share and lag. A table that shows a share on every row reads one line and looks each row up, rather than asking the engine once per row.
Get one from LocalHeddle.shareLine or LocalHeddleView.shareLine. It is a value: it keeps what it read of the tree and of the wake memory when it was taken, so it answers the same however the engine moves on, and any number of threads may read it at once.
Samples
val tree = draft("pool") {
group("research", Weight.of(2)) {
lane("gpu", Weight.of(3))
lane("cpu")
}
lane("ops")
lane("docs")
}
val pool = tree.groupId()
val research = tree.groupId("research")
val gpu = tree.groupId("research", "gpu")
val cpu = tree.groupId("research", "cpu")
val ops = tree.groupId("ops")
val docs = tree.groupId("docs")
val (heddle, booted) = LocalHeddle.fromTopology(tree, LocalPolicy(defaultReservation = 1L), epoch = 0L)
check(booted.refusals.isEmpty())
// Docs has nothing queued, so research (weight 2) and ops (weight 1) split the pool 2 : 1.
val queued = setOf(gpu, cpu, ops)
val line = heddle.shareLine(queued)
check(line.share(pool) == Rational.ONE)
check(line.share(research) == Rational.of(2L, 3L))
check(line.share(ops) == Rational.of(1L, 3L))
check(line.share(docs) == Rational.ZERO)
// Research's share is its lanes' entitlements of one slot, added up.
check(line.share(gpu) == heddle.entitlement(gpu, queued, totalSlots = 1L))
check(line.share(research) == heddle.entitlement(gpu, queued, 1L) + heddle.entitlement(cpu, queued, 1L))
// With nothing queued anywhere, nothing competes, and even the pool is owed nothing.
check(heddle.shareLine(emptySet()).share(pool) == Rational.ZERO)Functions
How far group stands from its share at its parent, in units of service: positive when it is owed that much, negative when it has had that much more than its share. A team two units of service behind where its weight puts it reads 2, and the siblings that ran ahead of it read below 0 between them by as much.
The share of the whole pool group and everything beneath it are owed, as an exact fraction of 1: group's weight over the summed weights of the siblings competing beside it, times its parent's fraction among the siblings beside that, up to the root. Which groups compete is said on LocalHeddleView.shareLine, and so is why a ceiling makes this no capped rate.