fp-columnar 0.2.0

Columnar storage primitives (Column, ValidityMask) for pandas-parity dataframes — the storage layer behind fp-frame.
Documentation
//! Bench for `Column::argsort_with` on a nullable (or NaN-bearing) Float64 column
//! — the na-last Float64 radix path in typed_radix_perm. Checksum folds the
//! returned permutation so treatment (radix) vs control (Scalar) must match.
//!
//! A/B via the `FP_NO_NULL_SORT_F64` env gate (set ⇒ Scalar comparator).
//!
//! Run: cargo run -p fp-columnar --example bench_sort_f64null --release -- 5000000 15 null asc
//! (arg3: "nan" ⇒ present-NaN via from_f64_values, else nullable-missing)

use fp_columnar::{Column, ValidityMask};

fn main() {
    let a: Vec<String> = std::env::args().collect();
    let n: usize = a.get(1).and_then(|s| s.parse().ok()).unwrap_or(5_000_000);
    let iters: usize = a.get(2).and_then(|s| s.parse().ok()).unwrap_or(15);
    let nan_mode = a.get(3).map(String::as_str).unwrap_or("null") == "nan";
    let ascending = a.get(4).map(String::as_str).unwrap_or("asc") != "desc";

    let base: Vec<f64> = (0..n)
        .map(|i| {
            let h = (i as u64).wrapping_mul(2_654_435_761).wrapping_add(12_345);
            ((h % 100_003) as f64 - 50_001.0) * 0.5
        })
        .collect();
    let col = if nan_mode {
        // Present-NaN at every 7th slot (validity all-valid; is_missing via NaN).
        let data: Vec<f64> = base
            .iter()
            .enumerate()
            .map(|(i, &v)| if i % 7 == 0 { f64::NAN } else { v })
            .collect();
        Column::from_f64_values(data)
    } else {
        let mut validity = ValidityMask::all_valid(n);
        for i in (0..n).step_by(7) {
            validity.set(i, false);
        }
        Column::from_f64_values_with_validity(base, validity)
    };

    let mut best = u128::MAX;
    let mut checksum: u64 = 0;
    for _ in 0..iters {
        let t = std::time::Instant::now();
        let perm = col.argsort_with(ascending);
        best = best.min(t.elapsed().as_nanos());
        let mut h: u64 = 0xcbf2_9ce4_8422_2325;
        for &p in &perm {
            h ^= p as u64;
            h = h.wrapping_mul(0x0000_0100_0000_01b3);
        }
        checksum = checksum.wrapping_add(h);
    }
    let gated = std::env::var("FP_NO_NULL_SORT_F64").is_ok();
    println!(
        "sort_f64null mode={} asc={ascending} n={n} iters={iters} fast_path={} best={best}ns ({:.3}ms) checksum={checksum}",
        if nan_mode { "nan" } else { "null" },
        !gated,
        best as f64 / 1e6,
    );
}