asap_sketchlib 0.2.0

A high-performance sketching library for approximate stream processing
Documentation
use std::{
    fs::File,
    io::{BufWriter, Write},
    path::PathBuf,
};

use asap_sketchlib::{DataInput, hash128_seeded};

const OUTPUT_PATH: &str = "src/common/precompute_hash.rs";
const MAX_VALUE: u64 = 0x3fff;
const SEED_INDEX: usize = 0;

fn main() -> std::io::Result<()> {
    let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(OUTPUT_PATH);
    let file = File::create(&path)?;
    let mut writer = BufWriter::new(file);

    writeln!(
        writer,
        "//! Auto-generated by `cargo run --bin generate_precomputed_hash`."
    )?;
    writeln!(
        writer,
        "//! Precomputes hash128_seeded for DataInput::U64(0)..=DataInput::U64(0x3fff)."
    )?;
    writeln!(writer, "pub static PRECOMPUTED_HASH: [u128; 0x4000] = [")?;

    for value in 0..=MAX_VALUE {
        let hash = hash128_seeded(SEED_INDEX, &DataInput::U64(value));
        writeln!(writer, "    0x{hash:032x}, // {value:#06x}")?;
    }

    writeln!(writer, "];")?;

    Ok(())
}