Skip to content

Commit

Permalink
add resort! function
Browse files Browse the repository at this point in the history
  • Loading branch information
rymanderson committed Jun 19, 2024
1 parent 59d712d commit 93a4434
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ function unsort!(system, tree::SingleTree)
unsort!(system, tree.buffer, tree.inverse_sort_index)
end

function unsort!(system, buffer, tree::Tree)
unsort!(system, buffer, tree.inverse_sort_index)
end

@inline function unsort!(system, buffer, inverse_sort_index)
for i_body in 1:get_n_bodies(system)
buffer[i_body] = system[inverse_sort_index[i_body], BODY]
Expand All @@ -462,6 +466,10 @@ function resort!(system, tree::SingleTree)
resort!(system, tree.buffer, tree.sort_index)
end

function resort!(system, buffer, tree::Tree)
resort!(system, buffer, tree.sort_index)
end

function resort!(system, buffer, sort_index)
for i_body in 1:get_n_bodies(system)
buffer[i_body] = system[sort_index[i_body], BODY]
Expand All @@ -471,19 +479,19 @@ function resort!(system, buffer, sort_index)
end
end

function unsorted_index_2_sorted_index(i_unsorted, tree::SingleTree)
@inline function unsorted_index_2_sorted_index(i_unsorted, tree::SingleTree)
return tree.inverse_sort_index[i_unsorted]
end

function unsorted_index_2_sorted_index(i_unsorted, i_system, tree::MultiTree)
@inline function unsorted_index_2_sorted_index(i_unsorted, i_system, tree::MultiTree)
return tree.inverse_sort_index_list[i_system][i_unsorted]
end

function sorted_index_2_unsorted_index(i_sorted, tree::SingleTree)
@inline function sorted_index_2_unsorted_index(i_sorted, tree::SingleTree)
return tree.sort_index[i_sorted]
end

function sorted_index_2_unsorted_index(i_unsorted, i_system, tree::MultiTree)
@inline function sorted_index_2_unsorted_index(i_unsorted, i_system, tree::MultiTree)
return tree.sort_index_list[i_system][i_unsorted]
end

Expand Down

0 comments on commit 93a4434

Please sign in to comment.