Skip to main content

Module alias

Module alias 

Source
Expand description

Vose’s alias method for O(1) sampling from discrete distributions.

Given N outcomes with associated weights, an alias table pre-computes a structure that allows selecting an outcome in constant time from a single uniform u64 input.

Two variants:

  • AliasTable<T>: generic, works with any Clone outcome type.
  • AliasTableU64: flat parallel arrays, optimized for the Phase 2 compiled kernel path where outcomes are indices 0..N.

Structs§

AliasSample
Sample an outcome index from a pre-built alias table over weights. The input is a uniform u64 (hash upstream for pseudo-random dispersion); the output is the chosen outcome index.
AliasTable
Generic alias table for O(1) weighted sampling.
AliasTableU64
Alias table optimized for u64 outcomes (indices 0..N).