Add ArrayHashingStyle trait for O(1) range hashing and use it only for Numbers #25822
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.
O(1) range hashing requires
widen
to avoid overflows when hashing heterogeneous arrays. Since this requirement can be problematic, add anArrayHashingStyle
trait to opt-in for this behavior, and use it only forNumber
s by default. This assumes thatisequal(x::Number, y::T)
will only return true when T<:Number, or at least that counter-examples are rare enough that it's OK to requires these types to define the trait: else,hash(::AbstractArray{T})
will be inconsistent with isequal across types.Do not use O(1) hashing for
Dates
types, which fixes hashing heterogeneous arrays, and add corresponding tests.See previous discussion. The new trait will probably not be used very often by external packages, but it sounds cleaner to define it than to special-case
Number
directly in the function. Again, it's annoying that this design is so complex, but at least this limits the burden of implementingwiden
toNumber
types, rather than requiring all types which support-
to implement it.