LLVM 22.0.0git
llvm::ReservoirSampler< T, GenT > Class Template Reference

Randomly selects an item by sampling into a set with an unknown number of elements, which may each be weighted to be more likely choices. More...

#include "llvm/FuzzMutate/Random.h"

Public Member Functions

 ReservoirSampler (GenT &RandGen)
uint64_t totalWeight () const
bool isEmpty () const
const TgetSelection () const
 operator bool () const
const Toperator* () const
template<typename RangeT>
ReservoirSamplersample (RangeT &&Items)
 Sample each item in Items with unit weight.
ReservoirSamplersample (const T &Item, uint64_t Weight)
 Sample a single item with the given weight.

Detailed Description

template<typename T, typename GenT>
class llvm::ReservoirSampler< T, GenT >

Randomly selects an item by sampling into a set with an unknown number of elements, which may each be weighted to be more likely choices.

Definition at line 33 of file Random.h.

Constructor & Destructor Documentation

◆ ReservoirSampler()

template<typename T, typename GenT>
llvm::ReservoirSampler< T, GenT >::ReservoirSampler ( GenT & RandGen)
inline

Definition at line 39 of file Random.h.

Referenced by sample(), and sample().

Member Function Documentation

◆ getSelection()

template<typename T, typename GenT>
const T & llvm::ReservoirSampler< T, GenT >::getSelection ( ) const
inline

Definition at line 44 of file Random.h.

References assert(), isEmpty(), and T.

Referenced by operator*().

◆ isEmpty()

template<typename T, typename GenT>
bool llvm::ReservoirSampler< T, GenT >::isEmpty ( ) const
inline

Definition at line 42 of file Random.h.

Referenced by getSelection(), and operator bool().

◆ operator bool()

template<typename T, typename GenT>
llvm::ReservoirSampler< T, GenT >::operator bool ( ) const
inlineexplicit

Definition at line 49 of file Random.h.

References isEmpty().

◆ operator*()

template<typename T, typename GenT>
const T & llvm::ReservoirSampler< T, GenT >::operator* ( ) const
inline

Definition at line 50 of file Random.h.

References getSelection(), and T.

◆ sample() [1/2]

template<typename T, typename GenT>
ReservoirSampler & llvm::ReservoirSampler< T, GenT >::sample ( const T & Item,
uint64_t Weight )
inline

Sample a single item with the given weight.

Definition at line 60 of file Random.h.

References ReservoirSampler(), T, and llvm::uniform().

◆ sample() [2/2]

template<typename T, typename GenT>
template<typename RangeT>
ReservoirSampler & llvm::ReservoirSampler< T, GenT >::sample ( RangeT && Items)
inline

Sample each item in Items with unit weight.

Definition at line 53 of file Random.h.

References I, ReservoirSampler(), and sample().

Referenced by llvm::makeSampler(), llvm::makeSampler(), and sample().

◆ totalWeight()

template<typename T, typename GenT>
uint64_t llvm::ReservoirSampler< T, GenT >::totalWeight ( ) const
inline

Definition at line 41 of file Random.h.


The documentation for this class was generated from the following file: