diff --git a/src/qtrees.jl b/src/qtrees.jl index fa07225..2c00fca 100644 --- a/src/qtrees.jl +++ b/src/qtrees.jl @@ -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)