55 uint32_t
permute(uint32_t x)
const;
65 uint32_t
invert(uint32_t y)
const;
97 uint32_t
roundFunction(uint32_t half,
unsigned int round)
const;
105 static unsigned int ceilLog2(uint32_t n);
114 static uint32_t
mix32(uint32_t x);
121 const unsigned int _n;
137 uint64_t seed = (
static_cast<uint64_t
>(v.
_k1) << 32) | v.
_k0;
145dataStore(std::ostream & stream, std::unique_ptr<MooseRandomPerturbation> & v,
void * context)
152dataLoad(std::istream & stream, std::unique_ptr<MooseRandomPerturbation> & v,
void * context)
155 unsigned int n, rounds;
159 v = std::make_unique<MooseRandomPerturbation>(seed, n, rounds);
void dataLoad(std::istream &stream, std::unique_ptr< MooseRandomPerturbation > &v, void *context)
void dataStore(std::ostream &stream, MooseRandomPerturbation &v, void *context)
Generates a keyed pseudo-random permutation of the integers [0, n) using a balanced Feistel network.
const uint32_t _k0
Lower 32 bits of the seed, used as the first subkey in the round function.
const unsigned int _n
Size of the permutation domain [0, n)
uint32_t invert(uint32_t y) const
Recover the original index from a permuted value, i.e.
const uint32_t _k1
Upper 32 bits of the seed, used as the second subkey in the round function.
const unsigned int _half_bits
Number of bits in each Feistel half-block: ceil((ceil(log2(n)) + 1) / 2)
const unsigned int _rounds
Number of Feistel rounds to apply per permute/invert call.
static uint32_t mix32(uint32_t x)
Bijective 32-bit avalanche hash (finalizer from Murmur3 / degski hash).
static unsigned int ceilLog2(uint32_t n)
Return the number of bits needed to represent values in [0, n-1], i.e.
const uint32_t _half_mask
Bitmask of width _half_bits, used to keep half-block arithmetic in range.
uint32_t permute(uint32_t x) const
Map x to its permuted index in [0, n).
uint32_t permutePadded(uint32_t x) const
Apply one full pass of the balanced Feistel network over the padded domain [0, 2^(2*half_bits)).
uint32_t roundFunction(uint32_t half, unsigned int round) const
Keyed round function F(half, round) used in each Feistel step.
uint32_t invertPadded(uint32_t y) const
Invert one full pass of the Feistel network by running rounds in reverse.