Rename set() to assign()
authorJeff Preshing <filter-github@preshing.com>
Mon, 14 Mar 2016 15:53:08 +0000 (11:53 -0400)
committerJeff Preshing <filter-github@preshing.com>
Mon, 14 Mar 2016 15:53:08 +0000 (11:53 -0400)
Will avoid ambiguity when ConcurrentSets are added to Junction, and more
consistent with C++17's insert_or_assign.

24 files changed:
README.md
junction/ConcurrentMap_Crude.h
junction/ConcurrentMap_Grampa.h
junction/ConcurrentMap_Leapfrog.h
junction/ConcurrentMap_Linear.h
junction/SingleMap_Linear.h
junction/extra/impl/MapAdapter_CDS_Cuckoo.h
junction/extra/impl/MapAdapter_CDS_Michael.h
junction/extra/impl/MapAdapter_Folly.h
junction/extra/impl/MapAdapter_LibCuckoo.h
junction/extra/impl/MapAdapter_Linear_Mutex.h
junction/extra/impl/MapAdapter_Linear_RWLock.h
junction/extra/impl/MapAdapter_NBDS.h
junction/extra/impl/MapAdapter_Null.h
junction/extra/impl/MapAdapter_StdMap.h
junction/extra/impl/MapAdapter_TBB.h
junction/extra/impl/MapAdapter_Tervel.h
samples/MallocTest/MallocTest.cpp
samples/MapCorrectnessTests/TestChurn.h
samples/MapCorrectnessTests/TestInsertDifferentKeys.h
samples/MapCorrectnessTests/TestInsertSameKeys.h
samples/MapLinearizabilityTest/MapLinearizabilityTest.cpp
samples/MapPerformanceTests/MapPerformanceTests.cpp
samples/MapScalabilityTests/MapScalabilityTests.cpp

index b4361a0d931b6abce227b452b7a1270c8fbc12d3..d603544caedfdff2d177747f7986c6803783be5f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -102,9 +102,9 @@ The `JUNCTION_USERCONFIG` variable works in a similar way. As an example, take a
 A Junction map is a lot like a big array of `std::atomic<>` variables, where the key is an index into the array. More precisely:
 
 * All of a Junction map's member functions, together with its `Mutator` member functions, are atomic with respect to each other, so you can safely call them from any thread without mutual exclusion.
-* If an `set` [happens before](http://preshing.com/20130702/the-happens-before-relation/) a `get` with the same key, the `get` will return the value set, except if another operation changes the value in between. Any [synchronizing operation](http://preshing.com/20130823/the-synchronizes-with-relation/) will establish this relationship.
-* For Linear, Leapfrog and Grampa maps, `set` is a [release](http://preshing.com/20120913/acquire-and-release-semantics/) operation and `get` is a [consume](http://preshing.com/20140709/the-purpose-of-memory_order_consume-in-cpp11/) operation, so you can safely pass non-atomic information between threads using a pointer. For Crude maps, all operations are relaxed.
-* In the current version, you must not set while concurrently using an `Iterator`.
+* If an `assign` [happens before](http://preshing.com/20130702/the-happens-before-relation/) a `get` with the same key, the `get` will return the value it inserted, except if another operation changes the value in between. Any [synchronizing operation](http://preshing.com/20130823/the-synchronizes-with-relation/) will establish this relationship.
+* For Linear, Leapfrog and Grampa maps, `assign` is a [release](http://preshing.com/20120913/acquire-and-release-semantics/) operation and `get` is a [consume](http://preshing.com/20140709/the-purpose-of-memory_order_consume-in-cpp11/) operation, so you can safely pass non-atomic information between threads using a pointer. For Crude maps, all operations are relaxed.
+* In the current version, you must not `assign` while concurrently using an `Iterator`.
 
 ## Feedback
 
index d064a4805b155a1b2702b1eeb5afeea8b9a751a8..0d8fd162687a5ca3d79284bb967de3a7a6318ea3 100644 (file)
@@ -49,7 +49,7 @@ public:
         delete[] m_cells;
     }
 
-    void set(Key key, Value value) {
+    void assign(Key key, Value value) {
         TURF_ASSERT(key != KeyTraits::NullKey);
         TURF_ASSERT(value != Value(ValueTraits::NullValue));
 
index c8fdc8d561e0b3f46c9e7e9aa56dd7e59f383262..8422b2261a278855a214f6595dfb02c1dcad777f 100644 (file)
@@ -398,7 +398,7 @@ public:
             }
         }
 
-        void setValue(Value desired) {
+        void assignValue(Value desired) {
             exchangeValue(desired);
         }
 
@@ -478,7 +478,7 @@ public:
         }
     }
 
-    Value set(Key key, Value desired) {
+    Value assign(Key key, Value desired) {
         Mutator iter(*this, key);
         return iter.exchangeValue(desired);
     }
index 3a8493e62d18ec979cc4f2d26038d470cb0814f3..4850f0db0006fd822283ba0584ede5349288901b 100644 (file)
@@ -197,7 +197,7 @@ public:
             }
         }
 
-        void setValue(Value desired) {
+        void assignValue(Value desired) {
             exchangeValue(desired);
         }
 
@@ -273,7 +273,7 @@ public:
         }
     }
 
-    Value set(Key key, Value desired) {
+    Value assign(Key key, Value desired) {
         Mutator iter(*this, key);
         return iter.exchangeValue(desired);
     }
index 7e268e59fb1f99c29757c6e21052ff01e7eecdde..6e74efacf0a2b5ddb67b5c9882de1d354ec6cf3a 100644 (file)
@@ -193,7 +193,7 @@ public:
             }
         }
 
-        void setValue(Value desired) {
+        void assignValue(Value desired) {
             exchangeValue(desired);
         }
 
@@ -270,7 +270,7 @@ public:
         }
     }
 
-    Value set(Key key, Value desired) {
+    Value assign(Key key, Value desired) {
         Mutator iter(*this, key);
         return iter.exchangeValue(desired);
     }
index ff1fd525ba63c72e8f39e71562062867988477b5..5716b4c64170a9fc79e125cca98d03bb8eaeff98 100644 (file)
@@ -189,7 +189,7 @@ public:
         return iter.isValid() ? iter.getValue() : NULL;
     }
 
-    Value set(const Key& key, Value desired) {
+    Value assign(const Key& key, Value desired) {
         Mutator iter(*this, key);
         return iter.exchangeValue(desired);
     }
index 71fef3083c686272b369315564f8c30144ac32c9..56ea0dfef5d2858d8cccc6b8071e357c0bde4f73 100644 (file)
@@ -86,7 +86,7 @@ public:
         Map(ureg capacity) : m_map() {
         }
 
-        void set(u32 key, void* value) {
+        void assign(u32 key, void* value) {
             m_map.insert(key, value);
         }
 
index bd6f1cdc0c00df82bfb2e422eb9c1512820b1b36..8820b79e5a49cc5f5cb6e7941e65971782dfe70e 100644 (file)
@@ -86,7 +86,7 @@ public:
         Map(ureg capacity) : m_map(capacity, 1) {
         }
 
-        void set(u32 key, void* value) {
+        void assign(u32 key, void* value) {
             m_map.insert(key, value);
         }
 
index 2cc837674e0931ac444a5ced47f1d58a7797f12e..2054483d85335511378c25b2dfb2230cc821012a 100644 (file)
@@ -54,7 +54,7 @@ public:
         Map(ureg capacity) : m_map(capacity) {
         }
 
-        void set(u32 key, void* value) {
+        void assign(u32 key, void* value) {
             m_map.insert(std::make_pair(key, value));
         }
 
index 9e8381776d9a644f455249fecbbd597b5dbfb2b9..784f9b034d2847af2caa895a680eb78f23db112a 100644 (file)
@@ -54,7 +54,7 @@ public:
         Map(ureg capacity) : m_map(capacity) {
         }
 
-        void set(u32 key, void* value) {
+        void assign(u32 key, void* value) {
             m_map.insert(key, value);
         }
 
index d383663442d1be939bdab58923735b1871a760d5..3592a1f7f5e6ce2944327057fc6c293d7ef6bb3b 100644 (file)
@@ -52,9 +52,9 @@ public:
         Map(ureg capacity) : m_map(capacity) {
         }
 
-        void set(u32 key, void* value) {
+        void assign(u32 key, void* value) {
             turf::LockGuard<turf::Mutex> guard(m_mutex);
-            m_map.set(key, value);
+            m_map.assign(key, value);
         }
 
         void* get(u32 key) {
index 8c0855932a21882311a2c984c8fba7a5946c3c9b..24bb227b89bc3dd7472945a81f280836c03446b0 100644 (file)
@@ -52,9 +52,9 @@ public:
         Map(ureg capacity) : m_map(capacity) {
         }
 
-        void set(u32 key, void* value) {
+        void assign(u32 key, void* value) {
             turf::ExclusiveLockGuard<turf::RWLock> guard(m_rwLock);
-            m_map.set(key, value);
+            m_map.assign(key, value);
         }
 
         void* get(u32 key) {
index bd2bc86dd50662343a091252e3c7afb18e881c2e..13e933406c36a2a9874a36350963c27ccaa89727 100644 (file)
@@ -69,7 +69,7 @@ public:
             ht_free(m_map);
         }
 
-        void set(u32 key, void* value) {
+        void assign(u32 key, void* value) {
             ht_cas(m_map, key, CAS_EXPECT_WHATEVER, (map_val_t) value);
         }
 
index af17120a601505ec16fc37007e2895b5cf593a93..f25dd9dc2146274c8479d930ae1d91b083fd91c1 100644 (file)
@@ -45,7 +45,7 @@ public:
         Map(ureg) {
         }
 
-        void set(u32, void*) {
+        void assign(u32, void*) {
         }
 
         void* get(u32) {
index 84259369d1cdddea13dba15f7af51021481d8f83..9fde8f4b136eb63eaf209f50bc7bd47b0ebf53f5 100644 (file)
@@ -52,7 +52,7 @@ public:
         Map(ureg) {
         }
 
-        void set(u32 key, void* value) {
+        void assign(u32 key, void* value) {
             std::lock_guard<std::mutex> guard(m_mutex);
             m_map[key] = value;
         }
index aa442ae97c8fddfb18a96f7df596f25497499b77..3e9bc0129ea112a140d13f7a05f289a626d5699d 100644 (file)
@@ -54,7 +54,7 @@ public:
         Map(ureg capacity) : m_map(capacity) {
         }
 
-        void set(u32 key, void* value) {
+        void assign(u32 key, void* value) {
             m_map.insert(std::make_pair(key, value));
         }
 
index d2942780fe328058b9ad101aa5daa0191817485b..440dff002dba4549ab21d3aa50f8165799f223d3 100644 (file)
@@ -62,7 +62,7 @@ public:
         Map(ureg capacity) : m_map(capacity, 3) {
         }
 
-        void set(u32 key, void* value) {
+        void assign(u32 key, void* value) {
             m_map.insert(key, (u64) value);
         }
 
index a6695d2a8b44905e0c0c015e9c69e7b4fc0d0c0a..c0e18cf71091e50b00b22028ec82f648200285b1 100644 (file)
@@ -28,7 +28,7 @@ int main() {
         std::cout << "Population=" << population << ", inUse=" << TURF_HEAP.getInUseBytes() << std::endl;
 #endif
         for (; population < i * 5000; population++)
-            map.set(population + 1, (void*) ((population << 2) | 3));
+            map.assign(population + 1, (void*) ((population << 2) | 3));
     }
 
     return 0;
index ca2b321fc2c066f9d72ccbb2b6d8befa99fa11e2..ac3800eeca991d59211f8c517c1bfbe6e0cc3d34 100644 (file)
@@ -79,7 +79,7 @@ public:
             u32 key = thread.insertIndex * m_relativePrime;
             key = key ^ (key >> 16);
             if (key >= 2) {
-                m_map.set(key, (void*) uptr(key));
+                m_map.assign(key, (void*) uptr(key));
             }
             if (++thread.insertIndex >= thread.rangeHi)
                 thread.insertIndex = thread.rangeLo;
@@ -96,7 +96,7 @@ public:
                     u32 key = thread.insertIndex * m_relativePrime;
                     key = key ^ (key >> 16);
                     if (key >= 2) {
-                        m_map.set(key, (void*) uptr(key));
+                        m_map.assign(key, (void*) uptr(key));
                     }
                     if (++thread.insertIndex >= thread.rangeHi)
                         thread.insertIndex = thread.rangeLo;
index 7e7bdaac3f5eb916e93fb1ef6020b9c40fca9f47..c0e22117c1ea64f4b426367a537f6f8ddd3a24f4 100644 (file)
@@ -36,7 +36,7 @@ public:
             u32 key = index * m_relativePrime;
             key = key ^ (key >> 16);
             if (key >= 2) { // Don't insert 0 or 1
-                m_map->set(key, (void*) uptr(key));
+                m_map->assign(key, (void*) uptr(key));
                 keysRemaining--;
             }
             index++;
index 8510d8ca716097a83cbe1937ad8f264c457971de..63e9172079028b7b74565dbd22e0a983d4261e1a 100644 (file)
@@ -36,7 +36,7 @@ public:
             u32 key = index * m_relativePrime;
             key = key ^ (key >> 16);
             if (key >= 2) { // Don't insert 0 or 1
-                m_map->set(key, (void*) uptr(key));
+                m_map->assign(key, (void*) uptr(key));
                 keysRemaining--;
             }
             index++;
index 1532de5cd1511b948bafc43cf4f61a639412bcad..243d32a23adbd2c019541c98133c12b8cb271b40 100644 (file)
@@ -49,10 +49,10 @@ public:
         if (threadIndex == 0) {
             // We store 2 because Junction maps reserve 1 for the default Redirect value.
             // The default can be overridden, but this is easier.
-            m_map.set(x, (void*) 2);
+            m_map.assign(x, (void*) 2);
             m_r1 = (uptr) m_map.get(y);
         } else {
-            m_map.set(y, (void*) 2);
+            m_map.assign(y, (void*) 2);
             m_r2 = (uptr) m_map.get(x);
         }
     }
@@ -89,11 +89,11 @@ public:
         case 0:
             // We store 2 because Junction maps reserve 1 for the default Redirect value.
             // The default can be overridden, but this is easier.
-            m_map.set(x, (void*) 2);
+            m_map.assign(x, (void*) 2);
             break;
             
         case 1:
-            m_map.set(y, (void*) 2);
+            m_map.assign(y, (void*) 2);
             break;
             
         case 2:
index d0a5e3d583214300f21f6800479928a371052315..ceead97ea0b19dbfb31897591a51b2547104eee8 100644 (file)
@@ -126,7 +126,7 @@ public:
         MapAdapter::Map* map = m_shared.map;
         for (ureg i = 0; i < m_shared.numKeysPerThread; i++) {
             u32 key = m_addIndex * Prime;
-            map->set(key, (void*) (key & ~uptr(3)));
+            map->assign(key, (void*) (key & ~uptr(3)));
             if (++m_addIndex == m_rangeHi)
                 m_addIndex = m_rangeLo;
         }
@@ -155,7 +155,7 @@ public:
                 break;
             u32 key = m_addIndex * Prime;
             if (key >= 2) {
-                map->set(key, (void*) uptr(key));
+                map->assign(key, (void*) uptr(key));
                 stats.mapOpsDone++;
             }
             if (++m_addIndex == m_rangeHi)
index 0841bdd225d8eb740e1f1f0b9aafa6eea20d5d25..a9fa58b48052b2c621363bcc43119584ab68f955 100644 (file)
@@ -103,7 +103,7 @@ public:
         for (ureg i = 0; i < m_shared.numKeysPerThread; i++) {
             u32 key = m_addIndex * Prime;
             if (key >= 2)
-                map->set(key, (void*) uptr(key));
+                map->assign(key, (void*) uptr(key));
             if (++m_addIndex == m_rangeHi)
                 m_addIndex = m_rangeLo;
         }
@@ -130,7 +130,7 @@ public:
                 break;
             u32 key = m_addIndex * Prime;
             if (key >= 2) {
-                map->set(key, (void*) uptr(key));
+                map->assign(key, (void*) uptr(key));
                 stats.mapOpsDone++;
             }
             if (++m_addIndex == m_rangeHi)