Fix MSVC warnings with u64 keys
authorJeff Preshing <filter-github@preshing.com>
Wed, 10 Feb 2016 13:59:29 +0000 (08:59 -0500)
committerJeff Preshing <filter-github@preshing.com>
Wed, 10 Feb 2016 13:59:29 +0000 (08:59 -0500)
junction/ConcurrentMap_Grampa.h
junction/ConcurrentMap_LeapFrog.h
junction/ConcurrentMap_Linear.h
junction/details/Grampa.h
junction/details/LeapFrog.h
junction/details/Linear.h

index b0d6cec..8d67f22 100644 (file)
@@ -41,7 +41,7 @@ private:
         if (root & 1) {
             typename Details::FlatTree* flatTree = (typename Details::FlatTree*) (root & ~ureg(1));
             for (;;) {
-                ureg leafIdx = (hash >> flatTree->safeShift);
+                ureg leafIdx = ureg(hash >> flatTree->safeShift);
                 table = flatTree->getTables()[leafIdx].load(turf::Relaxed);
                 if (ureg(table) != Details::RedirectFlatTree) {
                     sizeMask = (Details::LeafSize - 1);
@@ -189,7 +189,7 @@ public:
                         // Retry the loop.
                     } else {
                         ureg repeat = ureg(1) << (migration->m_safeShift - flatTree->safeShift);
-                        ureg dstStartIndex = migration->m_baseHash >> flatTree->safeShift;
+                        ureg dstStartIndex = ureg(migration->m_baseHash >> flatTree->safeShift);
                         // The subtree we're about to publish fits inside the flattree.
                         TURF_ASSERT(dstStartIndex + migration->m_numDestinations * repeat - 1 <= Hash(-1) >> flatTree->safeShift);
                         // If a previous attempt to publish got redirected, resume publishing into the new flattree,
index 0a51ad9..a9dc4a3 100644 (file)
@@ -37,7 +37,7 @@ private:
     turf::Atomic<typename Details::Table*> m_root;
 
 public:
-    ConcurrentMap_LeapFrog(ureg capacity) : m_root(Details::Table::create(capacity)) {
+    ConcurrentMap_LeapFrog(ureg capacity = Details::InitialSize) : m_root(Details::Table::create(capacity)) {
     }
 
     ~ConcurrentMap_LeapFrog() {
index 32b2a37..4cf349d 100644 (file)
@@ -37,7 +37,7 @@ private:
     turf::Atomic<typename Details::Table*> m_root;
 
 public:
-    ConcurrentMap_Linear(ureg capacity) {
+    ConcurrentMap_Linear(ureg capacity = Details::InitialSize) {
         ureg limitNumValues = capacity * 3 / 4;
         m_root.storeNonatomic(Details::Table::create(capacity, limitNumValues));
     }
index e628757..9f85df2 100644 (file)
@@ -110,7 +110,7 @@ struct Grampa {
             : sizeMask(sizeMask), baseHash(baseHash), unsafeRangeShift(unsafeRangeShift) {
         }
 
-        static Table* create(ureg tableSize, ureg baseHash, ureg unsafeShift) {
+        static Table* create(ureg tableSize, Hash baseHash, ureg unsafeShift) {
             TURF_ASSERT(turf::util::isPowerOf2(tableSize));
             TURF_ASSERT(unsafeShift > 0 && unsafeShift <= sizeof(Hash) * 8);
             TURF_ASSERT(tableSize >= 4);
@@ -362,7 +362,7 @@ struct Grampa {
         TURF_TRACE(Grampa, 3, "[insert] called", uptr(table), hash);
         TURF_ASSERT(table);
         TURF_ASSERT(hash != KeyTraits::NullHash);
-        ureg idx = hash;
+        ureg idx = ureg(hash);
 
         // Check hashed cell first, though it may not even belong to the bucket.
         CellGroup* group = table->getCellGroups() + ((idx & sizeMask) >> 2);
index e5af7b8..800d737 100644 (file)
@@ -191,7 +191,7 @@ struct LeapFrog {
         TURF_ASSERT(table);
         TURF_ASSERT(hash != KeyTraits::NullHash);
         ureg sizeMask = table->sizeMask;
-        ureg idx = hash;
+        ureg idx = ureg(hash);
 
         // Check hashed cell first, though it may not even belong to the bucket.
         CellGroup* group = table->getCellGroups() + ((idx & sizeMask) >> 2);
index d2ee367..991f853 100644 (file)
@@ -117,11 +117,11 @@ struct Linear {
         TURF_ASSERT(table);
         TURF_ASSERT(hash != KeyTraits::NullHash);
         ureg sizeMask = table->sizeMask;
-        for (ureg idx = hash;; idx++) {
+        for (ureg idx = ureg(hash);; idx++) {
             idx &= sizeMask;
             Cell* cell = table->getCells() + idx;
             // Load the hash that was there.
-            uptr probeHash = cell->hash.load(turf::Relaxed);
+            Hash probeHash = cell->hash.load(turf::Relaxed);
             if (probeHash == hash) {
                 TURF_TRACE(Linear, 1, "[find] found existing cell", uptr(table), idx);
                 return cell;
@@ -139,11 +139,11 @@ struct Linear {
         TURF_ASSERT(hash != KeyTraits::NullHash);
         ureg sizeMask = table->sizeMask;
 
-        for (ureg idx = hash;; idx++) {
+        for (ureg idx = ureg(hash);; idx++) {
             idx &= sizeMask;
             cell = table->getCells() + idx;
             // Load the existing hash.
-            uptr probeHash = cell->hash.load(turf::Relaxed);
+            Hash probeHash = cell->hash.load(turf::Relaxed);
             if (probeHash == hash) {
                 TURF_TRACE(Linear, 3, "[insert] found existing cell", uptr(table), idx);
                 return InsertResult_AlreadyFound; // Key found in table. Return the existing cell.
@@ -159,7 +159,7 @@ struct Linear {
                     return InsertResult_Overflow;
                 }
                 // Try to reserve this cell.
-                uptr prevHash = cell->hash.compareExchange(KeyTraits::NullHash, hash, turf::Relaxed);
+                Hash prevHash = cell->hash.compareExchange(KeyTraits::NullHash, hash, turf::Relaxed);
                 if (prevHash == KeyTraits::NullHash) {
                     // Success. We reserved a new cell.
                     TURF_TRACE(Linear, 5, "[insert] reserved cell", prevCellsRemaining, idx);