Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug in hashing samples #151

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading