7template<
typename _Geo, u32 SPLIT_FACTOR,
typename Derived>
requires (SPLIT_FACTOR > 1)
12 for (
int d = 0; d < Geo::D::N; d++) {
13 idx[d] = (linearSpaceIdx / (
u32) std::pow(SPLIT_FACTOR, d)) % SPLIT_FACTOR;
19 _Geo::RowMajorIdx
getChildIdx(
int linearSpaceChildIdx)
const {
20 auto childIdx = getIdxForLinearSpaceIdx(linearSpaceChildIdx);
21 childIdx = this->idx * SPLIT_FACTOR + childIdx;
26 assert(this->subtrees ==
nullptr)
27 assert(other.parent ==
nullptr)
29 this->range = other.range;
30 this->idx = other.idx;
31 this->level = other.level;
32 this->subtrees = other.subtrees;
34 other.subtrees =
nullptr;
36 if (!this->subtrees)
return;
39 this->subtrees[i].parent = (Derived*)
this;
46 static constexpr u32 SplitFactor = SPLIT_FACTOR;
48 Derived *parent =
nullptr;
49 Derived *subtrees =
nullptr;
54 unsigned int level = 0;
59 Derived *parent =
nullptr,
61 int level = 0) : parent(parent), range(range), idx(idx), level(level) {}
64 return Geo::template PowerN<SPLIT_FACTOR>();
68 this->moveOp(std::move(other));
72 this->moveOp(std::move(other));
77 if (splitLevel == 0)
return;
79 if (!this->subtrees) {
80 this->subtrees = (Derived*) malloc(
sizeof(Derived) * getMaxChildren());
83 this->range.split(SPLIT_FACTOR, subranges);
85 for (
int i = 0; i < getMaxChildren(); i++) {
86 auto childIdx = this->getChildIdx(i);
87 new (this->subtrees + i) Derived (subranges[i], (Derived*)
this, childIdx, this->level + 1);
91 for (
int i = 0; i < getMaxChildren(); i++) {
92 this->subtrees[i].split(splitLevel - 1);
97 auto *node = (Derived*)
this;
98 while (node->parent) node = node->parent;
103 auto childIdx = this->range.splitIdx(SPLIT_FACTOR, p);
104 auto *child = &this->subtrees[childIdx];
110 return (Derived *)
this - this->parent->subtrees;
114 if (!this->parent)
return nullptr;
116 auto siblingIdx = this->getSiblingIdx();
117 if (siblingIdx < getMaxChildren() - 1) {
118 return &this->parent->subtrees[siblingIdx + 1];
LinkedGrid(LinkedGrid &&other) noexcept
LinkedGrid(Geo::Region range, Derived *parent=nullptr, Geo::RowMajorIdx idx=typename Geo::RowMajorIdx(0), int level=0)
void moveOp(LinkedGrid &&other)
u32 getSiblingIdx() const
static _Geo::RowMajorIdx getIdxForLinearSpaceIdx(u32 linearSpaceIdx)
LinkedGrid & operator=(LinkedGrid &&other) noexcept
_Geo::RowMajorIdx getChildIdx(int linearSpaceChildIdx) const
Derived * getNextSibling()
static constexpr u32 getMaxChildren()
Derived * getChild(const Geo::Point &p)
void split(u32 splitLevel=1)
Region< dim, fp, topBoundaryInclusive > Region
NumVec< u64, D::N > RowMajorIdx