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);
206 m_buckets[i].cellIndex = sortedIndices[m_buckets[i].cellIndex];
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];
329 for (
size_t offset = 1; bucket->
isActive() && offset <= m_maxProbeLength; offset++)
331 index = (hashValue + offset * offset) %
m_capacity;
332 bucket = &m_buckets[index];
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];
366 m_allocator.deallocateBytes((
void *)oldBuckets, oldNumBuckets *
sizeof(
Bucket));
372 m_cellIds = m_cellIdBuffer->ptr<CellIdT>();
382 Real32 m_smoothingAverage;
388 const CellIdT *m_cellIds;
#define AGX_HASH_TABLE_MAX_PROBE_LENGTH
template_iterator()
Constructors.
bool operator!=(const template_iterator< T > &rhs)
template_iterator< CellTable > iterator
Iterators.
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
template_iterator< T > operator++(int)
template_iterator< T > operator--(int)
void insert(const CellIdT &cellId, UInt32 cellIndex)
#define AGX_HASH_TABLE_GROW_FACTOR
template_iterator(T *hashSet, size_t startIndex=0)
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
bool operator==(const template_iterator< T > &rhs)
UInt32 & operator*() const
bool contains(const CellIdT &cellId) const
template_iterator< const CellTable > const_iterator
Type-specific Array used for fast access into the data held by a Buffer.
Bucket & operator=(const Bucket &b)
template_iterator< T > & operator++()
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Templated callback with one argument.
CellTable(agxData::Buffer *cellIdBuffer)
Abstract representation of a data buffer.
UInt32 * operator->() const
template_iterator< T > operator--()
UInt32 find(const CellIdT &cellId) const
#define AGX_HASH_TABLE_MIN_SIZE
void erase(const CellIdT &cellId)
iterator end()
Iterator marking end of hash set.
AGXCORE_EXPORT int nextPrime(int n)
const_iterator begin() const
void updateWithReordering(const agxData::Array< UInt32 > &sortedIndices)
#define AGX_HASH_TABLE_GROW_THRESHOLD
#define agxAssert1(expr, msg)
const_iterator end() const
iterator begin()
Iterator to first element in hash set.
Vec3T< T > operator*(const Vec3T< T > &v, const AffineMatrix4x4T< T > &m)