Skip to content

Commit

Permalink
Apply fixes to a bunch of stuff in hashing2.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
staticfloat committed Oct 3, 2014
1 parent 8eb99ca commit 28d6a11
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions base/hashing2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,32 +155,35 @@ end
hash(x::Float16, h::Uint) = hash(float64(x), h)

## hashing collections ##

const hashaa_seed = Uint === Uint64 ? 0x7f53e68ceb575e76 : 0xeb575e76
function hash(a::AbstractArray, h::Uint)
h += uint(0x7f53e68ceb575e76)
h += uint(hashaa_seed)
h += hash(size(a))
for x in a
h = hash(x, h)
end
return h
end

const hasha_seed = Uint === Uint64 ? 0x6d35bb51952d5539 : 0x952d5539
function hash(a::Associative, h::Uint)
h += uint(0x6d35bb51952d5539)
h += uint(hasha_seed)
for (k,v) in a
h $= hash(k, hash(v))
end
return h
end

const hashs_seed = Uint === Uint64 ? 0x852ada37cfe8e0ce : 0xcfe8e0ce
function hash(s::Set, h::Uint)
h += uint(0x852ada37cfe8e0ce)
h += uint(hashs_seed)
for x in s
h $= hash(x)
end
return h
end

const hashis_seed = Uint === Uint64 ? 0x88989f1fc7dea67d : 0xc7dea67d
function hash(s::IntSet, h::Uint)
h += uint(0x88989f1fc7dea67d)
h += hash(s.fill1s)
Expand All @@ -194,8 +197,9 @@ function hash(s::IntSet, h::Uint)
end

# hashing ranges by component at worst leads to collisions for very similar ranges
const hashr_seed = Uint === Uint64 ? 0x80707b6821b70087 : 0x21b70087
function hash(r::Range, h::Uint)
h += uint(0x80707b6821b70087)
h += uint(hashr_seed)
h = hash(first(r), h)
h = hash(step(r), h)
h = hash(last(r), h)
Expand Down

0 comments on commit 28d6a11

Please sign in to comment.