Assign a random layer per the HNSW exponential distribution. Capped at `MAX_LAYER_CAP` to prevent pathological draws from inflating `max_layer`.
(&mut self)
| 105 | /// Capped at `MAX_LAYER_CAP` to prevent pathological draws from inflating |
| 106 | /// `max_layer`. |
| 107 | pub fn random_layer(&mut self) -> usize { |
| 108 | let r = self.rng.next_f64().max(f64::MIN_POSITIVE); |
| 109 | let layer = (-r.ln() * self.level_mult as f64).floor() as usize; |
| 110 | layer.min(MAX_LAYER_CAP) |
| 111 | } |
| 112 | |
| 113 | /// Return a reference to the quantized payload at `idx`, if present and |
| 114 | /// not deleted. |