[draft] implemented container::MultiLevelHashSet
[libcds.git] / cds / container / skip_list_map_rcu.h
index 8b78ba8133851f695251d6d4af0782b2e06770da..70185d7fe8a296ee1d78f598b5481a972b9b6e83 100644 (file)
@@ -326,46 +326,55 @@ namespace cds { namespace container {
             return false;
         }
 
-        /// Ensures that the \p key exists in the map
+        /// Updates data by \p key
         /**
             The operation performs inserting or changing data with lock-free manner.
 
             If the \p key not found in the map, then the new item created from \p key
-            is inserted into the map (note that in this case the \ref key_type should be
-            constructible from type \p K).
-            Otherwise, the functor \p func is called with item found.
+            is inserted into the map iff \p bInsert is \p true.
+            Otherwise, if \p key found, the functor \p func is called with item found.
             The functor \p Func interface is:
             \code
                 struct my_functor {
                     void operator()( bool bNew, value_type& item );
                 };
             \endcode
-            with arguments:
+            where:
             - \p bNew - \p true if the item has been inserted, \p false otherwise
-            - \p item - item of the list
+            - \p item - item of the map
 
             The functor may change any fields of \p item.second.
 
             RCU \p synchronize() method can be called. RCU should not be locked.
 
-            Returns <tt> std::pair<bool, bool> </tt> where \p first is true if operation is successfull,
-            \p second is true if new item has been added or \p false if the item with \p key
-            already is in the list.
+            Returns <tt> std::pair<bool, bool> </tt> where \p first is \p true if operation is successfull,
+            \p second is \p true if new item has been added or \p false if the item with \p key
+            already exists.
 
             @warning See \ref cds_intrusive_item_creating "insert item troubleshooting"
         */
         template <typename K, typename Func>
-        std::pair<bool, bool> ensure( K const& key, Func func )
+        std::pair<bool, bool> update( K const& key, Func func, bool bInsert = true )
         {
             scoped_node_ptr pNode( node_allocator().New( random_level(), key ));
-            std::pair<bool, bool> res = base_class::ensure( *pNode,
-                [&func](bool bNew, node_type& item, node_type const& ){ func( bNew, item.m_Value ); }
+            std::pair<bool, bool> res = base_class::update( *pNode,
+                [&func](bool bNew, node_type& item, node_type const& ){ func( bNew, item.m_Value );},
+                bInsert
             );
             if ( res.first && res.second )
                 pNode.release();
             return res;
         }
 
+        //@cond
+        // Deprecated, use update()
+        template <typename K, typename Func>
+        std::pair<bool, bool> ensure( K const& key, Func func )
+        {
+            return update( key, func, true );
+        }
+        //@endcond
+
         /// Delete \p key from the map
         /**\anchor cds_nonintrusive_SkipListMap_rcu_erase_val