Skip to content

ludus::foundation::math::WeightedReservoir

Ludus Wiki · API overview · Browse API

Class

Single-sample, with-replacement weighted reservoir over a caller-fixed candidate order.
A default-constructed reservoir is empty. Stream every candidate, including zero-weight ones, through TryAddReservoirCandidate in the same order on every evaluation: the outcome depends on that order and on each candidate's ticket, not on an address alone. The reservoir holds no candidate payload; record the payload of a candidate when the update reports it as selected. Plain value type with no allocation or thread affinity.

Declared in modules/foundation/math/include/ludus/foundation/math/weighted_reservoir.hpp

#include <ludus/foundation/math/weighted_reservoir.hpp>
class ludus::foundation::math::WeightedReservoir

Methods

GetWeightSum

LUDUS_INLINE float32 ludus::foundation::math::WeightedReservoir::GetWeightSum() const noexcept
Sum of the weights streamed so far, after the minimum-weight flush; zero when empty.

Related types: float32

Declared in modules/foundation/math/include/ludus/foundation/math/weighted_reservoir.hpp

GetCandidateCount

LUDUS_INLINE uint32 ludus::foundation::math::WeightedReservoir::GetCandidateCount() const noexcept
Number of candidates streamed so far, zero-weight candidates included (RIS M).

Related types: uint32

Declared in modules/foundation/math/include/ludus/foundation/math/weighted_reservoir.hpp

GetSelectedIndex

LUDUS_INLINE uint32 ludus::foundation::math::WeightedReservoir::GetSelectedIndex() const noexcept
Zero-based stream position of the selected candidate; zero when HasSelection() is false.

Related types: uint32

Declared in modules/foundation/math/include/ludus/foundation/math/weighted_reservoir.hpp

HasSelection

LUDUS_INLINE bool ludus::foundation::math::WeightedReservoir::HasSelection() const noexcept
True once any candidate with a weight of at least WEIGHTED_RESERVOIR_MINIMUM_WEIGHT has been streamed.
An empty reservoir after the whole stream (zero total weight) is a valid outcome that contributes zero, not an invalid sample.

Declared in modules/foundation/math/include/ludus/foundation/math/weighted_reservoir.hpp