Merge branch 'ldionne-ldionne-cmake' into dev
[libcds.git] / cds / intrusive / impl / feldman_hashset.h
index d2834f902f91662944404f9931f16ad276ac140a..95f1888af8dfe34583e7114df9929a59859ff9c3 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_INTRUSIVE_IMPL_FELDMAN_HASHSET_H
 #define CDSLIB_INTRUSIVE_IMPL_FELDMAN_HASHSET_H
@@ -92,7 +120,9 @@ namespace cds { namespace intrusive {
     >
     class FeldmanHashSet: protected feldman_hashset::multilevel_array<T, Traits>
     {
+        //@cond
         typedef feldman_hashset::multilevel_array<T, Traits> base_class;
+        //@endcond
 
     public:
         typedef GC      gc;         ///< Garbage collector
@@ -115,6 +145,12 @@ namespace cds { namespace intrusive {
         /// Count of hazard pointers required
         static CDS_CONSTEXPR size_t const c_nHazardPtrCount = 2;
 
+        /// The size of hash_type in bytes, see \p feldman_hashset::traits::hash_size for explanation
+        static CDS_CONSTEXPR size_t const c_hash_size = base_class::c_hash_size;
+
+        /// Level statistics
+        typedef feldman_hashset::level_statistics level_statistics;
+
     protected:
         //@cond
         typedef typename base_class::node_ptr node_ptr;
@@ -156,7 +192,7 @@ namespace cds { namespace intrusive {
                 m_guard.copy( rhs.m_guard );
             }
 
-            iterator_base& operator=(iterator_base const& rhs) CDS_NOEXCEPT
+            iterator_base& operator=( iterator_base const& rhs ) CDS_NOEXCEPT
             {
                 m_pNode = rhs.m_pNode;
                 m_idx = rhs.m_idx;
@@ -182,12 +218,12 @@ namespace cds { namespace intrusive {
                 m_guard.clear();
             }
 
-            bool operator ==(iterator_base const& rhs) const CDS_NOEXCEPT
+            bool operator ==( iterator_base const& rhs ) const CDS_NOEXCEPT
             {
                 return m_pNode == rhs.m_pNode && m_idx == rhs.m_idx && m_set == rhs.m_set;
             }
 
-            bool operator !=(iterator_base const& rhs) const CDS_NOEXCEPT
+            bool operator !=( iterator_base const& rhs ) const CDS_NOEXCEPT
             {
                 return !( *this == rhs );
             }
@@ -229,7 +265,7 @@ namespace cds { namespace intrusive {
                         if ( slot.bits() == base_class::flag_array_node ) {
                             // array node, go down the tree
                             assert( slot.ptr() != nullptr );
-                            pNode = to_array( slot.ptr() );
+                            pNode = to_array( slot.ptr());
                             idx = 0;
                             nodeSize = arrayNodeSize;
                         }
@@ -240,7 +276,7 @@ namespace cds { namespace intrusive {
                         else {
                             if ( slot.ptr()) {
                                 // data node
-                                if ( m_guard.protect( pNode->nodes[idx], [](node_ptr p) -> value_type * { return p.ptr(); }) == slot ) {
+                                if ( m_guard.protect( pNode->nodes[idx], []( node_ptr p ) -> value_type* { return p.ptr(); }) == slot ) {
                                     m_pNode = pNode;
                                     m_idx = idx;
                                     return;
@@ -258,7 +294,7 @@ namespace cds { namespace intrusive {
                         }
                         else {
                             // end()
-                            assert( pNode == m_set->head() );
+                            assert( pNode == m_set->head());
                             assert( idx == headSize );
                             m_pNode = pNode;
                             m_idx = idx;
@@ -287,7 +323,7 @@ namespace cds { namespace intrusive {
                         if ( slot.bits() == base_class::flag_array_node ) {
                             // array node, go down the tree
                             assert( slot.ptr() != nullptr );
-                            pNode = to_array( slot.ptr() );
+                            pNode = to_array( slot.ptr());
                             nodeSize = arrayNodeSize;
                             idx = nodeSize - 1;
                         }
@@ -298,7 +334,7 @@ namespace cds { namespace intrusive {
                         else {
                             if ( slot.ptr()) {
                                 // data node
-                                if ( m_guard.protect( pNode->nodes[idx], [](node_ptr p) -> value_type * { return p.ptr(); }) == slot ) {
+                                if ( m_guard.protect( pNode->nodes[idx], []( node_ptr p ) -> value_type* { return p.ptr(); }) == slot ) {
                                     m_pNode = pNode;
                                     m_idx = idx;
                                     return;
@@ -316,7 +352,7 @@ namespace cds { namespace intrusive {
                         }
                         else {
                             // rend()
-                            assert( pNode == m_set->head() );
+                            assert( pNode == m_set->head());
                             assert( idx == endIdx );
                             m_pNode = pNode;
                             m_idx = idx;
@@ -342,7 +378,7 @@ namespace cds { namespace intrusive {
         template <class Iterator>
         Iterator init_rbegin() const
         {
-            return Iterator( *this, head(), head_size() );
+            return Iterator( *this, head(), head_size());
         }
 
         template <class Iterator>
@@ -372,7 +408,7 @@ namespace cds { namespace intrusive {
                 : iterator_base( rhs )
             {}
 
-            bidirectional_iterator& operator=(bidirectional_iterator const& rhs) CDS_NOEXCEPT
+            bidirectional_iterator& operator=( bidirectional_iterator const& rhs ) CDS_NOEXCEPT
             {
                 iterator_base::operator=( rhs );
                 return *this;
@@ -408,13 +444,13 @@ namespace cds { namespace intrusive {
             }
 
             template <bool IsConst2>
-            bool operator ==(bidirectional_iterator<IsConst2> const& rhs) const CDS_NOEXCEPT
+            bool operator ==( bidirectional_iterator<IsConst2> const& rhs ) const CDS_NOEXCEPT
             {
                 return iterator_base::operator==( rhs );
             }
 
             template <bool IsConst2>
-            bool operator !=(bidirectional_iterator<IsConst2> const& rhs) const CDS_NOEXCEPT
+            bool operator !=( bidirectional_iterator<IsConst2> const& rhs ) const CDS_NOEXCEPT
             {
                 return !( *this == rhs );
             }
@@ -484,13 +520,13 @@ namespace cds { namespace intrusive {
             }
 
             template <bool IsConst2>
-            bool operator ==(reverse_bidirectional_iterator<IsConst2> const& rhs) const
+            bool operator ==( reverse_bidirectional_iterator<IsConst2> const& rhs ) const
             {
                 return iterator_base::operator==( rhs );
             }
 
             template <bool IsConst2>
-            bool operator !=(reverse_bidirectional_iterator<IsConst2> const& rhs)
+            bool operator !=( reverse_bidirectional_iterator<IsConst2> const& rhs )
             {
                 return !( *this == rhs );
             }
@@ -529,12 +565,12 @@ namespace cds { namespace intrusive {
     public:
         /// Creates empty set
         /**
-            @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
-            sizeof(hash_type) * 8 == head_bits + N * array_bits
+            sizeof( hash_type ) * 8 == head_bits + N * array_bits
             \endcode
             where \p N is multi-level array depth.
         */
@@ -557,7 +593,7 @@ namespace cds { namespace intrusive {
         */
         bool insert( value_type& val )
         {
-            return insert( val, [](value_type&) {} );
+            return insert( val, []( value_type& ) {} );
         }
 
         /// Inserts new node
@@ -582,41 +618,45 @@ namespace cds { namespace intrusive {
         template <typename Func>
         bool insert( value_type& val, Func f )
         {
-            hash_type const& hash = hash_accessor()(val);
+            hash_type const& hash = hash_accessor()( val );
             traverse_data pos( hash, *this );
             hash_comparator cmp;
-            typename gc::Guard guard;
+            typename gc::template GuardArray<2> guards;
 
-            while (true) {
+            guards.assign( 1, &val );
+            while ( true ) {
                 node_ptr slot = base_class::traverse( pos );
                 assert( slot.bits() == 0 );
 
                 // protect data node by hazard pointer
-                if (guard.protect(pos.pArr->nodes[pos.nSlot], [](node_ptr p) -> value_type * { return p.ptr(); }) != slot) {
+                if ( guards.protect( 0, pos.pArr->nodes[pos.nSlot], []( node_ptr p ) -> value_type* { return p.ptr(); }) != slot ) {
                     // slot value has been changed - retry
                     stats().onSlotChanged();
                 }
-
-                if (slot.ptr()) {
-                    if ( cmp( hash, hash_accessor()(*slot.ptr())) == 0 ) {
+                else if ( slot.ptr()) {
+                    if ( cmp( hash, hash_accessor()( *slot.ptr())) == 0 ) {
                         // the item with that hash value already exists
                         stats().onInsertFailed();
                         return false;
                     }
 
-                    // the slot must be expanded
-                    base_class::expand_slot( pos, slot );
+                    if ( !pos.splitter.eos()) {
+                        // the slot must be expanded
+                        base_class::expand_slot( pos, slot );
+                    }
+                    else
+                        return false;
                 }
                 else {
                     // the slot is empty, try to insert data node
                     node_ptr pNull;
-                    if ( pos.pArr->nodes[pos.nSlot].compare_exchange_strong(pNull, node_ptr(&val), memory_model::memory_order_release, atomics::memory_order_relaxed))
+                    if ( pos.pArr->nodes[pos.nSlot].compare_exchange_strong( pNull, node_ptr( &val ), memory_model::memory_order_release, atomics::memory_order_relaxed ))
                     {
                         // the new data node has been inserted
-                        f(val);
+                        f( val );
                         ++m_ItemCounter;
                         stats().onInsertSuccess();
-                        stats().height(pos.nHeight);
+                        stats().height( pos.nHeight );
                         return true;
                     }
 
@@ -638,13 +678,13 @@ namespace cds { namespace intrusive {
             - If hash value is not found and \p bInsert is \p false then the set is unchanged,
               the function returns <tt> std::pair<false, false> </tt>
 
-            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
             (i.e. the item has been inserted or updated),
             \p second is \p true if new item has been added or \p false if the set contains that hash.
         */
         std::pair<bool, bool> update( value_type& val, bool bInsert = true )
         {
-            return do_update(val, [](value_type&, value_type *) {}, bInsert );
+            return do_update( val, []( value_type&, value_type* ) {}, bInsert );
         }
 
         /// Unlinks the item \p val from the set
@@ -657,7 +697,7 @@ namespace cds { namespace intrusive {
         bool unlink( value_type const& val )
         {
             typename gc::Guard guard;
-            auto pred = [&val](value_type const& item) -> bool { return &item == &val; };
+            auto pred = [&val]( value_type const& item ) -> bool { return &item == &val; };
             value_type * p = do_erase( hash_accessor()( val ), guard, std::ref( pred ));
             return p != nullptr;
         }
@@ -672,7 +712,7 @@ namespace cds { namespace intrusive {
         */
         bool erase( hash_type const& hash )
         {
-            return erase(hash, [](value_type const&) {} );
+            return erase( hash, []( value_type const& ) {} );
         }
 
         /// Deletes the item from the set
@@ -749,16 +789,10 @@ namespace cds { namespace intrusive {
         */
         guarded_ptr extract( hash_type const& hash )
         {
-            guarded_ptr gp;
-            {
-                typename gc::Guard guard;
-                value_type * p = do_erase( hash, guard, []( value_type const&) -> bool {return true;} );
-
-                // p is guarded by HP
-                if ( p )
-                    gp.reset( p );
-            }
-            return gp;
+            typename gc::Guard guard;
+            if ( do_erase( hash, guard, []( value_type const&) -> bool {return true;} ))
+                return guarded_ptr( std::move( guard ));
+            return guarded_ptr();
         }
 
         /// Finds an item by it's \p hash
@@ -800,7 +834,7 @@ namespace cds { namespace intrusive {
         */
         bool contains( hash_type const& hash )
         {
-            return find( hash, [](value_type&) {} );
+            return find( hash, []( value_type& ) {} );
         }
 
         /// Finds an item by it's \p hash and returns the item found
@@ -828,12 +862,10 @@ namespace cds { namespace intrusive {
         */
         guarded_ptr get( hash_type const& hash )
         {
-            guarded_ptr gp;
-            {
-                typename gc::Guard guard;
-                gp.reset( search( hash, guard ));
-            }
-            return gp;
+            typename gc::Guard guard;
+            if ( search( hash, guard ))
+                return guarded_ptr( std::move( guard ));
+            return guarded_ptr();
         }
 
         /// Clears the set (non-atomic)
@@ -846,7 +878,7 @@ namespace cds { namespace intrusive {
         */
         void clear()
         {
-            clear_array( head(), head_size() );
+            clear_array( head(), head_size());
         }
 
         /// Checks if the set is empty
@@ -878,15 +910,15 @@ namespace cds { namespace intrusive {
         using base_class::array_node_size;
 
         /// Collects tree level statistics into \p stat
-        /** @anchor cds_intrusive_FeldmanHashSet_hp_get_level_statistics
-            The function traverses the set and collects staistics for each level of the tree
+        /**
+            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_hashset::level_statistics>& stat) const
+        void get_level_statistics( std::vector< feldman_hashset::level_statistics>& stat ) const
         {
             base_class::get_level_statistics( stat );
         }
@@ -964,19 +996,19 @@ namespace cds { namespace intrusive {
         /// Returns a reverse iterator to the first element of the reversed set
         reverse_iterator rbegin()
         {
-            return reverse_iterator( *this, head(), head_size() );
+            return reverse_iterator( *this, head(), head_size());
         }
 
         /// Returns a const reverse iterator to the first element of the reversed set
         const_reverse_iterator rbegin() const
         {
-            return const_reverse_iterator( *this, head(), head_size() );
+            return const_reverse_iterator( *this, head(), head_size());
         }
 
         /// Returns a const reverse iterator to the first element of the reversed set
         const_reverse_iterator crbegin()
         {
-            return const_reverse_iterator( *this, head(), head_size() );
+            return const_reverse_iterator( *this, head(), head_size());
         }
 
         /// Returns a reverse iterator to the element following the last element of the reversed set
@@ -1022,12 +1054,12 @@ namespace cds { namespace intrusive {
                     if ( slot.bits() == base_class::flag_array_node ) {
                         // array node, go down the tree
                         assert( slot.ptr() != nullptr );
-                        clear_array( to_array( slot.ptr()), array_node_size() );
+                        clear_array( to_array( slot.ptr()), array_node_size());
                         break;
                     }
                     else if ( slot.bits() == base_class::flag_array_converting ) {
                         // the slot is converting to array node right now
-                        while ( (slot = pArr->load(memory_model::memory_order_acquire)).bits() == base_class::flag_array_converting ) {
+                        while (( slot = pArr->load( memory_model::memory_order_acquire )).bits() == base_class::flag_array_converting ) {
                             bkoff();
                             stats().onSlotConverting();
                         }
@@ -1035,14 +1067,14 @@ namespace cds { namespace intrusive {
 
                         assert( slot.ptr() != nullptr );
                         assert( slot.bits() == base_class::flag_array_node );
-                        clear_array( to_array( slot.ptr()), array_node_size() );
+                        clear_array( to_array( slot.ptr()), array_node_size());
                         break;
                     }
                     else {
                         // data node
                         if ( pArr->compare_exchange_strong( slot, node_ptr(), memory_model::memory_order_acquire, atomics::memory_order_relaxed )) {
-                            if ( slot.ptr() ) {
-                                gc::template retire<disposer>( slot.ptr() );
+                            if ( slot.ptr()) {
+                                gc::template retire<disposer>( slot.ptr());
                                 --m_ItemCounter;
                                 stats().onEraseSuccess();
                             }
@@ -1061,16 +1093,17 @@ namespace cds { namespace intrusive {
             traverse_data pos( hash, *this );
             hash_comparator cmp;
 
-            while (true) {
+            while ( true ) {
                 node_ptr slot = base_class::traverse( pos );
-                assert(slot.bits() == 0);
+                assert( slot.bits() == 0 );
 
                 // protect data node by hazard pointer
-                if (guard.protect( pos.pArr->nodes[pos.nSlot], [](node_ptr p) -> value_type * { return p.ptr(); }) != slot) {
+                if ( guard.protect( pos.pArr->nodes[pos.nSlot], []( node_ptr p ) -> value_type* { return p.ptr(); }) != slot) {
                     // slot value has been changed - retry
                     stats().onSlotChanged();
+                    continue;
                 }
-                else if (slot.ptr() && cmp(hash, hash_accessor()(*slot.ptr())) == 0) {
+                else if ( slot.ptr() && cmp( hash, hash_accessor()( *slot.ptr())) == 0 ) {
                     // item found
                     stats().onFindSuccess();
                     return slot.ptr();
@@ -1085,21 +1118,21 @@ namespace cds { namespace intrusive {
         {
             traverse_data pos( hash, *this );
             hash_comparator cmp;
-            while (true) {
+            while ( true ) {
                 node_ptr slot = base_class::traverse( pos );
-                assert(slot.bits() == 0);
+                assert( slot.bits() == 0 );
 
                 // protect data node by hazard pointer
-                if (guard.protect( pos.pArr->nodes[pos.nSlot], [](node_ptr p) -> value_type * { return p.ptr(); }) != slot) {
+                if ( guard.protect( pos.pArr->nodes[pos.nSlot], []( node_ptr p ) -> value_type* { return p.ptr(); }) != slot ) {
                     // slot value has been changed - retry
                     stats().onSlotChanged();
                 }
-                else if (slot.ptr()) {
-                    if (cmp(hash, hash_accessor()(*slot.ptr())) == 0 && pred(*slot.ptr())) {
+                else if ( slot.ptr()) {
+                    if ( cmp( hash, hash_accessor()( *slot.ptr())) == 0 && pred( *slot.ptr())) {
                         // item found - replace it with nullptr
-                        if ( pos.pArr->nodes[pos.nSlot].compare_exchange_strong(slot, node_ptr(nullptr), memory_model::memory_order_acquire, atomics::memory_order_relaxed)) {
+                        if ( pos.pArr->nodes[pos.nSlot].compare_exchange_strong( slot, node_ptr( nullptr ), memory_model::memory_order_acquire, atomics::memory_order_relaxed)) {
                             // slot is guarded by HP
-                            gc::template retire<disposer>(slot.ptr());
+                            gc::template retire<disposer>( slot.ptr());
                             --m_ItemCounter;
                             stats().onEraseSuccess();
 
@@ -1123,17 +1156,19 @@ namespace cds { namespace intrusive {
         {
             if ( iter.m_set != this )
                 return false;
-            if ( iter.m_pNode == head() && iter.m_idx >= head_size())
-                return false;
-            if ( iter.m_idx >= array_node_size() )
+            if ( iter.m_pNode == head()) {
+                if ( iter.m_idx >= head_size())
+                    return false;
+            }
+            else if ( iter.m_idx >= array_node_size())
                 return false;
 
             for (;;) {
                 node_ptr slot = iter.m_pNode->nodes[iter.m_idx].load( memory_model::memory_order_acquire );
-                if ( slot.bits() == 0 && slot.ptr() == iter.pointer() ) {
-                    if ( iter.m_pNode->nodes[iter.m_idx].compare_exchange_strong(slot, node_ptr(nullptr), memory_model::memory_order_acquire, atomics::memory_order_relaxed) ) {
+                if ( slot.bits() == 0 && slot.ptr() == iter.pointer()) {
+                    if ( iter.m_pNode->nodes[iter.m_idx].compare_exchange_strong( slot, node_ptr( nullptr ), memory_model::memory_order_acquire, atomics::memory_order_relaxed )) {
                         // the item is guarded by iterator, so we may retire it safely
-                        gc::template retire<disposer>( slot.ptr() );
+                        gc::template retire<disposer>( slot.ptr());
                         --m_ItemCounter;
                         stats().onEraseSuccess();
                         return true;
@@ -1152,30 +1187,31 @@ namespace cds { namespace intrusive {
             hash_comparator cmp;
             typename gc::template GuardArray<2> guards;
 
-            while (true) {
+            guards.assign( 1, &val );
+            while ( true ) {
                 node_ptr slot = base_class::traverse( pos );
-                assert(slot.bits() == 0);
+                assert( slot.bits() == 0 );
 
                 // protect data node by hazard pointer
-                if (guards.protect(0, pos.pArr->nodes[pos.nSlot], [](node_ptr p) -> value_type * { return p.ptr(); }) != slot) {
+                if ( guards.protect( 0, pos.pArr->nodes[pos.nSlot], []( node_ptr p ) -> value_type* { return p.ptr(); }) != slot ) {
                     // slot value has been changed - retry
                     stats().onSlotChanged();
                 }
-                else if (slot.ptr()) {
-                    if (cmp(hash, hash_accessor()(*slot.ptr())) == 0) {
+                else if ( slot.ptr()) {
+                    if ( cmp( hash, hash_accessor()( *slot.ptr())) == 0 ) {
                         // the item with that hash value already exists
                         // Replace it with val
-                        if (slot.ptr() == &val) {
+                        if ( slot.ptr() == &val ) {
                             stats().onUpdateExisting();
-                            return std::make_pair(true, false);
+                            return std::make_pair( true, false );
                         }
 
-                        if ( pos.pArr->nodes[pos.nSlot].compare_exchange_strong(slot, node_ptr(&val), memory_model::memory_order_release, atomics::memory_order_relaxed)) {
+                        if ( pos.pArr->nodes[pos.nSlot].compare_exchange_strong( slot, node_ptr( &val ), memory_model::memory_order_release, atomics::memory_order_relaxed )) {
                             // slot can be disposed
-                            f(val, slot.ptr());
-                            gc::template retire<disposer>(slot.ptr());
+                            f( val, slot.ptr());
+                            gc::template retire<disposer>( slot.ptr());
                             stats().onUpdateExisting();
-                            return std::make_pair(true, false);
+                            return std::make_pair( true, false );
                         }
 
                         stats().onUpdateRetry();
@@ -1183,31 +1219,35 @@ namespace cds { namespace intrusive {
                     }
 
                     if ( bInsert ) {
-                        // the slot must be expanded
-                        base_class::expand_slot( pos, slot );
+                        if ( !pos.splitter.eos()) {
+                            // the slot must be expanded
+                            base_class::expand_slot( pos, slot );
+                        }
+                        else
+                            return std::make_pair( false, false );
                     }
                     else {
                         stats().onUpdateFailed();
-                        return std::make_pair(false, false);
+                        return std::make_pair( false, false );
                     }
                 }
                 else {
                     // the slot is empty, try to insert data node
-                    if (bInsert) {
+                    if ( bInsert ) {
                         node_ptr pNull;
-                        if ( pos.pArr->nodes[pos.nSlot].compare_exchange_strong(pNull, node_ptr(&val), memory_model::memory_order_release, atomics::memory_order_relaxed))
+                        if ( pos.pArr->nodes[pos.nSlot].compare_exchange_strong( pNull, node_ptr( &val ), memory_model::memory_order_release, atomics::memory_order_relaxed ))
                         {
                             // the new data node has been inserted
-                            f(val, nullptr);
+                            f( val, nullptr );
                             ++m_ItemCounter;
                             stats().onUpdateNew();
                             stats().height( pos.nHeight );
-                            return std::make_pair(true, true);
+                            return std::make_pair( true, true );
                         }
                     }
                     else {
                         stats().onUpdateFailed();
-                        return std::make_pair(false, false);
+                        return std::make_pair( false, false );
                     }
 
                     // insert failed - slot has been changed by another thread