Changed default back-off strategy
[libcds.git] / cds / container / feldman_hashmap_rcu.h
index 7a11254d00c4485265b098c163a2ab010d7a0a55..548164dbf65afb968be2d5f4f5051525dd7c4d50 100644 (file)
@@ -1,4 +1,32 @@
-//$$CDS-header$$
+/*
+    This file is a part of libcds - Concurrent Data Structures library
+
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
+
+    Source code repo: http://github.com/khizmax/libcds/
+    Download: http://sourceforge.net/projects/libcds/files/
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this
+      list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
 
 #ifndef CDSLIB_CONTAINER_FELDMAN_HASHMAP_RCU_H
 #define CDSLIB_CONTAINER_FELDMAN_HASHMAP_RCU_H
@@ -81,12 +109,15 @@ namespace cds { namespace container {
         typedef typename traits::allocator      allocator;      ///< Element allocator
         typedef typename traits::node_allocator node_allocator; ///< Array node allocator
         typedef typename traits::memory_model   memory_model;   ///< Memory model
-        typedef typename traits::back_off       back_off;       ///< Backoff strategy
+        typedef typename traits::back_off       back_off;       ///< Back-off strategy
         typedef typename traits::stat           stat;           ///< Internal statistics type
         typedef typename traits::rcu_check_deadlock rcu_check_deadlock; ///< Deadlock checking policy
         typedef typename gc::scoped_lock       rcu_lock;        ///< RCU scoped lock
         static CDS_CONSTEXPR const bool c_bExtractLockExternal = false; ///< Group of \p extract_xxx functions does not require external locking
 
+        /// Level statistics
+        typedef feldman_hashmap::level_statistics level_statistics;
+
     protected:
         //@cond
         typedef typename maker::node_type node_type;
@@ -288,8 +319,8 @@ namespace cds { namespace container {
     public:
         /// Creates empty map
         /**
-            @param head_bits: 2<sup>head_bits</sup> specifies the size of head array, minimum is 4.
-            @param array_bits: 2<sup>array_bits</sup> specifies the size of array node, minimum is 2.
+            @param head_bits - 2<sup>head_bits</sup> specifies the size of head array, minimum is 4.
+            @param array_bits - 2<sup>array_bits</sup> specifies the size of array node, minimum is 2.
 
             Equation for \p head_bits and \p array_bits:
             \code
@@ -321,7 +352,7 @@ namespace cds { namespace container {
         template <typename K>
         bool insert( K&& key )
         {
-            scoped_node_ptr sp( cxx_node_allocator().MoveNew( m_Hasher, std::forward<K>(key) ));
+            scoped_node_ptr sp( cxx_node_allocator().MoveNew( m_Hasher, std::forward<K>(key)));
             if ( base_class::insert( *sp )) {
                 sp.release();
                 return true;
@@ -429,7 +460,7 @@ namespace cds { namespace container {
 
             The functor may change any fields of the \p item.second.
 
-            Returns <tt> std::pair<bool, bool> </tt> where \p first is \p true if operation is successfull,
+            Returns <tt> std::pair<bool, bool> </tt> where \p first is \p true if operation is successful,
             \p second is \p true if new item has been added or \p false if \p key already exists.
 
             The function locks RCU internally.
@@ -535,7 +566,7 @@ namespace cds { namespace container {
         template <typename K>
         bool contains( K const& key )
         {
-            return base_class::contains( m_Hasher( key_type( key )) );
+            return base_class::contains( m_Hasher( key_type( key )));
         }
 
         /// Find the key \p key
@@ -640,7 +671,13 @@ namespace cds { namespace container {
         }
 
         /// Collects tree level statistics into \p stat
-        /** @copydetails cds::intrusive::FeldmanHashSet::get_level_statistics
+        /**
+            The function traverses the set and collects statistics for each level of the tree
+            into \p feldman_hashset::level_statistics struct. The element of \p stat[i]
+            represents statistics for level \p i, level 0 is head array.
+            The function is thread-safe and may be called in multi-threaded environment.
+
+            Result can be useful for estimating efficiency of hash functor you use.
         */
         void get_level_statistics(std::vector< feldman_hashmap::level_statistics>& stat) const
         {