Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
KarrasRadixTree.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
22
23namespace shamtree {
24
33 class KarrasRadixTree;
34
35} // namespace shamtree
36
38
39 public:
42
44 inline u32 get_leaf_count() const { return get_internal_cell_count() + 1; }
45
46 inline u32 get_total_cell_count() const { return get_internal_cell_count() + get_leaf_count(); }
47
53
54 u32 tree_depth;
55
67
68 inline KarrasTreeTraverser get_structure_traverser() const {
75 }
76
77 inline KarrasTreeTraverserHost get_structure_traverser_host() const {
78 return KarrasTreeTraverserHost{
84 }
85
86 static inline KarrasRadixTree make_empty(sham::DeviceScheduler_ptr dev_sched) {
87 return KarrasRadixTree{
88 sham::DeviceBuffer<u32>(0, dev_sched),
89 sham::DeviceBuffer<u32>(0, dev_sched),
90 sham::DeviceBuffer<u8>(0, dev_sched),
91 sham::DeviceBuffer<u8>(0, dev_sched),
92 sham::DeviceBuffer<u32>(0, dev_sched),
93 0};
94 }
95
97 inline bool is_root_leaf() const { return get_internal_cell_count() == 0; }
98};
99
100namespace shamtree {
101
119 template<class Tmorton>
120 KarrasRadixTree karras_tree_from_morton_set(
121 sham::DeviceScheduler_ptr dev_sched,
122 u32 morton_count,
123 sham::DeviceBuffer<Tmorton> &morton_codes,
124 KarrasRadixTree &&recycled_tree);
125
139 template<class Tmorton>
140 KarrasRadixTree karras_tree_from_morton_set(
141 sham::DeviceScheduler_ptr dev_sched,
142 u32 morton_count,
143 sham::DeviceBuffer<Tmorton> &morton_codes);
144
146 std::string karras_tree_to_dot_graph(KarrasRadixTree &recycled_tree);
147
148} // namespace shamtree
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory)
std::vector< T > copy_to_stdvec() const
Copy the content of the buffer to a std::vector.
size_t get_size() const
Gets the number of elements in the buffer.
A data structure representing a Karras Radix Tree.
sham::DeviceBuffer< u8 > buf_rchild_flag
right child flag (size = internal_count)
u32 get_leaf_count() const
Get leaf count.
sham::DeviceBuffer< u32 > buf_rchild_id
right child id (size = internal_count)
sham::DeviceBuffer< u32 > buf_endrange
endrange (size = internal_count)
bool is_root_leaf() const
is the root a leaf ?
sham::DeviceBuffer< u32 > buf_lchild_id
left child id (size = internal_count)
u32 get_internal_cell_count() const
Get internal cell count.
sham::DeviceBuffer< u8 > buf_lchild_flag
left child flag (size = internal_count)
KarrasRadixTree(sham::DeviceBuffer< u32 > &&buf_lchild_id, sham::DeviceBuffer< u32 > &&buf_rchild_id, sham::DeviceBuffer< u8 > &&buf_lchild_flag, sham::DeviceBuffer< u8 > &&buf_rchild_flag, sham::DeviceBuffer< u32 > &&buf_endrange, u32 tree_depth)
CTOR.
STL namespace.
Utility struct to traverse a Karras Radix Tree.