Skip to content

Commit

Permalink
fix bug in hashing samples (#151)
Browse files Browse the repository at this point in the history
Co-authored-by: Phillip Alday <phillip.alday@beacon.bio>
  • Loading branch information
ericphanson and palday authored Jan 26, 2024
1 parent 6488083 commit 4664841
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Onda"
uuid = "e853f5be-6863-11e9-128d-476edb89bfb5"
authors = ["Beacon Biosignals, Inc."]
version = "0.15.3"
version = "0.15.4"

[deps]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
Expand Down
6 changes: 6 additions & 0 deletions src/samples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ function Base.isequal(a::Samples, b::Samples)
return isequal(a.encoded, b.encoded) && isequal(a.info, b.info) && isequal(a.data, b.data)
end

# Define in a compatible way as `isequal` so that two samples being `isequal` to each other
# ensures they have the same hash.
function Base.hash(a::Samples, h::UInt)
return hash(Samples, hash(a.encoded, hash(a.info, hash(a.data, h))))
end

"""
copy(s::Samples)
Expand Down
3 changes: 2 additions & 1 deletion test/samples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ end
@test copy_samples.info.channels !== info.channels === samples.info.channels
end

@testset "Base.isequal" begin
@testset "Base.isequal and Base.hash" begin
info = SamplesInfoV2(sensor_type="eeg",
channels=["a", "b", "c"],
sample_unit="unit",
Expand All @@ -244,6 +244,7 @@ end
samples.data[1,1] = samples2.data[1,1] = NaN
@test samples != samples2
@test isequal(samples, samples2)
@test hash(samples) == hash(samples2)
end

@testset "Samples views" begin
Expand Down

0 comments on commit 4664841

Please sign in to comment.