17 #ifndef AGX_HIERARCHICAL_GRID_CELLTABLE_H
18 #define AGX_HIERARCHICAL_GRID_CELLTABLE_H
27 template <
typename CellIdT,
typename HashT = HashFn<CellIdT> >
56 {
return state >=
ACTIVE; }
61 return state ==
VALID;
78 { this->gotoNextElement(); }
81 #ifndef __clang__ // TODO Make sure clang does not produce warnings for this
85 constIt.m_cellTable = m_cellTable;
86 constIt.m_currentIndex = m_currentIndex;
93 this->gotoNextElement();
99 size_t oldIndex = m_currentIndex;
100 this->gotoNextElement();
108 this->gotoPreviousElement();
114 size_t oldIndex = m_currentIndex;
115 this->gotoPreviousElement();
121 {
return this->m_currentIndex == rhs.m_currentIndex && this->m_cellTable == rhs.m_cellTable; }
124 {
return this->m_currentIndex != rhs.m_currentIndex || this->m_cellTable != rhs.m_cellTable; }
129 agxAssert1(m_cellTable && m_currentIndex != m_cellTable->m_capacity,
"Can not dereference an invalid bucket!");
130 return m_cellTable->m_buckets[m_currentIndex].cellIndex;
139 m_cellTable = copy.m_cellTable;
140 m_currentIndex = copy.m_currentIndex;
148 while (m_currentIndex < m_cellTable->m_capacity && !m_cellTable->m_buckets[m_currentIndex].isValid())
154 if (m_currentIndex > 0) {
156 while (m_currentIndex > 0 && !m_cellTable->buckets()[m_currentIndex].isValid())
163 size_t m_currentIndex;
174 m_smoothingAverage(0), m_maxProbeLength(0),
175 m_cellIds(cellIdBuffer->ptr<CellIdT>()), m_cellIdBuffer(cellIdBuffer), m_cellIdReallocationCallback(&
CellTable::cellIdReallocationCallback, this)
177 m_cellIdBuffer->reallocationEvent.addCallback(&m_cellIdReallocationCallback);
183 m_cellIdBuffer->reallocationEvent.removeCallback(&m_cellIdReallocationCallback);
190 UInt32 bucketIndex = findBucket(cellId);
205 if (m_buckets[i].isValid())
213 UInt32 hashValue = m_hashFunctor(cellId);
224 #pragma warning(push)
225 #pragma warning(disable: 4127) // warning C4127: conditional expression is constant
230 const bool trueVal =
true;
233 bucket = &m_buckets[(hashValue + offset * offset) %
m_capacity];
238 targetBucket = bucket;
243 if (!bucket->
isValid() && !targetBucket)
244 targetBucket = bucket;
247 if (targetBucket && offset >= m_maxProbeLength)
257 this->
insert(cellId, cellIndex);
268 if (offset > m_maxProbeLength)
269 m_maxProbeLength = (
UInt16)offset;
284 UInt32 bucketIndex = findBucket(cellId);
287 Bucket *bucket = &m_buckets[bucketIndex];
320 UInt32 hashValue = m_hashFunctor(cellId);
322 const Bucket *bucket = &m_buckets[index];
325 if (bucket->isValid() && m_cellIds[bucket->cellIndex] == cellId)
329 for (
size_t offset = 1; bucket->isActive() && offset <= m_maxProbeLength; offset++)
331 index = (hashValue + offset * offset) %
m_capacity;
332 bucket = &m_buckets[index];
334 if (bucket->isValid() && m_cellIds[bucket->cellIndex] == cellId)
342 void rebuild(
size_t size)
348 Bucket *oldBuckets = m_buckets;
353 ::
new (&m_buckets[i])
Bucket();
356 m_maxProbeLength = 0;
358 for (
size_t i = 0; i < oldNumBuckets; i++)
360 Bucket& bucket = oldBuckets[i];
362 if (bucket.isValid())
363 this->
insert(m_cellIds[bucket.cellIndex], bucket.cellIndex);
372 m_cellIds = m_cellIdBuffer->ptr<CellIdT>();
382 Real32 m_smoothingAverage;
384 ByteAllocator m_allocator;
388 const CellIdT *m_cellIds;