Skip to content

Commit

Permalink
upgrade BitBasis, fix #47 (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiggleLiu authored Jan 14, 2024
1 parent 70293b6 commit c03912b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
16 changes: 3 additions & 13 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
name = "BitBasis"
uuid = "50ba71b6-fa0f-514d-ae9a-0916efc90dcf"
version = "0.8.1"
version = "0.9"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
LinearAlgebra = "1"
StaticArrays = "1"
julia = "1"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Aqua", "Random", "SparseArrays", "LinearAlgebra", "Documenter"]
julia = "1.6"
7 changes: 5 additions & 2 deletions src/DitStr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Base.zero(::Type{DitStr{D,N,T}}) where {D,N,T} = DitStr{D,N,T}(zero(T))
Base.zero(::DitStr{D,N,T}) where {D,N,T} = DitStr{D,N,T}(zero(T))

buffer(b::DitStr) = b.buf
Base.hash(d::DitStr) = hash(buffer(d))
Base.reinterpret(::Type{DitStr{D,N,T}}, x::Integer) where {D,N,T} = DitStr{D,N,T}(reinterpret(T, x))
Base.reinterpret(::Type{T}, x::DitStr) where {T} = reinterpret(T, buffer(x))
Base.reinterpret(::Type{DitStr{D,N,T}}, x::DitStr) where {D,N,T} = DitStr{D,N,T}(x)
Expand Down Expand Up @@ -106,8 +107,8 @@ Base.:(==)(a::DitStr{D,N}, b::DitStr{D,N}) where {D,N} = Base.:(==)(buffer(a), b

# Note: the transitivity of == is not satisfied here.
Base.:(==)(lhs::DitStr, rhs::DitStr) = false
Base.isapprox(a::DitStr, b::Number; kwargs...) = Base.isapprox(buffer(a), b; kwargs...)
Base.isapprox(a::Number, b::DitStr; kwargs...) = Base.isapprox(a, buffer(b); kwargs...)
Base.isapprox(a::DitStr, b::Integer; kwargs...) = Base.isapprox(buffer(a), b; kwargs...)
Base.isapprox(a::Integer, b::DitStr; kwargs...) = Base.isapprox(a, buffer(b); kwargs...)
Base.isapprox(lhs::DitStr, rhs::DitStr; kwargs...) = false
Base.isapprox(a::T, b::T; kwargs...) where {T<:DitStr} =
Base.isapprox(buffer(a), buffer(b); kwargs...)
Expand All @@ -124,6 +125,8 @@ Base.to_index(x::UnitRange{<:DitStr}) = error(
# NOTE: maybe this is wrong?
Base.checkindex(::Type{Bool}, inds::AbstractUnitRange, i::DitStr) =
checkindex(Bool, inds, Base.to_index(i))
Base.checkindex(::Type{Bool}, inds::Base.IdentityUnitRange, i::DitStr) =
checkindex(Bool, inds, Base.to_index(i))
Base.length(::DitStr{D,N,T}) where {D,N,T} = N
Base.lastindex(dits::DitStr) = length(dits)

Expand Down
4 changes: 2 additions & 2 deletions src/iterate_control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ function Base.getindex(it::IterControl{S}, k::Int) where {S}
end
return out + it.base
end
Base.lastindex(it) = it.n
Base.lastindex(it::IterControl) = it.n

function Base.iterate(it::IterControl{S}, state = 1) where {S}
function Base.iterate(it::IterControl, state = 1)
if state > length(it)
return nothing
else
Expand Down
2 changes: 2 additions & 0 deletions test/DitStr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ using BitBasis, Test
@test BitBasis.readat(dit"001;3") == 0
@test BitBasis.readat(dit"001;3", 1, 2, 3) == 1
@test_throws ErrorException BitBasis.parse_dit(Int64, "12341111111111111111111111111111111111111111111111111111111;5")

@test hash(x) isa UInt64
end
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Aqua = "0.5"
Aqua = "0.8"

0 comments on commit c03912b

Please sign in to comment.