功能说明
从标准输入读行,每行哈希为 32 位整数并更新 HyperLogLog 寄存器数组。寄存器索引为哈希高 p 位,寄存器值为剩余位最左置位位置。估计用寄存器调和均值与小范围修正。运行 printf “a\nb\nc\na\nb” | node hll.mjs 12 输出 3。标准误差约 1.04/sqrt(m),默认精度 12(4096 寄存器)误差约 1.6%,更高精度减误差但增内存。
运行方式
printf "a\nb\nc\na\nb" | node hll.mjs 12
限制与后续
当前HyperLogLog 命令行工具实现覆盖最常见的使用路径。本译文依据英文原文完整重写,代码与命令与英文版本严格一致,可在本地按运行方式复现并核对结果。The estimate has a standard error of about 1.04 / sqrt(m), so with the default precision of 12 (4096 registers) the error is about 1.6%. Higher precision reduces error but uses more memory.若用于生产,请先补充输入校验、错误处理与日志,再结合自身环境调整node版本。