Skip to content

Commit

Permalink
Pkg: hash methods for various Pkg types in agreement with ==
Browse files Browse the repository at this point in the history
It's a bit weird to define these since they're not used anywhere.

cf JuliaLang#12198
  • Loading branch information
StefanKarpinski committed Aug 11, 2015
1 parent d5b880d commit 03eb136
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions base/pkg/reqs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Reqs

import Base: ==
import Base: ==, hash

using ..Types

Expand Down Expand Up @@ -49,8 +49,8 @@ immutable Requirement <: Line
end
end

# TODO: shouldn't be neccessary #4648
==(a::Line, b::Line) = a.content == b.content
hash(s::Line, h::UInt) = hash(s.content, h + (0x3f5a631add21cb1a % UInt))

# general machinery for parsing REQUIRE files

Expand Down
5 changes: 4 additions & 1 deletion base/pkg/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Types

export VersionInterval, VersionSet, Requires, Available, Fixed, merge_requires!, satisfies
import Base: show, isempty, in, intersect, hash, deepcopy_internal, ==
import Base: show, isempty, in, intersect, ==, hash, deepcopy_internal

immutable VersionInterval
lower::VersionNumber
Expand All @@ -17,6 +17,7 @@ isempty(i::VersionInterval) = i.upper <= i.lower
in(v::VersionNumber, i::VersionInterval) = i.lower <= v < i.upper
intersect(a::VersionInterval, b::VersionInterval) = VersionInterval(max(a.lower,b.lower), min(a.upper,b.upper))
==(a::VersionInterval, b::VersionInterval) = a.lower == b.lower && a.upper == b.upper
hash(i::VersionInterval, h::UInt) = hash((i.lower, i.upper), h + (0x0f870a92db508386 % UInt))

immutable VersionSet
intervals::Vector{VersionInterval}
Expand Down Expand Up @@ -67,6 +68,7 @@ immutable Available
end

==(a::Available, b::Available) = a.sha1 == b.sha1 && a.requires == b.requires
hash(a::Available, h::UInt) = hash((a.sha1, a.requires), h + (0xbc8ae0de9d11d972 % UInt))

show(io::IO, a::Available) = isempty(a.requires) ?
print(io, "Available(", repr(a.sha1), ")") :
Expand All @@ -79,6 +81,7 @@ end
Fixed(v::VersionNumber) = Fixed(v,Requires())

==(a::Fixed, b::Fixed) = a.version == b.version && a.requires == b.requires
hash(f::Fixed, h::UInt) = hash((f.version, f.requires), h + (0x68628b809fd417ca % UInt))

show(io::IO, f::Fixed) = isempty(f.requires) ?
print(io, "Fixed(", repr(f.version), ")") :
Expand Down

0 comments on commit 03eb136

Please sign in to comment.