Data-CountMinSketch-Shared

 view release on metacpan or  search on metacpan

cms.h  view on Meta::CPAN

    double w_opt_d = ceil(M_E / epsilon);
    if (w_opt_d > (double)CMS_MAX_W) { CMS_ERR("epsilon too small for the column cap"); return 0; }
    uint64_t w = cms_next_pow2_u64((uint64_t)w_opt_d);

    /* d = ceil(log(1/delta)) clamped to [1, 32].  Clamp in DOUBLE before the cast:
       a delta below 1/DBL_MAX (~5.6e-309) makes 1.0/delta overflow to +inf, and
       (long)inf is undefined -- on x86-64 it yields INT64_MIN, which the lower
       clamp would then raise to depth 1, handing the caller who asked for the
       STRONGEST guarantee the weakest possible sketch (and differing by
       architecture, since aarch64 saturates the other way). The comparison is
       false for NaN, which therefore also lands on the maximum. */
    double d_d = ceil(log(1.0 / delta));
    long dl = (d_d < (double)CMS_MAX_D) ? (long)d_d : (long)CMS_MAX_D;
    if (dl < CMS_MIN_D) dl = CMS_MIN_D;
    uint32_t d = (uint32_t)dl;

    *w_out = w;
    *d_out = d;
    return 1;
}



( run in 5.402 seconds using v1.01-cache-2.11-cpan-60884a8df76 )