Skip to content

Commit 01155e1

Browse files
authored
Merge pull request #35598 from goretkin/hash-offsetarray
Allow hashing 1D OffsetArrays
2 parents cf0c3e0 + 7c45add commit 01155e1

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

base/abstractarray.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,7 @@ function hash(A::AbstractArray, h::UInt)
22082208
keyidx = last(ks)
22092209
linidx = key_to_linear[keyidx]
22102210
fibskip = prevfibskip = oneunit(linidx)
2211+
first_linear = first(LinearIndices(linear_to_key))
22112212
n = 0
22122213
while true
22132214
n += 1
@@ -2217,7 +2218,7 @@ function hash(A::AbstractArray, h::UInt)
22172218

22182219
# Skip backwards a Fibonacci number of indices -- this is a linear index operation
22192220
linidx = key_to_linear[keyidx]
2220-
linidx <= fibskip && break
2221+
linidx < fibskip + first_linear && break
22212222
linidx -= fibskip
22222223
keyidx = linear_to_key[linidx]
22232224

test/hashing.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ vals = Any[
9191
[-0. 0; -0. 0.], SparseMatrixCSC(2, 2, [1, 3, 3], [1, 2], [-0., -0.]),
9292
# issue #16364
9393
1:4, 1:1:4, 1:-1:0, 1.0:4.0, 1.0:1.0:4.0, range(1, stop=4, length=4),
94+
# issue #35597, when `LinearIndices` does not begin at 1
95+
Base.IdentityUnitRange(2:4),
9496
'a':'e', ['a', 'b', 'c', 'd', 'e'],
9597
# check that hash is still consistent with heterogeneous arrays for which - is defined
9698
# for some pairs and not others
@@ -102,9 +104,9 @@ for a in vals, b in vals
102104
end
103105

104106
for a in vals
105-
if a isa AbstractArray
106-
@test hash(a) == hash(Array(a)) == hash(Array{Any}(a))
107-
end
107+
a isa AbstractArray || continue
108+
keys(a) == keys(Array(a)) || continue
109+
@test hash(a) == hash(Array(a)) == hash(Array{Any}(a))
108110
end
109111

110112
vals = Any[

0 commit comments

Comments
 (0)