void TestIteratorsAndRanges() { REMARK("testing iterators compliance\n"); TestIteratorTraits<MyTable::iterator,MyTable::value_type>(); TestIteratorTraits<MyTable::const_iterator,const MyTable::value_type>(); MyTable v; MyTable const &u = v; TestIteratorAssignment<MyTable::const_iterator>( u.begin() ); TestIteratorAssignment<MyTable::const_iterator>( v.begin() ); TestIteratorAssignment<MyTable::iterator>( v.begin() ); // doesn't compile as expected: TestIteratorAssignment<typename V::iterator>( u.begin() ); // check for non-existing ASSERT(v.equal_range(MyKey::make(-1)) == std::make_pair(v.end(), v.end()), NULL); ASSERT(u.equal_range(MyKey::make(-1)) == std::make_pair(u.end(), u.end()), NULL); REMARK("testing ranges compliance\n"); TestRangeAssignment<MyTable::const_range_type>( u.range() ); TestRangeAssignment<MyTable::const_range_type>( v.range() ); TestRangeAssignment<MyTable::range_type>( v.range() ); // doesn't compile as expected: TestRangeAssignment<typename V::range_type>( u.range() ); REMARK("testing construction and insertion from iterators range\n"); FillTable( v, 1000 ); MyTable2 t(v.begin(), v.end()); v.rehash(); CheckTable(t, 1000); t.insert(v.begin(), v.end()); // do nothing CheckTable(t, 1000); t.clear(); t.insert(v.begin(), v.end()); // restore CheckTable(t, 1000); REMARK("testing comparison\n"); typedef tbb::concurrent_hash_map<MyKey,MyData2,YourHashCompare,MyAllocator> YourTable1; typedef tbb::concurrent_hash_map<MyKey,MyData2,YourHashCompare> YourTable2; YourTable1 t1; FillTable( t1, 10 ); CheckTable(t1, 10 ); YourTable2 t2(t1.begin(), t1.end()); MyKey key( MyKey::make(-5) ); MyData2 data; ASSERT(t2.erase(key), NULL); YourTable2::accessor a; ASSERT(t2.insert(a, key), NULL); data.set_value(0); a->second = data; ASSERT( t1 != t2, NULL); data.set_value(5*5); a->second = data; ASSERT( t1 == t2, NULL); }
//! Test travering the tabel with a parallel range void ParallelTraverseTable( MyTable& table, size_t n, size_t expected_size ) { REMARK("testing parallel traversal\n"); ASSERT( table.size()==expected_size, NULL ); AtomicByte* array = new AtomicByte[n]; memset( array, 0, n*sizeof(AtomicByte) ); MyTable::range_type r = table.range(10); tbb::parallel_for( r, ParallelTraverseBody<MyTable::range_type>( array, n )); Check( array, n, expected_size ); const MyTable& const_table = table; memset( array, 0, n*sizeof(AtomicByte) ); MyTable::const_range_type cr = const_table.range(10); tbb::parallel_for( cr, ParallelTraverseBody<MyTable::const_range_type>( array, n )); Check( array, n, expected_size ); delete[] array; }