add method
Folds element into the sketch (idempotent for equal elements).
Audited: 2026-06-12 11:26 EDT
Implementation
void add(Object? element) {
// Top `precision` bits pick the register; the remaining bits' leading-zero
// run (rank) is what HyperLogLog records — a long run is rare and signals
// many distinct elements landed in that bucket. The 64-bit hash is held as
// two 32-bit limbs so the mixing and bit extraction are identical on the VM
// and the web (a native 64-bit `<<`/`*` would truncate to 32 bits on web).
final (int hashHi, int hashLo) = _mix64(element.hashCode);
// precision <= 16, so the top `precision` index bits live entirely in the
// high limb.
final int index = hashHi >>> (32 - precision);
final int rank = _rank64(hashHi, hashLo, precision);
if (rank > _registers[index]) _registers[index] = rank;
}