X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tests%2Ftest-hdr%2Fmap%2Fhdr_cuckoo_map.h;h=7135645ae99e8b056759c266125392d3757d588e;hb=cd515d6402be81b84e2eb0c9d4cf0a1ca9e4d95a;hp=ccc7cfa910d72d2570299818bd4f44ed65627cdf;hpb=bab1583cb2db30355c138a507943cd5ad068ccf4;p=libcds.git diff --git a/tests/test-hdr/map/hdr_cuckoo_map.h b/tests/test-hdr/map/hdr_cuckoo_map.h index ccc7cfa9..7135645a 100644 --- a/tests/test-hdr/map/hdr_cuckoo_map.h +++ b/tests/test-hdr/map/hdr_cuckoo_map.h @@ -1,14 +1,41 @@ -//$$CDS-header$$ - -#ifndef __CDSTEST_HDR_CUCKOO_MAP_H -#define __CDSTEST_HDR_CUCKOO_MAP_H +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + 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 CDSTEST_HDR_CUCKOO_MAP_H +#define CDSTEST_HDR_CUCKOO_MAP_H #include "size_check.h" #include "cppunit/cppunit_proxy.h" #include #include -#include -#include // random_shuffle +#include // ref namespace cds { namespace container {}} @@ -121,7 +148,7 @@ namespace map { item.second.m_val = item.first * 3; } - // ensure ftor + // update() ftor void operator()( bool bNew, pair_type& item ) { if ( bNew ) @@ -213,108 +240,112 @@ namespace map { template void test_int_with( Map& m ) { - std::pair ensureResult; + std::pair updateResult; typedef typename std::conditional< Map::c_isSorted, less, equal >::type predicate; // insert CPPUNIT_ASSERT( m.empty() ); CPPUNIT_ASSERT( check_size( m, 0 )); - CPPUNIT_ASSERT( !m.find(25) ); + CPPUNIT_ASSERT( !m.contains(25) ); CPPUNIT_ASSERT( m.insert( 25 ) ) ; // value = 0 - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 1 )); - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( !m.insert( 25 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 1 )); - CPPUNIT_ASSERT( !m.find_with(10, predicate()) ); + CPPUNIT_ASSERT( !m.contains(10, predicate()) ); CPPUNIT_ASSERT( m.insert( 10, 10 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); - CPPUNIT_ASSERT( m.find_with(10, predicate()) ); + CPPUNIT_ASSERT( m.contains(10, predicate()) ); CPPUNIT_ASSERT( !m.insert( 10, 20 ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); - CPPUNIT_ASSERT( !m.find(30) ); - CPPUNIT_ASSERT( m.insert_key( 30, insert_functor() ) ) ; // value = 90 + CPPUNIT_ASSERT( !m.contains(30) ); + CPPUNIT_ASSERT( m.insert_with( 30, insert_functor() ) ) ; // value = 90 CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( m.find(30) ); - - CPPUNIT_ASSERT( !m.insert_key( 10, insert_functor() ) ); - CPPUNIT_ASSERT( !m.insert_key( 25, insert_functor() ) ); - CPPUNIT_ASSERT( !m.insert_key( 30, insert_functor() ) ); - - // ensure (new key) - CPPUNIT_ASSERT( !m.find(27) ); - ensureResult = m.ensure( 27, insert_functor() ) ; // value = 54 - CPPUNIT_ASSERT( ensureResult.first ); - CPPUNIT_ASSERT( ensureResult.second ); - CPPUNIT_ASSERT( m.find(27) ); + CPPUNIT_ASSERT( m.contains(30) ); + + CPPUNIT_ASSERT( !m.insert_with( 10, insert_functor() ) ); + CPPUNIT_ASSERT( !m.insert_with( 25, insert_functor() ) ); + CPPUNIT_ASSERT( !m.insert_with( 30, insert_functor() ) ); + + // update (new key) + CPPUNIT_ASSERT( !m.contains(27) ); + updateResult = m.update(27, insert_functor(), false); + CPPUNIT_ASSERT(!updateResult.first); + CPPUNIT_ASSERT(!updateResult.second); + CPPUNIT_ASSERT(!m.contains(27)); + updateResult = m.update( 27, insert_functor() ) ; // value = 54 + CPPUNIT_ASSERT( updateResult.first ); + CPPUNIT_ASSERT( updateResult.second ); + CPPUNIT_ASSERT( m.contains(27) ); // find test check_value chk(10); - CPPUNIT_ASSERT( m.find( 10, cds::ref(chk) )); + CPPUNIT_ASSERT( m.find( 10, std::ref(chk) )); chk.m_nExpected = 0; - CPPUNIT_ASSERT( m.find_with( 25, predicate(), boost::ref(chk) )); + CPPUNIT_ASSERT( m.find_with( 25, predicate(), std::ref(chk) )); chk.m_nExpected = 90; - CPPUNIT_ASSERT( m.find( 30, boost::ref(chk) )); + CPPUNIT_ASSERT( m.find( 30, std::ref(chk) )); chk.m_nExpected = 54; - CPPUNIT_ASSERT( m.find( 27, boost::ref(chk) )); + CPPUNIT_ASSERT( m.find( 27, std::ref(chk) )); - ensureResult = m.ensure( 10, insert_functor() ) ; // value = 50 - CPPUNIT_ASSERT( ensureResult.first ); - CPPUNIT_ASSERT( !ensureResult.second ); + updateResult = m.update( 10, insert_functor() ) ; // value = 50 + CPPUNIT_ASSERT( updateResult.first ); + CPPUNIT_ASSERT( !updateResult.second ); chk.m_nExpected = 50; - CPPUNIT_ASSERT( m.find( 10, boost::ref(chk) )); + CPPUNIT_ASSERT( m.find( 10, std::ref(chk) )); // erase test - CPPUNIT_ASSERT( !m.find(100) ); + CPPUNIT_ASSERT( !m.contains(100) ); CPPUNIT_ASSERT( !m.erase( 100 )) ; // not found - CPPUNIT_ASSERT( m.find(25) ); + CPPUNIT_ASSERT( m.contains(25) ); CPPUNIT_ASSERT( check_size( m, 4 )); CPPUNIT_ASSERT( m.erase( 25 )); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( !m.find(25) ); + CPPUNIT_ASSERT( !m.contains(25) ); CPPUNIT_ASSERT( !m.erase( 25 )); - CPPUNIT_ASSERT( !m.find(258) ); + CPPUNIT_ASSERT( !m.contains(258) ); CPPUNIT_ASSERT( m.insert(258)) CPPUNIT_ASSERT( check_size( m, 4 )); - CPPUNIT_ASSERT( m.find_with(258, predicate()) ); + CPPUNIT_ASSERT( m.contains(258, predicate()) ); CPPUNIT_ASSERT( m.erase_with( 258, predicate() )); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); - CPPUNIT_ASSERT( !m.find(258) ); + CPPUNIT_ASSERT( !m.contains(258) ); CPPUNIT_ASSERT( !m.erase_with( 258, predicate() )); int nVal; extract_functor ext; ext.m_pVal = &nVal; - CPPUNIT_ASSERT( !m.find(29) ); + CPPUNIT_ASSERT( !m.contains(29) ); CPPUNIT_ASSERT( m.insert(29, 290)) - CPPUNIT_ASSERT( m.erase_with( 29, predicate(), boost::ref(ext))); + CPPUNIT_ASSERT( m.erase_with( 29, predicate(), std::ref(ext))); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); CPPUNIT_ASSERT( nVal == 290 ); nVal = -1; - CPPUNIT_ASSERT( !m.erase_with( 29, predicate(), boost::ref(ext))); + CPPUNIT_ASSERT( !m.erase_with( 29, predicate(), std::ref( ext ) ) ); CPPUNIT_ASSERT( nVal == -1 ); - CPPUNIT_ASSERT( m.erase( 30, boost::ref(ext))); + CPPUNIT_ASSERT( m.erase( 30, std::ref( ext ) ) ); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 2 )); CPPUNIT_ASSERT( nVal == 90 ); nVal = -1; - CPPUNIT_ASSERT( !m.erase( 30, boost::ref(ext))); + CPPUNIT_ASSERT( !m.erase( 30, std::ref( ext ) ) ); CPPUNIT_ASSERT( nVal == -1 ); m.clear(); @@ -330,15 +361,15 @@ namespace map { CPPUNIT_ASSERT( check_size( m, 3 )); chk.m_nExpected = 0; - CPPUNIT_ASSERT( m.find( 126, cds::ref(chk) )); + CPPUNIT_ASSERT( m.find( 126, std::ref(chk) )); chk.m_nExpected = 731; - CPPUNIT_ASSERT( m.find_with( 137, predicate(), cds::ref(chk) )); + CPPUNIT_ASSERT( m.find_with( 137, predicate(), std::ref(chk) )); chk.m_nExpected = 941; - CPPUNIT_ASSERT( m.find( 149, cds::ref(chk) )); + CPPUNIT_ASSERT( m.find( 149, std::ref(chk) )); CPPUNIT_ASSERT( !m.emplace(126, 621)) ; // already in map chk.m_nExpected = 0; - CPPUNIT_ASSERT( m.find( 126, cds::ref(chk) )); + CPPUNIT_ASSERT( m.find( 126, std::ref(chk) )); CPPUNIT_ASSERT( !m.empty() ); CPPUNIT_ASSERT( check_size( m, 3 )); @@ -387,4 +418,4 @@ namespace map { }; } // namespace map -#endif // #ifndef __CDSTEST_HDR_CUCKOO_MAP_H +#endif // #ifndef CDSTEST_HDR_CUCKOO_MAP_H