Fixed some bugs related to type conversion
authorkhizmax <libcds.dev@gmail.com>
Sat, 2 Apr 2016 16:03:02 +0000 (19:03 +0300)
committerkhizmax <libcds.dev@gmail.com>
Sat, 2 Apr 2016 16:03:02 +0000 (19:03 +0300)
Docfix

cds/container/details/make_skip_list_map.h
cds/container/impl/skip_list_map.h
cds/container/skip_list_map_nogc.h
cds/container/skip_list_map_rcu.h
cds/container/skip_list_set_nogc.h
cds/container/skip_list_set_rcu.h

index e6377e7a8d53f71088d4dedd3ce0d094ad375b84..a55de3b96afc07106e66cbb68f6d12d14b454814 100644 (file)
@@ -96,7 +96,7 @@ namespace cds { namespace container { namespace details {
             template <typename Q>
             node_type * New( unsigned int nHeight, Q const& key )
             {
-                return base_class::New( nHeight, key );
+                return base_class::New( nHeight, key_type( key ));
             }
             template <typename Q, typename U>
             node_type * New( unsigned int nHeight, Q const& key, U const& val )
@@ -105,7 +105,7 @@ namespace cds { namespace container { namespace details {
                 return new( pMem )
                     node_type( nHeight,
                         nHeight > 1 ? reinterpret_cast<typename base_class::node_tower_item *>( pMem + base_class::c_nNodeSize ) : nullptr,
-                        key, val
+                        key_type( key ), mapped_type( val )
                     );
             }
             template <typename... Args>
index 5e8653d505756f90531dce221df496b4987575a3..b0fa85779e7b51d15cf49b551a0992449f56035e 100644 (file)
@@ -79,48 +79,6 @@ namespace cds { namespace container {
         - <tt><cds/container/skip_list_map_dhp.h></tt> for \p gc::DHP garbage collector
         - <tt><cds/container/skip_list_map_rcu.h></tt> for \ref cds_nonintrusive_SkipListMap_rcu "RCU type"
         - <tt><cds/container/skip_list_map_nogc.h></tt> for \ref cds_nonintrusive_SkipListMap_nogc "non-deletable SkipListMap"
-
-        <b>Iterators</b>
-
-        The class supports a forward iterator (\ref iterator and \ref const_iterator).
-        The iteration is ordered.
-        The iterator object is thread-safe: the element pointed by the iterator object is guarded,
-        so, the element cannot be reclaimed while the iterator object is alive.
-        However, passing an iterator object between threads is dangerous.
-
-        \warning Due to concurrent nature of skip-list map it is not guarantee that you can iterate
-        all elements in the map: any concurrent deletion can exclude the element
-        pointed by the iterator from the map, and your iteration can be terminated
-        before end of the map. Therefore, such iteration is more suitable for debugging purpose only
-
-        Remember, each iterator object requires 2 additional hazard pointers, that may be
-        a limited resource for \p GC like \p gc::HP (for gc::DHP the count of
-        guards is unlimited).
-
-        The iterator class supports the following minimalistic interface:
-        \code
-        struct iterator {
-            // Default ctor
-            iterator();
-
-            // Copy ctor
-            iterator( iterator const& s);
-
-            value_type * operator ->() const;
-            value_type& operator *() const;
-
-            // Pre-increment
-            iterator& operator ++();
-
-            // Copy assignment
-            iterator& operator = (const iterator& src);
-
-            bool operator ==(iterator const& i ) const;
-            bool operator !=(iterator const& i ) const;
-        };
-        \endcode
-        Note, the iterator object returned by \ref end, \ cend member functions points to \p nullptr and should not be dereferenced.
-
     */
     template <
         typename GC,
@@ -162,6 +120,8 @@ namespace cds { namespace container {
         typedef typename traits::random_level_generator random_level_generator ; ///< random level generator
         typedef typename traits::stat              stat;           ///< internal statistics type
 
+        static size_t const c_nHazardPtrCount = base_class::c_nHazardPtrCount; ///< Count of hazard pointer required for the skip-list
+
     protected:
         //@cond
         typedef typename maker::node_type           node_type;
@@ -193,11 +153,57 @@ namespace cds { namespace container {
         {}
 
     public:
+    ///@name Forward iterators (only for debugging purpose)
+    //@{
         /// Iterator type
+        /**
+            The forward iterator has some features:
+            - it is ordered
+            - it has no post-increment operator
+            - to protect the value, the iterator contains a GC-specific guard + another guard is required locally for increment operator.
+              For some GC (like as \p gc::HP), a guard is a limited resource per thread, so an exception (or assertion) "no free guard"
+              may be thrown if the limit of guard count per thread is exceeded.
+            - The iterator cannot be moved across thread boundary because it contains thread-private GC's guard.
+            - Iterator ensures thread-safety even if you delete the item the iterator points to. However, in case of concurrent
+              deleting operations there is no guarantee that you iterate all item in the list. 
+              Moreover, a crash is possible when you try to iterate the next element that has been deleted by concurrent thread.
+
+            @warning Use this iterator on the concurrent container for debugging purpose only.
+
+            @note \p end() and \p cend() are not dereferenceable.
+
+            The iterator interface:
+            \code
+            class iterator {
+            public:
+                // Default constructor
+                iterator();
+
+                // Copy construtor
+                iterator( iterator const& src );
+
+                // Dereference operator
+                value_type * operator ->() const;
+
+                // Dereference operator
+                value_type& operator *() const;
+
+                // Preincrement operator
+                iterator& operator ++();
+
+                // Assignment operator
+                iterator& operator = (iterator const& src);
+
+                // Equality operators
+                bool operator ==(iterator const& i ) const;
+                bool operator !=(iterator const& i ) const;
+            };
+            \endcode
+        */
         typedef skip_list::details::iterator< typename base_class::iterator >  iterator;
 
-        /// Const iterator type
-        typedef skip_list::details::iterator< typename base_class::const_iterator >   const_iterator;
+        /// Const forward iterator type
+        typedef skip_list::details::iterator< typename base_class::const_iterator > const_iterator;
 
         /// Returns a forward iterator addressing the first element in a map
         iterator begin()
@@ -210,6 +216,7 @@ namespace cds { namespace container {
         {
             return cbegin();
         }
+
         /// Returns a forward const iterator addressing the first element in a map
         const_iterator cbegin() const
         {
@@ -227,11 +234,13 @@ namespace cds { namespace container {
         {
             return cend();
         }
+
         /// Returns a forward const iterator that addresses the location succeeding the last element in a map.
         const_iterator cend() const
         {
             return const_iterator( base_class::cend() );
         }
+    //@}
 
     public:
         /// Inserts new node with key and default value
@@ -265,7 +274,7 @@ namespace cds { namespace container {
         template <typename K, typename V>
         bool insert( K const& key, V const& val )
         {
-            return insert_with( key, [&val](value_type& item) { item.second = val ; } );
+            return insert_with( key, [&val]( value_type& item ) { item.second = val; } );
         }
 
         /// Inserts new node and initialize it by a functor
index df625a176e5bb41351a5c4568c30ed765e3e7e02..2171c65053555fc760121747a439303939cdc9ee 100644 (file)
@@ -122,10 +122,13 @@ namespace cds { namespace container {
         {}
 
     public:
+    ///@name Forward ordered iterators
+    //@{
         /// Forward iterator
         /**
-            Remember, the iterator <tt>operator -> </tt> and <tt>operator *</tt> returns \ref value_type pointer and reference.
-            To access item key and value use <tt>it->first</tt> and <tt>it->second</tt> respectively.
+            The forward iterator for a split-list has some features:
+            - it has no post-increment operator
+            - it depends on iterator of underlying \p OrderedList
         */
         typedef typename base_class::iterator iterator;
 
@@ -157,6 +160,7 @@ namespace cds { namespace container {
         {
             return base_class::begin();
         }
+
         /// Returns a forward const iterator addressing the first element in a map
         const_iterator cbegin() const
         {
@@ -168,11 +172,13 @@ namespace cds { namespace container {
         {
             return base_class::end();
         }
+
         /// Returns an const iterator that addresses the location succeeding the last element in a map
         const_iterator cend() const
         {
             return base_class::cend();
         }
+    //@}
 
     public:
         /// Inserts new node with key and default value
@@ -190,7 +196,7 @@ namespace cds { namespace container {
         iterator insert( K const& key )
         {
             //TODO: pass arguments by reference (make_pair makes copy)
-            return base_class::insert( std::make_pair( key, mapped_type() ) );
+            return base_class::insert( std::make_pair( key_type( key ), mapped_type() ) );
         }
 
         /// Inserts new node
@@ -208,7 +214,7 @@ namespace cds { namespace container {
         iterator insert( K const& key, V const& val )
         {
             //TODO: pass arguments by reference (make_pair makes copy)
-            return base_class::insert( std::make_pair( key, val ) );
+            return base_class::insert( std::make_pair( key_type( key ), mapped_type( val )));
         }
 
         /// Inserts new node and initialize it by a functor
@@ -256,7 +262,7 @@ namespace cds { namespace container {
         template <typename K, typename... Args>
         iterator emplace( K&& key, Args&&... args )
         {
-            return base_class::emplace( std::forward<K>(key), std::move(mapped_type(std::forward<Args>(args)...)));
+            return base_class::emplace( key_type( std::forward<K>( key )), mapped_type( std::forward<Args>(args)... ));
         }
 
         /// UPdates data by \p key
@@ -272,7 +278,7 @@ namespace cds { namespace container {
         std::pair<iterator, bool> update( K const& key, bool bInsert = true )
         {
             //TODO: pass arguments by reference (make_pair makes copy)
-            return base_class::update( std::make_pair( key, mapped_type() ), bInsert );
+            return base_class::update( std::make_pair( key_type( key ), mapped_type() ), bInsert );
         }
         //@cond
         template <typename K>
index 5bd9a8a01a30bc0cb92d2e15a17e617c0e166a10..64217a906a42ab80c04daf0344e25d5853db0883 100644 (file)
@@ -212,7 +212,17 @@ namespace cds { namespace container {
         {}
 
     public:
-        /// Iterator type
+    ///@name Forward ordered iterators (thread-safe under RCU lock)
+    //@{
+        /// Forward iterator
+        /**
+            The forward iterator has some features:
+            - it has no post-increment operator
+            - it depends on iterator of underlying \p OrderedList
+
+            You may safely use iterators in multi-threaded environment only under RCU lock.
+            Otherwise, a crash is possible if another thread deletes the element the iterator points to.
+        */
         typedef skip_list::details::iterator< typename base_class::iterator >  iterator;
 
         /// Const iterator type
@@ -251,6 +261,7 @@ namespace cds { namespace container {
         {
             return const_iterator( base_class::cend() );
         }
+    //@}
 
     public:
         /// Inserts new node with key and default value
index b337b12a515138ee1865ba8420a32a1cad6884c9..4f89d653fde618f5acee78f18698db320a6cb918 100644 (file)
@@ -201,7 +201,7 @@ namespace cds { namespace container {
     public:
     ///@name Forward iterators
     //@{
-        /// Forward iterator
+        /// Forward ordered iterator
         /**
             The forward iterator for a split-list has some features:
             - it has no post-increment operator
index f3770e1e7113f5db722b4b2e3c66a7633c592884..7d3f45eec868b0524870b7547f69d08b470642b5 100644 (file)
@@ -259,7 +259,7 @@ namespace cds { namespace container {
         {}
 
     public:
-    ///@name Forward iterators (thread-safe under RCU lock)
+    ///@name Forward ordered iterators (thread-safe under RCU lock)
     //@{
         /// Forward iterator
         /**