Weight

@Serializable(with = WeightSerializer::class)
class Weight : Comparable<Weight>

A sibling's fairness share, expressed as a positive integer ratio.

Weights only ever have meaning relative to their siblings — "three parts to one" — so a Weight is a numerator/denominator pair, reduced to lowest terms on construction (2/4 and 1/2 are the same weight). Two weights are ordered by exact cross-multiplication with overflow detection — never by converting to Double — because the scheduler's ordering must be bit-identical on JVM, Native, and wasmJs, and floating point is not (design §2). A comparison that would overflow Long throws rather than silently returning a wrong order.

A Weight crosses the wire inside AttachmentRecord — replicated in the EntitlementLedger and carried by the Raft Prepare command — so the read path is a second construction path and enforces the same invariant: WeightSerializer routes every decoded pair through of rather than into the constructor, and a denormalized encoding (2/4, -1/-2) is repaired to its canonical form rather than admitted. See WeightSerializer for why repair, not rejection.

Samples

// Weights are compared by exact cross-multiplication, never floating point.
check(Weight.of(1, 3) < Weight.of(1, 2))
check(Weight.of(2, 4) == Weight.of(1, 2))

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

the ratio's denominator; always > 0 and coprime with numerator.

Link copied to clipboard

the ratio's numerator; always > 0 and coprime with denominator.

Functions

Link copied to clipboard
open operator override fun compareTo(other: Weight): Int

Order by exact cross-multiplication: a/b <=> c/d compares a*d against c*b. Both products are overflow-checked, so an out-of-range comparison throws ArithmeticException rather than wrapping to a wrong verdict.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun toString(): String