Function precompute_linear_counting

Source
pub const fn precompute_linear_counting<const NUMBER_OF_REGISTERS: usize>() -> [f32; NUMBER_OF_REGISTERS]
Expand description

Precomputes small corrections for HyperLogLog algorithm.

This function calculates a correction factor for each register that helps to improve the accuracy of the HyperLogLog algorithm. The corrections are stored in an array and can be accessed for later use by other methods of the HyperLogLog struct.

§Arguments

  • NUMBER_OF_REGISTERS - The number of registers used in the HyperLogLog algorithm.

§Examples

use hyperloglog_rs::utils::precompute_linear_counting;
use hyperloglog_rs::log::log;

const NUMBER_OF_REGISTERS: usize = 16;
let small_corrections = precompute_linear_counting::<NUMBER_OF_REGISTERS>();
assert_eq!(small_corrections.len(), NUMBER_OF_REGISTERS);
assert_eq!(small_corrections[0], NUMBER_OF_REGISTERS as f32 * log(NUMBER_OF_REGISTERS as f64) as f32);
assert_eq!(small_corrections[1], NUMBER_OF_REGISTERS as f32 * log(NUMBER_OF_REGISTERS as f64 / 2.0_f64) as f32);