13 #ifndef __UT_ARTMAPIMPL_H__
14 #define __UT_ARTMAPIMPL_H__
24 return this->myNumChildren == 4;
35 unsigned c = prefix[0];
37 myChildKeys[this->myNumChildren] =
c;
38 myChildren[this->myNumChildren] = child.release();
39 parent_t** node = &myChildren[this->myNumChildren];
40 this->myNumChildren++;
45 auto upgrade = this->
template newNode<UT_ARTNode16<T>>();
46 this->moveHeader(*upgrade);
49 upgrade->myNumChildren = this->myNumChildren;
50 memcpy(upgrade->myChildKeys, myChildKeys,
51 sizeof(
unsigned char) *
this->myNumChildren);
52 for (
int i = 0; i < 4; ++i)
54 upgrade->myChildren[i] = myChildren[i];
55 myChildren[i] =
nullptr;
58 *ref = upgrade.release();
71 if (myChildKeys[0] == c)
73 else if (myChildKeys[1] == c)
75 else if (myChildKeys[2] == c)
77 else if (myChildKeys[3] == c)
82 return stealChild(ref, idx);
92 if (myChildKeys[0] == c)
93 found = &myChildren[0];
94 else if (myChildKeys[1] == c)
95 found = &myChildren[1];
96 else if (myChildKeys[2] == c)
97 found = &myChildren[2];
98 else if (myChildKeys[3] == c)
99 found = &myChildren[3];
104 template <
typename T>
108 for (; index < this->myNumChildren; index++)
110 if (myChildren[index] !=
nullptr)
111 return myChildren[
index];
116 template <
typename T>
120 for (; index < this->myNumChildren; index++)
122 if (myChildren[index] !=
nullptr)
123 return myChildren[
index];
128 template <
typename T>
132 this->myNumChildren--;
134 myChildren[idx] = myChildren[this->myNumChildren];
135 myChildKeys[idx] = myChildKeys[this->myNumChildren];
136 myChildKeys[this->myNumChildren] = 0;
137 myChildren[this->myNumChildren] =
nullptr;
145 template <
typename T>
149 return this->myNumChildren == 16;
152 template <
typename T>
158 if (this->myNumChildren < 16)
160 uchar c = child->prefix()[0];
161 int idx = prefixToIndex_(c);
164 idx = this->myNumChildren;
166 myChildKeys[idx] =
c;
167 myChildren[idx] = child.release();
168 this->myNumChildren++;
170 return &myChildren[idx];
175 auto upgrade = this->
template newNode<UT_ARTNode48<T>>();
176 this->moveHeader(*upgrade);
177 for (
int i = 0; i < this->myNumChildren; i++)
179 upgrade->myChildKeys[myChildKeys[i]] = i + 1;
180 upgrade->myChildren[i] = myChildren[i];
181 myChildren[i] =
nullptr;
183 *ref = upgrade.release();
188 template <
typename T>
193 int idx = prefixToIndex_(c);
195 return stealChild(ref, idx);
200 template <
typename T>
206 int idx = prefixToIndex_(c);
209 return &myChildren[idx];
215 template <
typename T>
219 for (; index < this->myNumChildren; index++)
221 if (myChildren[index] !=
nullptr)
222 return myChildren[
index];
227 template <
typename T>
231 for (; index < this->myNumChildren; index++)
233 if (myChildren[index] !=
nullptr)
234 return myChildren[
index];
239 template <
typename T>
243 this->myNumChildren--;
245 myChildren[idx] = myChildren[this->myNumChildren];
246 myChildKeys[idx] = myChildKeys[this->myNumChildren];
247 myChildKeys[this->myNumChildren] = 0;
248 myChildren[this->myNumChildren] =
nullptr;
250 if (this->myNumChildren == 2)
252 auto downgrade = this->
template newNode<UT_ARTNode4<T>>();
253 this->moveHeader(*downgrade);
254 memcpy(downgrade->myChildKeys, myChildKeys, 4);
255 for (
int i = 0; i < this->myNumChildren; i++)
257 downgrade->myChildren[i] = myChildren[i];
258 myChildren[i] =
nullptr;
263 *ref = downgrade.release();
273 template <
typename T>
277 return this->myNumChildren == 48;
280 template <
typename T>
284 uchar c = child->prefix()[0];
285 if (this->myNumChildren < 48)
288 for (pos = 0; pos < 48; pos++)
290 if (myChildren[pos] ==
nullptr)
293 myChildren[pos] = child.release();
294 myChildKeys[
c] = pos + 1;
295 this->myNumChildren++;
297 return &myChildren[pos];
302 auto upgrade = this->
template newNode<UT_ARTNode256<T>>();
303 this->moveHeader(*upgrade);
304 for (
int i = 0; i < 256; i++)
308 upgrade->myChildren[i] = myChildren[myChildKeys[i] - 1];
309 myChildren[myChildKeys[i] - 1] =
nullptr;
313 *ref = upgrade.release();
318 template <
typename T>
323 int idx = myChildKeys[
c];
325 return stealChild(ref, idx - 1);
329 template <
typename T>
334 int idx = myChildKeys[
c];
336 return &myChildren[idx - 1];
340 template <
typename T>
344 for (; index < 48; index++)
346 if (myChildren[index] !=
nullptr)
347 return myChildren[
index];
352 template <
typename T>
356 for (; index < 48; index++)
358 if (myChildren[index] !=
nullptr)
359 return myChildren[
index];
364 template <
typename T>
368 this->myNumChildren--;
370 uchar c = myChildren[idx]->prefix()[0];
372 myChildren[idx] =
nullptr;
377 if (this->myNumChildren == 12)
380 auto downgrade = this->
template newNode<UT_ARTNode16<T>>();
381 this->moveHeader(*downgrade);
384 for (
int i = 0; i < 256; i++)
386 int pos = myChildKeys[i];
389 downgrade->myChildKeys[cidx] = i;
390 downgrade->myChildren[cidx] = myChildren[pos - 1];
391 myChildren[pos - 1] =
nullptr;
396 *ref = downgrade.release();
407 template <
typename T>
411 return this->myNumChildren == 256;
414 template <
typename T>
418 uchar c = child->prefix()[0];
419 this->myNumChildren++;
420 myChildren[
c] = child.release();
422 return &myChildren[
c];
425 template <
typename T>
430 return stealChild(ref, c);
433 template <
typename T>
439 if (myChildren[c] !=
nullptr)
440 return &myChildren[
c];
444 template <
typename T>
451 for (; index < 256; index++)
453 if (myChildren[index] !=
nullptr)
454 return myChildren[
index];
459 template <
typename T>
463 for (; index < 256; index++)
465 if (myChildren[index] !=
nullptr)
466 return myChildren[
index];
471 template <
typename T>
475 this->myNumChildren--;
477 myChildren[idx] =
nullptr;
482 if (this->myNumChildren == 37)
485 auto downgrade = this->
template newNode<UT_ARTNode48<T>>();
486 this->moveHeader(*downgrade);
488 for (
int i = 0; i < 256; i++)
490 if (myChildren[i] !=
nullptr)
492 downgrade->myChildren[pos] = myChildren[i];
493 downgrade->myChildKeys[i] = pos + 1;
495 myChildren[i] =
nullptr;
499 *ref = downgrade.release();
506 #endif // __UT_ARTMAPIMPL_H__
UT_ARTNodePtr< parent_t > parent_ptr_t
parent_t * nextChild(int &index) override
parent_t * nextChild(int &index) override
parent_ptr_t stealChild(parent_t **ref, parent_t *child) override
UT_ARTNodePtr< parent_t > parent_ptr_t
parent_ptr_t stealChild(parent_t **ref, parent_t *child) override
**But if you need a or simply need to know when the task has note that the like this
parent_t ** findPartialPrefixChild(const UT_StringView &prefix) override
A utility class to do read-only operations on a subset of an existing string.
bool isFull() const override
bool isFull() const override
parent_t ** insertChild(parent_t **ref, parent_ptr_t child) override
bool isFull() const override
parent_t ** findPartialPrefixChild(const UT_StringView &prefix) override
UT_ARTNodePtr< parent_t > parent_ptr_t
parent_t ** insertChild(parent_t **ref, parent_ptr_t child) override
parent_t ** findPartialPrefixChild(const UT_StringView &prefix) override
parent_t ** insertChild(parent_t **ref, parent_ptr_t child) override
parent_ptr_t stealChild(parent_t **ref, parent_t *child) override
parent_t ** insertChild(parent_t **ref, parent_ptr_t child) override
parent_t * nextChild(int &index) override
parent_t * nextChild(int &index) override
parent_t ** findPartialPrefixChild(const UT_StringView &prefix) override
parent_ptr_t stealChild(parent_t **ref, parent_t *child) override
virtual UT_ARTNode< T > ** insertChild(UT_ARTNode **ref, UT_ARTNodePtr< UT_ARTNode< T >> node)=0
UT_UniquePtr< T, UT_ARTNodeDelete > UT_ARTNodePtr
SYS_FORCE_INLINE const UT_StringView & prefix() const
bool isFull() const override