From d4700a9d2fe5ad61f0a1b010e4f363b155741958 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Tue, 5 Jul 2022 16:55:13 +0200 Subject: [PATCH] Use naive hash fallback for BioSequence Current hashing behaviour hashes equal biosequences with different encodings to different values, which violate the interface of hash. This is a fix until (and if) we figure out a better method of hashing. See issue #243 --- Project.toml | 2 +- src/biosequence/biosequence.jl | 1 + src/longsequences/hash.jl | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 0869ebf6..b6c5bedd 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BioSequences" uuid = "7e6ae17a-c86d-528c-b3b9-7f778a29fe59" authors = ["Sabrina Jaye Ward ", "Jakob Nissen "] -version = "3.0.1" +version = "3.0.2" [deps] BioSymbols = "3c28c6f8-a34d-59c4-9654-267d177fcfa9" diff --git a/src/biosequence/biosequence.jl b/src/biosequence/biosequence.jl index d2106cc0..a6a05ec7 100644 --- a/src/biosequence/biosequence.jl +++ b/src/biosequence/biosequence.jl @@ -93,6 +93,7 @@ Base.isempty(x::BioSequence) = iszero(length(x)) Base.empty(::Type{T}) where {T <: BioSequence} = T(eltype(T)[]) Base.empty(x::BioSequence) = empty(typeof(x)) BitsPerSymbol(x::BioSequence) = BitsPerSymbol(Alphabet(typeof(x))) +Base.hash(s::BioSequence, x::UInt) = foldl((a, b) -> hash(b, a), s, init=x) function Base.similar(seq::BioSequence, len::Integer=length(seq)) return typeof(seq)(undef, len) diff --git a/src/longsequences/hash.jl b/src/longsequences/hash.jl index 812bf5b6..394140c3 100644 --- a/src/longsequences/hash.jl +++ b/src/longsequences/hash.jl @@ -15,6 +15,8 @@ ### This file is a part of BioJulia. ### License is MIT: https://github.com/BioJulia/BioSequences.jl/blob/master/LICENSE.md +# NB NOTE: This entire file is commented out until issue #243 is resolved +#= const c1 = 0x87c37b91114253d5 const c2 = 0x4cf5ad432745937f @@ -173,3 +175,4 @@ function Base.hash(seq::SeqOrView, seed::UInt64) return h1 end +=#