tilezz 0.2.0

Utilities to work with perfect-precision polygonal tiles built on top of cyclotomic integer rings.
Documentation
//! Cross-cutting utilities used by binaries and various library modules: the
//! [`profile`] RAII helper for optional `pprof` flamegraph recording from the
//! CLI binaries, plus small numeric helpers like `gcd`.

pub(crate) mod parallel;
pub mod profile;

/// How many worker threads to use when the caller has no explicit request: the
/// machine's available parallelism, or `4` if the OS cannot report it (a rare
/// fallback -- assume a few cores rather than serialize). The single "count the
/// cores" helper behind the CLI bins and the classify parallel sweeps; each
/// caller layers its own request/cap policy on top (e.g. "0 means all", or
/// "cap the requested count at this").
pub fn available_workers() -> usize {
    std::thread::available_parallelism().map_or(4, |x| x.get())
}

/// Greatest common divisor of two integers (Euclid, iterative). Result is
/// non-negative; `gcd(0, 0) == 0`. The single copy behind the sites that each
/// used to roll their own (ring symmetry order, prune-moduli coprimality).
pub(crate) fn gcd(mut a: i64, mut b: i64) -> i64 {
    while b != 0 {
        let t = b;
        b = a % b;
        a = t;
    }
    a.abs()
}