Assign a random layer using the exponential distribution. Capped at `MAX_LAYER_CAP` to prevent pathological RNG draws from promoting the index's `max_layer` to hundreds or thousands, which would make every search's Phase-1 greedy descent O(max_layer).
(&mut self)
| 346 | /// promoting the index's `max_layer` to hundreds or thousands, which |
| 347 | /// would make every search's Phase-1 greedy descent O(max_layer). |
| 348 | pub(crate) fn random_layer(&mut self) -> usize { |
| 349 | let ml = 1.0 / (self.params.m as f64).ln(); |
| 350 | let r = self.rng.next_f64().max(f64::MIN_POSITIVE); |
| 351 | let layer = (-r.ln() * ml).floor() as usize; |
| 352 | layer.min(MAX_LAYER_CAP) |
| 353 | } |
| 354 | |
| 355 | /// Compute distance between a pre-encoded query and a stored node. |
| 356 | /// |