Skip to content

Commit

Permalink
perf: Replace unsafe_trunc with % for trunc int
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-yong-zhi committed Nov 4, 2024
1 parent 30ae975 commit 35e517b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/qtrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ const PERM4::NTuple{24, NTuple{4, UInt8}} = ((0, 1, 2, 3), (0, 1, 3, 2), (0, 2,
const Index = Tuple{Int, Int, Int}
@inline function child(ind::Index, n::UInt8) # n: 0, 1, 2, 3
# @assert 0 <= n <= 3
@inbounds (ind[1] - 1, 2ind[2] - n & 0x01, 2ind[3] - n >> 1)
@inbounds (ind[1] - 1, 2ind[2] - n & 0x01, 2ind[3] - n >> 0x01)
end
@inline parent(ind::Index) = @inbounds (ind[1] + 1, (ind[2] + 1) ÷ 2, (ind[3] + 1) ÷ 2)
indexcenter(l::Integer, a::Integer, b::Integer) = l == 1 ? (a, b) : (2^(l - 1) * (a - 1) + 2^(l - 2), 2^(l - 1) * (b - 1) + 2^(l - 2))
indexcenter(ind) = indexcenter(ind...)
function childnumber(ancestor::Index, descendant::Index) #assume the ancestor-descendant relationship exists
o2, o3 = indexcenter(ancestor[1] - descendant[1] + 1, ancestor[2], ancestor[3])
(unsafe_trunc(UInt8, descendant[3] <= o3) << 1) | unsafe_trunc(UInt8, descendant[2] <= o2) # 0, 1, 2, 3
(((descendant[3] <= o3) % UInt8) << 0x01) | ((descendant[2] <= o2) % UInt8) # 0, 1, 2, 3
end
function childnumber(ind::Index)
((unsafe_trunc(UInt8, ind[3])&0x01)<<0x01) | (unsafe_trunc(UInt8, ind[2])&0x01) # 0, 1, 2, 3
(((ind[3] % UInt8) & 0x01) << 0x01) | ((ind[2] % UInt8) & 0x01) # 0, 1, 2, 3
end
function indexrange(l::Integer, a::Integer, b::Integer)
r = 2^(l - 1)
Expand Down

0 comments on commit 35e517b

Please sign in to comment.