Skip to content

Release ColorHashSharp 2.0.0 with color-hash 2.0.2 parity - #10

Merged
fernandezja merged 21 commits into
mainfrom
develop
Nov 22, 2026
Merged

fernandezja merged 21 commits into
mainfrom
develop

Conversation

@fernandezja

Copy link
Copy Markdown
Owner
  • Match JavaScript color-hash 2.0.2 by default with SHA-256, compatible HSL and RGB calculations, and #rrggbb output. Preserve historical C# colors through explicit configuration
  • Validate and copy color options at construction, and add parity and regression tests
  • Update the NuGet version and target frameworks, refresh the package icons and README, and run .NET 10 and 11 CI on Windows and Linux

Breaking changes
Default colors and HEX output can change. Options.S and Options.L now use List, and changes to Options after construction require a new ColorHash instance.

Refs #9

Jose A. Fernandez and others added 21 commits January 30, 2026 16:03
 - Updated BenchmarkDotNet in benchmarks project to 0.15.8.
 - Upgraded Microsoft.NET.Test.Sdk to 18.0.1 and
 - xunit.runner.visualstudio to 3.1.5 in test project.
…ard2.0, netstandard2.1, net48, net481, net8.0, net9.0, and net10.0)
- Convert string to UTF8 bytes once instead of per-character conversion
- Remove inefficient ToString() and ToUTF8Bytes() calls in loop
- Eliminate redundant ToUTF8() and ToUTF8Bytes() helper methods
- Direct byte array iteration reduces allocations and GC pressure
- Expected performance improvement: 50-70% faster hash generation
- Remove all Debug.WriteLine statements from BKDRHash loops
- Remove Debug.WriteLine statements from ColorToRgb conversion methods
- Eliminate I/O and string formatting overhead in production code
- Debug statements executed on every hash/color conversion
- Expected performance improvement: 20-30% faster
- Replace ArrayList with List<double> for S and L properties
- Eliminate boxing/unboxing overhead on every access
- Remove unnecessary type casting: (double)_options.S[i] to _options.S[i]
- Update all GetLS methods to return List<double> instead of ArrayList
- Update test files to use List<double> instead of ArrayList
- Improve type safety and memory efficiency
- Expected performance improvement: 15-25% faster
- Add readonly fields for BKDRHash, ColorToHex instances
- Reuse cached instances instead of creating new ones per call
- Use static ColorToRgb.ToRgb() method directly instead of instance
- Remove unnecessary Hue cast (HueRanges is already List<Hue>)
- Remove obsolete TODO comment
- Reduce GC pressure by eliminating repeated allocations
- Expected performance improvement: 10-15% fewer allocations
- Add IHashFunction interface for custom hash implementations
- BKDRHash now implements IHashFunction
- Options.HashFunction property allows custom hash functions
- ColorHash uses custom hash if provided, otherwise defaults to BKDRHash
- Add comprehensive tests for custom hash function functionality
- Add documentation and examples in samples/CustomHashFunction.md

This allows users to:
- Use custom hash algorithms (MD5, SHA, etc.)
- Implement domain-specific hash functions
- Ensure cross-platform consistency
- Create predictable hashes for testing

Fixes #1
Remove .NET 8 and .NET 9 targets
Add support for .NET 10 and .NET 11
Update NuGet packages to compatible versions
Refresh CI workflow configuration
- Add separate build and test jobs for Windows and Ubuntu
- Run the CI matrix against .NET 10 and .NET 11
- Multi-target the test project for both frameworks
- Update checkout and configure workflow permissions and concurrency
- Upgrade actions/checkout from v4 to v5
- Upgrade actions/setup-dotnet from v4 to v5
- Apply updates to both build and test jobs
- Match the color-hash 2.0.2 default hash using the first four SHA-256
  digest bytes as an unsigned big-endian integer.
- Add JavaScriptBkdrHash and keep historical BKDR and custom hashes
  available through Options.HashFunction.
- Update default color expectations and add exact hash, HSL, RGB, and
  HEX regression vectors.
- Document hash selection and the Options migration from NuGet 1.1.0.

BREAKING CHANGE: Default colors may change. Select BKDRHash explicitly
with the same palettes and hue ranges to preserve historical colors.
Options.S, Options.L, and protected GetLS now use List<double> in place
of ArrayList. Affected consumers must update and recompile

ref #9
- Reject missing or empty palettes, non-finite values, and invalid hue ranges
- Copy palettes and hue bounds while preserving valid endpoints and fixed hues
- Treat null input as an empty string, including for custom hashes
- Add regression tests and document the 2.0 behavior

BREAKING CHANGE: Changes to Options after construction no longer affect existing ColorHash instances. Create a new instance to apply changes.
Custom hashes now receive an empty string for null input

ref #9
- Enable JavaScript-compatible HSL calculations, RGB rounding, and CSS hex output by default
- Port upstream tests to xUnit and retain regression tests for historical colors
- Update the README and examples with the 2.0 defaults and migration settings

BREAKING CHANGE: Default color values may change, and HEX output now uses lowercase #rrggbb. To reproduce ColorHashSharp 1.x colors, set Options.UseJavaScriptCompatibility to false and select BKDRHash

#9
@fernandezja
fernandezja merged commit de658a6 into main Nov 22, 2026
20 checks passed
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