Changes in Set and Map classes

This commit is contained in:
Daniel Chappuis 2021-09-02 20:49:12 +02:00
parent e7a1296de1
commit e229cc9b4b
2 changed files with 24 additions and 13 deletions

View File

@ -89,7 +89,8 @@ class Map {
if (mHashSize > 0) {
const size_t hashCode = Hash()(key);
const uint32 bucket = hashCode & (mHashSize - 1);
const size_t divider = mHashSize - 1;
const uint32 bucket = static_cast<uint32>(hashCode & divider);
auto keyEqual = KeyEqual();
for (uint32 i = mBuckets[bucket]; i != INVALID_INDEX; i = mNextEntries[i]) {
@ -304,7 +305,8 @@ class Map {
// Get the corresponding bucket
const size_t hashCode = Hash()(mEntries[entryIndex].first);
const uint32 bucketIndex = hashCode & (capacity - 1);
const size_t divider = capacity - 1;
const uint32 bucketIndex = static_cast<uint32>(hashCode & divider);
newNextEntries[entryIndex] = newBuckets[bucketIndex];
newBuckets[bucketIndex] = entryIndex;
@ -358,7 +360,8 @@ class Map {
if (mHashSize > 0) {
// Compute the corresponding bucket index
bucket = hashCode & (mHashSize - 1);
const size_t divider = mHashSize - 1;
bucket = static_cast<uint32>(hashCode & divider);
auto keyEqual = KeyEqual();
@ -395,7 +398,8 @@ class Map {
reserve(mHashSize == 0 ? 16 : mHashSize * 2);
// Recompute the bucket index
bucket = hashCode & (mHashSize - 1);
const size_t divider = mHashSize - 1;
bucket = static_cast<uint32>(hashCode & divider);
}
assert(mNbEntries < mNbAllocatedEntries);
@ -432,7 +436,8 @@ class Map {
const size_t hashcode = Hash()(key);
auto keyEqual = KeyEqual();
const uint32 bucket = hashcode & (mHashSize - 1);
const size_t divider = mHashSize - 1;
const uint32 bucket = static_cast<uint32>(hashcode & divider);
uint32 last = INVALID_INDEX;
for (uint32 i = mBuckets[bucket]; i != INVALID_INDEX; last = i, i = mNextEntries[i]) {
@ -537,7 +542,8 @@ class Map {
if (mHashSize > 0) {
const size_t hashCode = Hash()(key);
bucket = hashCode & (mHashSize - 1);
const size_t divider = mHashSize - 1;
bucket = hashCode & divider;
auto keyEqual = KeyEqual();
for (uint32 i = mBuckets[bucket]; i != INVALID_INDEX; i = mNextEntries[i]) {

View File

@ -34,7 +34,6 @@
#include <functional>
#include <limits>
namespace reactphysics3d {
// Class Set
@ -89,7 +88,8 @@ class Set {
if (mHashSize > 0) {
const size_t hashCode = Hash()(value);
const uint32 bucket = hashCode & (mHashSize - 1);
const size_t divider = mHashSize - 1;
const uint32 bucket = static_cast<uint32>(hashCode & divider);
auto keyEqual = KeyEqual();
for (uint32 i = mBuckets[bucket]; i != INVALID_INDEX; i = mNextEntries[i]) {
@ -304,7 +304,8 @@ class Set {
// Get the corresponding bucket
const size_t hashCode = Hash()(mEntries[entryIndex]);
const uint32 bucketIndex = hashCode & (capacity - 1);
const size_t divider = capacity - 1;
const uint32 bucketIndex = static_cast<uint32>(hashCode & divider);
newNextEntries[entryIndex] = newBuckets[bucketIndex];
newBuckets[bucketIndex] = entryIndex;
@ -358,7 +359,8 @@ class Set {
if (mHashSize > 0) {
// Compute the corresponding bucket index
bucket = hashCode & (mHashSize - 1);
const size_t divider = mHashSize - 1;
bucket = static_cast<uint32>(hashCode & divider);
auto keyEqual = KeyEqual();
@ -382,7 +384,8 @@ class Set {
reserve(mHashSize == 0 ? 16 : mHashSize * 2);
// Recompute the bucket index
bucket = hashCode & (mHashSize - 1);
const size_t divider = mHashSize - 1;
bucket = static_cast<uint32>(hashCode & divider);
}
assert(mNbEntries < mNbAllocatedEntries);
@ -418,7 +421,8 @@ class Set {
const size_t hashcode = Hash()(value);
auto keyEqual = KeyEqual();
const uint32 bucket = hashcode & (mHashSize - 1);
const size_t divider = mHashSize - 1;
const uint32 bucket = static_cast<uint32>(hashcode & divider);
uint32 last = INVALID_INDEX;
for (uint32 i = mBuckets[bucket]; i != INVALID_INDEX; last = i, i = mNextEntries[i]) {
@ -535,7 +539,8 @@ class Set {
if (mHashSize > 0) {
const size_t hashCode = Hash()(value);
bucket = hashCode & (mHashSize - 1);
const size_t divider = mHashSize - 1;
bucket = static_cast<uint32>(hashCode & divider);
auto keyEqual = KeyEqual();
for (uint32 i = mBuckets[bucket]; i != INVALID_INDEX; i = mNextEntries[i]) {