41 TagTree(uint16_t leavesWidth, uint16_t leavesHeight)
52 return (std::numeric_limits<T>::max)();
75 void set(uint64_t leafno, T value)
77 uint32_t node =
static_cast<uint32_t
>(leafno);
78 while(node != UINT32_MAX &&
nodes_[node].value > value)
80 nodes_[node].value = value;
95 uint32_t nodeStack[16];
97 uint32_t node =
static_cast<uint32_t
>(leafno);
100 nodeStack[stackPtr++] = node;
112 while(low < threshold)
131 node = nodeStack[--stackPtr];
153 uint32_t nodeStack[16];
155 uint32_t node =
static_cast<uint32_t
>(leafno);
160 nodeStack[stackPtr++] = node;
174 while(low < threshold && low < n.value) [[likely]]
185 if(stackPtr == 0) [[unlikely]]
188 node = nodeStack[--stackPtr];
191 *value =
nodes_[node].value;
192 if(*value < threshold)
207 uint16_t resW[16]{}, resH[16]{};
211 uint64_t totalNodes = 0;
212 uint32_t nodesPerLevel;
216 nodesPerLevel =
static_cast<uint32_t
>(resW[levels]) * resH[levels];
217 resW[levels + 1] = (uint16_t)((resW[levels] + 1) >> 1);
218 resH[levels + 1] = (uint16_t)((resH[levels] + 1) >> 1);
219 totalNodes += nodesPerLevel;
221 }
while(nodesPerLevel > 1);
223 nodes_.resize(totalNodes);
224 parents_.resize(totalNodes, UINT32_MAX);
231 for(int8_t lvl = 0; lvl < levels - 1; ++lvl)
233 uint32_t w = resW[lvl];
234 uint32_t h = resH[lvl];
235 for(uint32_t j = 0; j < h; ++j)
237 for(uint32_t k = 0; k < w; ++k)
239 parents_[cur] =
static_cast<uint32_t
>(parentBase + (j >> 1) * resW[lvl + 1] + (k >> 1));
243 parentBase +=
static_cast<uint64_t
>(resW[lvl + 1]) * resH[lvl + 1];
constexpr T getUninitializedValue() const noexcept
Definition TagTree.h:50
void buildTree()
Definition TagTree.h:204
TagTree(uint16_t leavesWidth, uint16_t leavesHeight)
TagTree constructor.
Definition TagTree.h:41
void decode(t1_t2::BitIO *bio, uint64_t leafno, T threshold, T *value)
Decode the value of a leaf of the tag tree up to a given threshold.
Definition TagTree.h:143
void reset()
Reset a tag tree (set all leaves to 0).
Definition TagTree.h:58
std::vector< Node > nodes_
Definition TagTree.h:249
void set(uint64_t leafno, T value)
Set the value of a leaf of a tag tree.
Definition TagTree.h:75
std::vector< uint32_t > parents_
Definition TagTree.h:250
bool encode(t1_t2::BitIO *bio, uint64_t leafno, T threshold)
Encode the value of a leaf of the tag tree up to a given threshold.
Definition TagTree.h:92
std::vector< uint8_t > leafCache_
Definition TagTree.h:251
uint16_t leavesWidth_
Definition TagTree.h:247
uint16_t leavesHeight_
Definition TagTree.h:248
void read(T *bits, uint8_t n)
Reads bits.
Definition BitIO.h:114
bool write(uint32_t v, uint8_t n)
Writes bits.
Definition BitIO.h:87
ResWindow.
Definition CompressedChunkCache.h:36
TagTree< uint8_t > TagTreeU8
Definition TagTree.h:254
TagTree< uint16_t > TagTreeU16
Definition TagTree.h:255
bool known
Definition TagTree.h:201
T value
Definition TagTree.h:199
T low
Definition TagTree.h:200