Added hash_size option support to FeldmanHashMap
[libcds.git] / cds / container / impl / feldman_hashmap.h
index 2e28e3e248949eb8214dc2a3ab9b345406b4347e..453b245cad2b294749b3b83803f9b3fba16cf31e 100644 (file)
@@ -5,7 +5,7 @@
 
     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:
 
@@ -25,7 +25,7 @@
     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.     
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #ifndef CDSLIB_CONTAINER_IMPL_FELDMAN_HASHMAP_H
@@ -155,6 +155,9 @@ namespace cds { namespace container {
         /// Count of hazard pointers required
         static CDS_CONSTEXPR size_t const c_nHazardPtrCount = base_class::c_nHazardPtrCount;
 
+        /// The size of \p hash_type in bytes, see \p feldman_hashmap::traits::hash_size for explanation
+        static CDS_CONSTEXPR size_t const c_hash_size = base_class::c_hash_size;
+
         /// Level statistics
         typedef feldman_hashmap::level_statistics level_statistics;
 
@@ -358,7 +361,7 @@ namespace cds { namespace container {
 
             Equation for \p head_bits and \p array_bits:
             \code
-            sizeof( hash_type ) * 8 == head_bits + N * array_bits
+            c_hash_size * 8 == head_bits + N * array_bits
             \endcode
             where \p N is multi-level array depth.
         */
@@ -384,7 +387,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;
@@ -486,7 +489,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.
 
             @warning See \ref cds_intrusive_item_creating "insert item troubleshooting"
@@ -592,14 +595,7 @@ namespace cds { namespace container {
         template <typename K>
         guarded_ptr extract( K const& key )
         {
-            guarded_ptr gp;
-            typename gc::Guard guard;
-            node_type * p = base_class::do_erase( m_Hasher( key_type( key )), guard, []( node_type const&) -> bool {return true;} );
-
-            // p is guarded by HP
-            if ( p )
-                gp.reset( p );
-            return gp;
+            return base_class::extract( m_Hasher( key_type( key )));
         }
 
         /// Checks whether the map contains \p key
@@ -610,7 +606,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
@@ -665,12 +661,7 @@ namespace cds { namespace container {
         template <typename K>
         guarded_ptr get( K const& key )
         {
-            guarded_ptr gp;
-            {
-                typename gc::Guard guard;
-                gp.reset( base_class::search( m_Hasher( key_type( key )), guard ));
-            }
-            return gp;
+            return base_class::get( m_Hasher( key_type( key )));
         }
 
         /// Clears the map (non-atomic)