1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Lazily-built table of `ln(1 - u)` draws used to amortise geometric-skip
//! sampling.
//!
//! Storing this as a [`LazyLock`] instead of a 64K-entry literal array keeps
//! the crate small enough to publish to crates.io while preserving the same
//! `PRECOMPUTED_SAMPLE[i]` access pattern. The table is generated once per
//! process from a [`SmallRng`] with a fixed seed, so values are stable
//! across runs and across versions of this crate.
use LazyLock;
use SmallRng;
use ;
/// Number of precomputed entries. `PRECOMPUTED_SAMPLE[i]` is defined for
/// `i` in `0..PRECOMPUTED_SAMPLE_LEN`.
pub const PRECOMPUTED_SAMPLE_LEN: usize = 0x10000;
/// Fixed seed used to make the table reproducible across runs / versions.
const SEED: u64 = 0xA5A0_5A71_B11B_C0DE_u64;
/// Precomputes part of geometric sampling: `ln(1 - u)` with
/// `u` drawn uniformly from the open interval `(0, 1)`.
///
/// The table is materialised lazily on first access through [`LazyLock`].
/// Indexing (`PRECOMPUTED_SAMPLE[i]`), iteration (`PRECOMPUTED_SAMPLE.iter()`),
/// and length (`PRECOMPUTED_SAMPLE.len()`) all work via `Deref` to the
/// underlying slice.
pub static PRECOMPUTED_SAMPLE: =
new;
/// Builds a length-`PRECOMPUTED_SAMPLE_LEN` boxed slice whose i-th entry is
/// `ln(1 - u_i) * scale`, where `u_i ∈ (0, 1)` is drawn from a `SmallRng`
/// seeded with [`SEED`].
///
/// Shared by [`PRECOMPUTED_SAMPLE`] and
/// [`super::precompute_sample2::PRECOMPUTED_SAMPLE_RATE_1PERCENT`].
pub