17 #ifndef AGXCOLLIDE_COLLISIONGROUPHANDLER_H
18 #define AGXCOLLIDE_COLLISIONGROUPHANDLER_H
118 bool hasGroup(
const agx::Name& groupName)
const;
153 void removeInactiveSets();
185 {
return state >= ACTIVE; }
190 return state == VALID;
194 friend class GroupSetCache;
213 m_maxProbeLength = 0;
233 size_t numGroups = 0;
236 const GroupVector& groups = set.
groups();
238 for (; i < groups.size() && groups[i].
id() < group.
id(); ++i)
239 localGroups[numGroups++] = groups[i];
241 localGroups[numGroups++] = group;
243 for (; i < groups.size(); ++i)
244 localGroups[numGroups++] = groups[i];
247 agx::UInt32 bucketIndex = findBucket(localGroups, numGroups);
255 size_t numGroups = 0;
258 const GroupVector& groups = set.
groups();
259 for (
size_t i = 0; i < groups.size(); ++i)
261 if (groups[i].
id() == group.
id())
264 localGroups[numGroups++] = groups[i];
267 agx::UInt32 bucketIndex = findBucket(localGroups, numGroups);
276 const GroupVector& groups = set.
groups();
278 agx::UInt32 bucketIndex = findBucket(groups.begin(), groups.size());
285 const GroupVector& groups = set.
groups();
287 agx::UInt32 hashValue = calculateHash(groups.begin(), groups.size());
302 bucket = &m_buckets[(hashValue + offset * offset) %
m_capacity];
305 if (bucket->isValid() && compareGroups(groups.begin(), groups.size(), bucket->groupSet))
307 targetBucket = bucket;
312 if (!bucket->isValid() && !targetBucket)
313 targetBucket = bucket;
316 if (targetBucket && offset >= m_maxProbeLength)
326 return this->insert(set);
332 if (offset > m_maxProbeLength)
335 targetBucket->groupSet = set;
338 if (!targetBucket->isValid())
341 targetBucket->state = Bucket::VALID;
347 return find(set).isValid();
354 const GroupVector& groups = set.
groups();
356 agx::UInt32 bucketIndex = findBucket(groups.begin(), groups.size());
359 Bucket *bucket = &m_buckets[bucketIndex];
360 agxAssert(bucket->isValid() && compareGroups(groups.begin(), groups.size(), bucket->groupSet));
365 bucket->state = Bucket::ACTIVE;
375 agx::UInt32 hashValue = calculateHash(localGroups, numGroups);
378 const Bucket *bucket = &m_buckets[index];
381 if (bucket->isValid() && compareGroups(localGroups, numGroups, bucket->groupSet))
385 for (
size_t offset = 1; bucket->isActive() && offset <= m_maxProbeLength; offset++)
387 index = (hashValue + offset * offset) %
m_capacity;
388 bucket = &m_buckets[index];
390 if (bucket->isValid() && compareGroups(localGroups, numGroups, bucket->groupSet))
403 for (
size_t i = 0; i < numGroups; ++i)
413 const GroupVector& groups = set.
groups();
415 if (groups.size() != numGroups)
418 for (
size_t i = 0; i < groups.size(); ++i)
420 if (groups[i].
id() != localGroups[i].
id())
427 void rebuild(
size_t size)
433 Bucket *oldBuckets = m_buckets;
438 ::
new (&m_buckets[i])
Bucket();
441 m_maxProbeLength = 0;
443 for (
size_t i = 0; i < oldNumBuckets; i++)
445 Bucket& bucket = oldBuckets[i];
447 if (bucket.isValid())
448 this->insert(bucket.groupSet);
451 m_allocator.deallocateBytes((
void *)oldBuckets, oldNumBuckets *
sizeof(
Bucket));
454 void deallocateBuckets()
473 GroupSetCache m_groupSetCache;
476 CollisionHash m_disabledSetCollisions;
477 CollisionHash m_disabledGroupCollisions;
484 CollisionGroupTable m_collisionGroupTable;
487 CollisionGroupNameTable m_collisionGroupNameTable;