Skip to content

Enhancement/hyperloglog perf and tests - #1

Merged
hichxm merged 7 commits into
masterfrom
enhancement/hyperloglog-perf-and-tests
Jul 3, 2026
Merged

hichxm merged 7 commits into
masterfrom
enhancement/hyperloglog-perf-and-tests

Conversation

@hichxm

@hichxm hichxm commented Jul 3, 2026

Copy link
Copy Markdown
Owner

No description provided.

hichxm added 7 commits July 3, 2026 22:55
The `setCounterBits`, `setHashAlgorithm`, and `setM` methods have been removed to make the class strict/immutable.

BREAKING CHANGE: Consumers can no longer mutate the configuration of a HyperLogLog instance after creation. You must now pass these configurations during instantiation.
- Converted `$_precalculatedTwoPow32` property to `TWO_POW_32` class constant.
- Updated `setCounters` return type hint from `HyperLogLog` to `self`.
- Replaced slow string-based byte/bit extraction in `counter` and `rho` with native 64-bit integer bitwise operations using `unpack('J')`.
- Added padding logic (`$needsPadding`) to support hash algorithms producing less than 64 bits (e.g., crc32).
- Expanded test suite significantly (invalid algorithms, empty strings, short hashes, and small/large range corrections).
- Added a check using `hash_algos()` to ensure the provided hash algorithm is supported.
- Throw `InvalidArgumentException` instead of relying on PHP's native `ValueError`.
- Updated the corresponding unit test.
- Updated test suite to fallback to `sha256` for PHP versions < 8.1 since `xxh3` is unavailable.
- Refactored `HyperLogLog` constructor to inline `hash_algos()` and removed the unnecessary `$availableHashAlgorithms` state property.
- Added a safeguard in `add()` to throw an `\InvalidArgumentException` if `unpack()` returns `false`.
- Removed `InvalidArgumentException` imports in favor of fully qualified class names (FQCN).
- Added `@var` annotations to improve static analysis and IDE support.
- Fixed docblock indentation and missing EOF newlines.
@hichxm
hichxm merged commit 7474486 into master Jul 3, 2026
9 checks passed
@hichxm
hichxm deleted the enhancement/hyperloglog-perf-and-tests branch July 3, 2026 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant