Skip to content

Commit

Permalink
change childnumber 4 to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-yong-zhi committed Apr 20, 2024
1 parent 336aca1 commit e9b24fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Stuffing"
uuid = "4175e07e-e5b7-423e-8796-3ea7f6d48281"
authors = ["guoyongzhi <[email protected]>"]
version = "0.10.0"
version = "0.10.1"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
14 changes: 6 additions & 8 deletions src/qtrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ const PERM4 = ((1, 2, 3, 4), (1, 2, 4, 3), (1, 3, 2, 4), (1, 3, 4, 2), (1, 4, 2,
@assert length(PERM4) == 24
@inline shuffle4() = @inbounds PERM4[rand(1:24)]
const Index = Tuple{Int, Int, Int}
@inline function child(ind::Index, n::Int)
@inline function child(ind::Index, n::Int) # n: 0 or 4, 1, 2, 3
@inbounds (ind[1] - 1, 2ind[2] - n & 0x01, 2ind[3] - (n & 0x02) >> 1)
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])
n = ((descendant[3] <= o3)<<1) | (descendant[2] <= o2)
n == 0 ? 4 : n
((descendant[3] <= o3) << 1) | (descendant[2] <= o2) # 0, 1, 2, 3
end
function childnumber(ind::Index)
n = ((ind[3]&0x01)<<0x01)| (ind[2]&0x01)
n == 0 ? 4 : n
((ind[3]&0x01)<<0x01) | (ind[2]&0x01) # 0, 1, 2, 3
end
function indexrange(l::Integer, a::Integer, b::Integer)
r = 2^(l - 1)
Expand Down Expand Up @@ -472,7 +470,7 @@ function remove_tree_node(t::LinkedSpacialQTree, node::SpacialQTreeNode)
p = node.parent
ind = spacial_index(node)
# @show ind
p.children[childnumber(ind)] = p
p.children[childnumber(ind)+1] = p
end
function Base.push!(t::LinkedSpacialQTree, ind::Index, label::Int)
# @show ind, label
Expand All @@ -485,10 +483,10 @@ function Base.push!(t::LinkedSpacialQTree, ind::Index, label::Int)
aind[1] <= ind[1] && break
cn = childnumber(aind, ind)
# @show aind, ind, cn
cnode = tn.children[cn]
cnode = tn.children[cn+1]
if isemptychild(tn, cnode)
cnode = new_spacial_qtree_node(t, tn, child(aind, cn))
tn.children[cn] = cnode
tn.children[cn+1] = cnode
end
tn = cnode
end
Expand Down

0 comments on commit e9b24fb

Please sign in to comment.