Enhancement/hyperloglog perf and tests - #1
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.