fn checkWeights(weights: []const Weight, max_incl: u64) void weights: []const Weightmax_incl: u64177
178
179
180
181
182
183
184
185
186
187
188
189
190
191fn checkWeights(weights: []const Weight, max_incl: u64) void {
@disableInstrumentation();
const w0 = weights[0]; // Sum of weights is zero
assert(w0.weight != 0);
assert(w0.max <= max_incl);
var incl_sum: u64 = (w0.max - w0.min) * w0.weight + (w0.weight - 1); // Sum of weights greater than 2^64
for (weights[1..]) |w| {
assert(w.weight != 0);
assert(w.max <= max_incl);
// This addition will not overflow except with an illegal combination of weights since
// the exclusive sum must be at least one so a span of all values is impossible.
incl_sum += (w.max - w.min + 1) * w.weight; // Sum of weights greater than 2^64
}
}